InertiaM
Well-known member
Is it normal for events to fire on invisible controls? I've always been lazy and just made certain buttons invisible rather than set their Enabled property to false.
Create a new project, and only put Button1 on it.
When I run the code, and press Space, I get the OK messagebox. Press Space to accept the OK - and Button1 disappears. Now, if I press Space again, the Click event fires (and shows the messagebox) - even though the button is hidden After this, when you press Space again, it doesnt fire.
As far as I can ascertain, when I accept the 1st messagebox, it puts the focus back onto Button1 before it is made invisible, but doesnt blur the focus when it is hidden. Pressing Space then fires the event on the invisible button, but once it IS invisible, it obviously cannot accept the focus.
I know I can avoid this, but are there any other quirks like this that I need to try and avoid
Create a new project, and only put Button1 on it.
VB.NET:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.KeyPreview = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("OK")
Me.Button1.Visible = False
End Sub
End Class
When I run the code, and press Space, I get the OK messagebox. Press Space to accept the OK - and Button1 disappears. Now, if I press Space again, the Click event fires (and shows the messagebox) - even though the button is hidden After this, when you press Space again, it doesnt fire.
As far as I can ascertain, when I accept the 1st messagebox, it puts the focus back onto Button1 before it is made invisible, but doesnt blur the focus when it is hidden. Pressing Space then fires the event on the invisible button, but once it IS invisible, it obviously cannot accept the focus.
I know I can avoid this, but are there any other quirks like this that I need to try and avoid