I need to have something happen when a user clicks anywhere inside the form. I don't know much about c# and I have tried looking it up but I just can't find an answer to this exact question.
Asked
Active
Viewed 1,312 times
-4
-
What kind of form? Winforms? Web Forms? WPF? – Joel Coehoorn Nov 16 '18 at 22:20
-
1"windows forms app" in visual studio – Aceramey Nov 16 '18 at 22:23
-
Implement the IMessageFilter interface. Thinking that this is useful is a standard "don't know much" mistake. You can't get the help you really need if you don't explain why you think you need it. – Hans Passant Nov 16 '18 at 22:34
-
it seems you want to handle a click in the form, not in any of the contained controls (buttons, textbox and so on), you just have to handle the Click event of the form. anyway, an advice: if this is actually your problem, you should start looking for tutorials on C# and winforms, before start asking on SO. Learning a language, as a start, requires something different than asking questions on sites like this – Gian Paolo Nov 16 '18 at 22:38
-
Start by reading about the following events. Give something a try, and if you get stuck come back with a more specific question (including problematic code). These events are all related to clicking on a form: `MouseClick`, `MouseDoubleClick`, `MouseDown`, and `MouseUp`. – Rufus L Nov 16 '18 at 23:07
-
2This is the best answer you will find if you want to handle all click globally (ps - Google is your friend) https://stackoverflow.com/questions/804374/capturing-mouse-events-from-every-component-on-c-sharp-winform – Kevin Nov 16 '18 at 23:40
-
Also related: [Handling a Click for all controls on a Form](https://stackoverflow.com/q/247946/3744182). – dbc Nov 17 '18 at 03:18
2 Answers
0
There's things called events
so when the event is happen the code will work
for ex:
Click : when I 'click', the code will happen and that's what are you looking for
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello world!");
}
All you have to do is select the event you want from the properties tab and double click on it and write the code you want

user229044
- 232,980
- 40
- 330
- 338

Lubbock
- 63
- 2
- 13