Monday, January 18, 2010

Is it posibble to add controls dynamically in Visula studio VB.net? how?

uh, what your talking about... you mean programmaticaly, you find the control you want you make a new instance of it and then you it to your form like so...





yourcontrolhere As New ListView()


Form1.Controls.Add(yourcontrolhere)Is it posibble to add controls dynamically in Visula studio VB.net? how?
Yes, and I'm assuming that you're doing a WinForms application.





Use the Add method of the Controls collection object of your current form, for example:





Dim txtName as New TextBox();


'you can set properties for this control too


...





Me.Controls.Add(txtName);Is it posibble to add controls dynamically in Visula studio VB.net? how?
Yes you can surely do this. Following is a method which adds a button (for example) to your form dynamically. When you will call this method, this will add a button to your form. You can add other controls likewise.





Private Sub CreatButton()


Dim btnYes As System.Windows.Forms.Button


' Create control


btnYes = New System.Windows.Forms.Button()


' Set button properties


btnYes.Name = ';ButtonYes';


btnYes.Size = New System.Drawing.Size(70, 30)


btnYes.Location = New System.Drawing.Point(300, 30)


btn.TabIndex = 1


btnYes.Text = ';YES';


' add to the parent form's controls collection


Me.Controls.Add(btnYes)


End Sub





Hope that answers the question

No comments:

Post a Comment