VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Creates A form control such as textbox or listbox without creating an instance or an object

by Bhumika Dave (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 16th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Creates A form control such as textbox or listbox without creating an instance or an object

Rate Creates A form control such as textbox or listbox without creating an instance or an object




Private Sub Command1_Click()
Dim txtnew As Object
Set txtnew = Form1.Controls.Add("VB.TEXTBOX", "txt1")
txtnew.Visible = True
txtnew.Text = "Hi,I am here"
End Sub

//Similar code for creating a run time ListBox

Private Sub Command3_Click()
Dim lstnew As Object
Set lstnew = Form1.Controls.Add("VB.LISTBOX", "lstname")
lstnew.Left = lstnew.Left + 3000  //Placing of control on the form
lstnew.Visible = True
lstnew.AddItem ("One")
lstnew.AddItem ("Two")
lstnew.AddItem ("Three")
lstnew.AddItem ("Four")
lstnew.AddItem ("Five")
lstnew.AddItem ("Six")
End Sub

Note:Various other Controls can be created by using such VB constant:

Constant                 Control
_____________________________________
VB.OPTIONBUTTON        Creates an Option button      
VB.COMBOBOX            Creates a Combo box
VB.TEXTBOX             Creates a Text box
VB.LISTBOX             Creates a List box
VB.CHECKBOX            Creates a Check box
VB.LABLE               Creates a Lable    


Download this snippet    Add to My Saved Code

Creates A form control such as textbox or listbox without creating an instance or an object Comments

No comments have been posted about Creates A form control such as textbox or listbox without creating an instance or an object. Why not be the first to post a comment about Creates A form control such as textbox or listbox without creating an instance or an object.

Post your comment

Subject:
Message:
0/1000 characters