6

i have an application develped in c# long before by some developers,now we started providing maintanance.

When i went through the code i can see a click event "private void _menuNewView_Click(object sender, EventArgs e)" which is not triggering when i put a break point and started action from UI, a strange beaviour.

When i open the design view, i open the context menu strip and clicked the menu "newview" it is triggering in to the code behind click event "private void _menuNewView_Click(object sender, EventArgs e)" .

But from UI i started application and put break point in click event in code and did the operation newview but its not triggering, Can anybody help me here, the new view action is not complete as of now This is one of the reference of click event

5
  • Try Find All References on the event handler. Where is it referenced? Commented Oct 23, 2011 at 18:47
  • That's the only reference? If you put a breakpoint there, does it run? Commented Oct 23, 2011 at 18:55
  • Make sure that there is not unregistering the click event in any other place (-=) or re-construction of the _menuNew anywhere Commented Oct 23, 2011 at 19:08
  • Does the menuNew.Click += line get executed? Commented Oct 23, 2011 at 19:13
  • Hi all sorry for taking your valuable timing, the same click event is used in some other cotrols which is the responsible one , i put break point there and now everything fine Commented Oct 23, 2011 at 19:15

3 Answers 3

10

You can triger it on 2 ways:

  1. With subscribing to the Click event of button:

    this.button1.Click += new EventHandler(button1_Click);
    //there you have an event:
    private void button1_Click(object sender, EventArgs e)
    {
       //code inside event...
    }
    
  2. or with an actual code:

    button1_Click(new object(), new EventArgs());
    
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for providing information,,but mistake was from my side same click event defined in two different pages and i selected wrong one
:D i actually did the same mistake and your comment helped me thank you!
1

I came here for help on triggering a Click event on a toolstripitem that I had made an event for manually so I had no method to call directly. But turns out that the tsi have a method called

PerfomClick() 

That triggers the click event; I didn’t think to look for a method so I though to share it here and hopefully help others in the same situation.

My code looks like this if it helps:

Click performed on the second toolstrip item in the contexts menu

 ContextMenuStrip.Items[1].PerformClick();

Then the event it self

 tsmi.Click += (s, e) =>
 {
      BackUpVSSolution(@"C:\temp\");
 };

And it Works like a charm

thought i whould add this as well. if you just wanna start what ever proses is related to a file type or something you can just change it to something like

 tsmi.Click += (s, e) =>
 {
     Process.Start("C:\temp\temptext.txt");
 };

and this will open your default text editor program.

Comments

0

This Issue will Occur, If the Button Control Name Changes After the Click_Event Created. So i think, Copy your Code and Delete the Event from Code view, Run your Solution and Definitely an Error occurs, Click on the Error and that will Guide you to Designer Generated Code. Delete/Comment that part(Single Line of Click_Event_Name). Rebuild Your Code and Create a new Click_Event and Paste your Copied Code. Its Good,If you already find any solutions. Hope this Helps Somebody Else in the same trouble.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.