Creating a Button without Form Designer

JDT_71

Member
Joined
Jul 11, 2006
Messages
7
Programming Experience
Beginner
Given the following code:

Dim btnEnter As New Button()
btnEnter.Top = 100
btnEnter.Left = 100
btnEnter.Height = 100
btnEnter.Width = 100

How do I get the button to show up on the form and be available for use?

Oops, sorry. I meant to post this in the Windows Forms board.
 
You may need to make it visible i.e. btnEnter.visible = true

I use the
DynButton.Load(index)

where index is a global for the next button id that I want to create.

And where DynButton is an array of Buttons on the Form having the
same name ..but that's using the form designer.


 
You'll need to add the control to the form's ControlCollection:

Me.Controls.Add(btnEnter)

where Me is referencing the form that you are adding the button.

For your information: An easy way to answer this question is to add a button to the designer then look at the code generated. Since you're using 2005 you need to look in the .designer.vb file to find the code that was generated.
 
Back
Top