G
Guest
FYI: This may be a duplicate posting. It appears my previous posts have
failed.
I have a form that displays nothing on it except a few buttons. When the
form is loaded it is dynamically displays additional buttons. Each customer
who has an open order has a button created for them. The buttons are created
during the Form_Load event.
The problem I’m having is that all of my existing buttons disappear when the
form loads. Being frustrated with this behavior I came up with a solution. My
solution was to just go ahead and dynamically create my regular buttons such
as btnExit, btnOpen and btnPrint dynamically just like the other buttons were
created. During my first test everything was working great. I used the
following code to create the buttons.
Dim btn1 As New Button
' Create the Exit Button.
btn1.Location = New System.Drawing.Point(888, 603)
btn1.Margin = New System.Windows.Forms.Padding(2)
btn1.Name = "btnExit"
btn1.Size = New System.Drawing.Size(117, 66)
btn1.TabIndex = 5
btn1.Text = "Exit"
Controls.Add(btn1)
AddHandler btn1.Click, AddressOf btnExit_Click
The code created the buttons just as I wanted. But, when I ran my test I
realized I forgot to set one property and that was the anchor property
because when I resized the form the button did not stay anchored as I need it
to. So, I added the following line of code to anchor the buttons to the lower
right corner of the form.
btn1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or
System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Now, all of the sudden my buttons are not showing up again. After further
testing I discovered that if I have an existing or a dynamic button with the
anchor properties set they will not appear on the form at all.
My assumption is the buttons are being created except they are not being
displayed on the form.
Why is this happening and if theres are reason for this what must I do to
resolve the problem?
Thanks
failed.
I have a form that displays nothing on it except a few buttons. When the
form is loaded it is dynamically displays additional buttons. Each customer
who has an open order has a button created for them. The buttons are created
during the Form_Load event.
The problem I’m having is that all of my existing buttons disappear when the
form loads. Being frustrated with this behavior I came up with a solution. My
solution was to just go ahead and dynamically create my regular buttons such
as btnExit, btnOpen and btnPrint dynamically just like the other buttons were
created. During my first test everything was working great. I used the
following code to create the buttons.
Dim btn1 As New Button
' Create the Exit Button.
btn1.Location = New System.Drawing.Point(888, 603)
btn1.Margin = New System.Windows.Forms.Padding(2)
btn1.Name = "btnExit"
btn1.Size = New System.Drawing.Size(117, 66)
btn1.TabIndex = 5
btn1.Text = "Exit"
Controls.Add(btn1)
AddHandler btn1.Click, AddressOf btnExit_Click
The code created the buttons just as I wanted. But, when I ran my test I
realized I forgot to set one property and that was the anchor property
because when I resized the form the button did not stay anchored as I need it
to. So, I added the following line of code to anchor the buttons to the lower
right corner of the form.
btn1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or
System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Now, all of the sudden my buttons are not showing up again. After further
testing I discovered that if I have an existing or a dynamic button with the
anchor properties set they will not appear on the form at all.
My assumption is the buttons are being created except they are not being
displayed on the form.
Why is this happening and if theres are reason for this what must I do to
resolve the problem?
Thanks