SnuKies
SnuKies

Reputation: 1723

Find when something on form has been clicked

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?

Upvotes: 1

Views: 76

Answers (2)

Vinicius Victor
Vinicius Victor

Reputation: 358

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");
}

Upvotes: 1

Ori Nachum
Ori Nachum

Reputation: 598

I think you can do that with wndproc

Upvotes: 0

Related Questions