1

I know that I can check when an item has been clicked or not.

But if I have an _Click event on my Widget, when this event is triggered, can I trigger the _click event for my form as well?

I have used a pictureBox in my class and I wrote the code for it inside my class and now I do not know how to register a click on my form as well.

EDIT: I'm sorry; it was a clumsy explanaiton I'll try again: How can I throw an Event (or something like that) in my class and catch it in a Form?

SnuKies
  • 1,578
  • 1
  • 16
  • 37
  • It may be a duplicate of http://stackoverflow.com/questions/247946/handling-a-click-for-all-controls-on-a-form, but `code for it inside my class and now I do not know how to register a click on my form` part may suggest something different, like http://stackoverflow.com/questions/913374/how-to-subscribe-to-other-class-events-in-c. So it is not fully clear what you want to achieve and what the issue is - http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist. – Eugene Podskal Jan 15 '17 at 16:49

2 Answers2

1

You can use the method Form.OnClick to simulate a click on the Form. On my example I created a button and added a Click event to it. When the button is clicked, it simulates a Click on the Form, which triggers the Form's Click event.

private void button1_Click(object sender, EventArgs e) {
    // do something when it's clicked
    this.OnClick(new EventArgs());
}

private void Form1_Click(object sender, EventArgs e) {
    Console.WriteLine("a click occurred on the form");
}
Vinicius Victor
  • 348
  • 1
  • 10
0

I think you can do that with wndproc

Ori Nachum
  • 588
  • 3
  • 19