Guest makai Posted November 28, 2002 Posted November 28, 2002 there is absolutely no help on this - so I tried for quite a while with no luck how is it done my code Dim c As System.Windows.Forms.Button Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load c = New System.Windows.Forms.Button() c.Enabled = True c.Visible = True c.Text = "One" c.Height = 20 c.Width = 200 c.Top = 0 c.Left = 0 End Sub Quote
wyrd Posted November 28, 2002 Posted November 28, 2002 Here you go.. 'Instantiate the button. Dim WithEvents button As New Windows.Forms.Button() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load 'Set the button's properties... With button .Name = "aButton" 'Name. .Location = New Drawing.Point(0, 0) 'Where to put the button. .Size = New Drawing.Size(50, 50) 'Size of the button. .Text = "hi there" 'Text to display. End With 'Add the button to the form. Me.Controls.Add(button) End Sub Quote Gamer extraordinaire. Programmer wannabe.
elizabeths Posted November 8, 2003 Posted November 8, 2003 I am a beginner in VB.NET I think this is an excellent code to try. I've been looking for this for 2 days... Thanks Wyrd. I will try it and get back on this.. However, the downside of this code is that you'd need to know the number of controls that appears on the form.. since you need to declare the variable buttons.. etc in order to generate the control itself within the code.. what if we want to generate controls on the fly and do not know how many control there are to generate? Can we REDIM the variable name to different iteration of variable name to generate the code? Please advice. eg : dim x,y as integer x = <no of bottuns to be generate> for y = 0 to x Dim WithEvents button As New Windows.Forms.Button() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load 'Set the button's properties... With button .Name = "aButton" & y 'SETTING NAME CHANGE HERE FOR EACH BUTTON .Location = New Drawing.Point(0, 50 * y +2) 'Where to put the button. .Size = New Drawing.Size(50, 50) 'Size of the button. .Text = "hi there" 'Text to display. End With 'Add the button to the form. Me.Controls.Add(button) End Sub next Liz.. <-- Trying to create an application that generates forms elements from database. Quote
Administrators PlausiblyDamp Posted November 8, 2003 Administrators Posted November 8, 2003 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75448&highlight=control+array http://www.xtremedotnettalk.com/showthread.php?s=&threadid=75012&highlight=control+array http://www.xtremedotnettalk.com/showthread.php?s=&threadid=73387&highlight=control+array Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.