Question button in runtime

andrews

Well-known member
Joined
Nov 22, 2011
Messages
132
Programming Experience
5-10
I am trying to make a button in runtime but the button is not to see

in de form1.vb I put

dim but as new button

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
but.Left = 100
but.Top = 100
but.Width = 20
but.Height = 20
but.Visible = True
Me.Controls.Add(but)
End Sub
What do I wrong?
 
Hi,

There is nothing wrong with that code and it works fine for me. The only way I can get this NOT to show is if I place another control on the Form where this button will be created. This button is then hidden behind that control. If this is the case for you then you can change the zorder of the button to bring it to the Front by calling BringToFront AFTER you add the control to the form. i.e:-

With but
  .Left = 100
  .Top = 100
  .Width = 20
  .Height = 20
  .Visible = True
End With
 
Me.Controls.Add(but)
but.BringToFront()


Hope that helps.

Cheers,

Ian
 
Thanks IanRyder
But there was no control hiding the other.
II found the reason but I have no explanation.
Before creating the button I had some subs by loading the form and they works.
These subs did no anything with the window but where some calculations and filling some arrays.
When I switch off these subs then the button was there.
But like I said I have no explanation.


The sub who is the "real killer" looks very innocent and is very simple, it fils an array that is mentionned as public


Public Sub vulrijletterwaarde()
rijletterwaarde(65) = 1
rijletterwaarde(66) = 3
rijletterwaarde(67) = 3
rijletterwaarde(68) = 2
rijletterwaarde(69) = 1
end sub
Very strange
 
Hi,

A recognised fact in VS is that if you are using a 64bit Machine then any exceptions thrown in the Form Load event get "swallowed" by the system and do NOT result is an error being thrown which sounds like what you are experiencing.

One way to answer this is to encase all the code in your Form Load Event in a Try/Catch block to see if an error is actually being thrown by one of the subroutines. You should then be able to narrow down what the issue may be.

Hope that helps.

Cheers,

Ian
 
Back
Top