maidinhtai
asked on
Close the form when clicking anywhere of the form or anywhere of the screen
A Very simple question. A good example is the splash screen. How to do that? Thanks.
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Me.Close()
End Sub
Me.Close()
End Sub
ASKER
The matter is when I click on a label control of that form, the click event of the form is not fired. When the user press anykey on the keyboard, the form will close. But when he click the mouse on the form, nothing happens.
Here is the function makes the form closed when the user press any key on the keyboard. But it cannot trap the mouse button.
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Messa ge, ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Scroll Then ChamLai()
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Here is the function makes the form closed when the user press any key on the keyboard. But it cannot trap the mouse button.
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Messa
If keyData = Keys.Scroll Then ChamLai()
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Xersoft, I'd used the same code before I posted this question. Is there another method that is shorter. Something likes Function ProcessCmdKey that can trap all the keys on the keyboard. Or your codes is the only choice?
Although I'm sure there are other ways, probably some easer and shorter, I can think of none.
I also know there are easier ways, I know there was a way to reroute all form objects' events to the main form, but I have to sit at it and try to remember it :D
ASKER
PockyMaster, I'm waiting for you :D.
ASKER
PockyMaster, it's been a long time waiting for your remembering. Or you have forgot about that? I mean "I also know there are easier ways, I know there was a way to reroute all form objects' events to the main form, but I have to sit at it and try to remember it :D"
Heheh.... Yeah, I remember the easier ways were easier in a far past, now the old easier ways have become the more difficult ways :D
I would say, go for the reroute events stuff.
I would say, go for the reroute events stuff.
keep in mind that your not "rerouting events" you are just adding another handler. You can still have other events handling the click event.
ASKER
OK. It seems that there's no shorter ways to do it. Why doesn't VB.NET have any function like ProcessCmdKey to solve my problem?
Well, there are events that you can catch when you click anywhere on the screen.. but uhm...
ok, let me look at it again :D
ok, let me look at it again :D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you don't need the debug.writeline of course :D but that will let you view all the messages being posted
ASKER
That's exact what I want. If possible, I will change the accept answer. Thank you two :D.
You're welcome
and write me.close in it