Bir Click lenme olayından başka bir Click lenme olayını tetikleme RRS feed

  • Question

  • Formun MouseDoubleClick olayına yazdığım kodun bir Buton un tıklanması olayında da tetiklenmesini istiyorum. Yani buton tıklandığında Form_MouseDoubleClick() olayı tetiklensin. nasıl yapabilirim acaba?
    • Moved by CoolDadTx Monday, November 6, 2017 3:08 PM Winforms related
    • Moved by Stanly Fan Wednesday, November 15, 2017 5:42 AM
    Saturday, November 4, 2017 6:58 PM

All replies

  • You can simply call the event handler from the button click:

    private void Button1_Click(object sender, EventArgs e)
        MouseEventArgs mea = new MouseEventArgs(MouseButtons.Left, 1, button1.Left, button1.Top, 0);
        this.Form1_MouseDoubleClick(this, mea);

    Note that in the preceding example I have set the (x,y) where the doubleclick occurred to the location of the button itself. Obviously you would adjust this as needed if your doubleclick handler (which in the preceding example I named Form1_MouseDoubleClick) requires a different values.

    Although this will work, a more elegant approach would be to refactor the code so that you extract the content of the doubleclick handler into a separate method, and then call that method from the button click.

    Sunday, November 5, 2017 7:48 PM
  • Hello Demetsen,

    There is an easy way to implement the feature via registering a method to button event.

    public partial class Form7 : Form
            public Form7()
                button1.Click += Form7_DoubleClick;
            private void Form7_DoubleClick(object sender, EventArgs e)
            private void button1_Click(object sender, EventArgs e)


    Note. This  is English forum ,you should translate the language to English so that we can provide more support for you.


    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 6, 2017 8:35 AM