How to add an event on a menu in C# project? - c#

I have a C# Windows Forms App that contain a menu bar.
I want to display a Help Message when I press on the "HELP" menu button.
All that I can see when I press view code is this:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
I think that I need to create inside the function a MessageBox or an event that will display the desired message.
Do you have any idea how should I do this, please?

Below should work for what your asking. If you are on your form you can double click the button you want to interact with, and Visual Studio should take you to the empty method.
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is supposed to be helpful");
}

Related

VSTO Ribbon - general/abstract button click event?

In a C# VSTO Ribbon, you can design and place buttons and you can program whatever you want each button to do i.e. an action that will occur on each individual button click event can be defined by the programmer.
I have some code I would like to perform every time a button was clicked -
regardless of which button was clicked. A simple example includes measuring the time that the button click event was received: I want this for all my buttons, so, I am looking for a general / abstract event handling all button clicks or something of the sort rather than each event one by one. Does this exist in VSTO or is there a clean implementation to it?
Here is a simple illustration of the problem in code.
I have 3 buttons: btn1, btn2 and btn3. And I have defined what I will do for each click as follows:
private void btn1_Click(object sender, RibbonControlEventArgs e)
{
//same code
//btn1 specific code
}
private void btn2_Click(object sender, RibbonControlEventArgs e)
{
//same code
//btn2 specific code
}
private void btn3_Click(object sender, RibbonControlEventArgs e)
{
//same code
//btn3 specific code
}
The problem is clear: there is part of the code that I want to do that is the same for each click. So is there a general click event where I can define the same code only just once?

Xamarin Forms. How I can focus on the end of entry when I press the button?

private void Sum(object sender, EventArgs e)
{
AddSign('+');
calculatorString.Focus();
}
After pressing button I want to focus on the end of entry.
Image with design of app, xaml code and description of my problem :)
I suppose you have to create a CustomRenderer. Here some notes
Entry CustomRenderer
Then you should use setSelection

How to programmatically click on cross button X c#

i searched google lot to know how can i programmatically click on cross button X using c#. i got the below code which is used for different purpose.
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
if (string.Equals((sender as Button).Name, #"CloseButton"))
// Do something proper to CloseButton.
else
// Then assume that X has been clicked and act accordingly.
}
so anyone can tell me How to programmatically click on cross button for closing form. thanks
To check the close reason you can use the CloseReason enum
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.ApplicationExitCall)
// Do something...
}
If you want to programattically close a form you can use
this.Close();
This will launch the FormClosing event that is displayed above.
I hope this helps.
If you want to emulate close click investigate SendMessage to send WM_CLOSE to you window.

How do you PerformClick(); for a button on a different tab?

I'm using Visual c# express 2010, I have 3 tabs and on the first tab there is a button that exits the program. I'm trying to call that button click on the 2nd and 3rd tab with
btnExit.PerformClick();
but since it isn't visible nothing happens. How would I call the invisible button click?
any help would be appreciated
EDIT:
Thanks for the replies, the two answers work great but I found a way that I think is easier and better.
instead of systematically changing tabs or calling a whole different method, I did this
btnExit_Click(sender, e);
I can put that in any other button click and it works great, very simple to.
I think it's better to create a method that actually has the code to exit the program, and call that method from btnExit click event and also other buttons click event, than PerformClick of the exit button.
void ExitApplication()
{
// code to exit the application
}
protected void btnExit_Click(object sender, EventArgs e)
{
ExitApplication();
}
protected void ButtonInOtherTab_Click(object sender, EventArgs e)
{
ExitApplication();
}
This way it's easier to read and understand.
myTabs.SelectedTab = specificTab;
btnExit.PerformClick();

ButtonClick in DropDown not working in VS2010/Outlook2010

I'm working on an add-in for Outlook 2010. I've created a new Ribbon Tab with a dropdown box. I'd like for the data in the dropdown to update when I click the dropdown button, but nothing is occurring. I've written the sample code below for testing purposes and nothing fires:
private void dropDown1_ButtonClick(object sender, RibbonControlEventArgs e)
{
MessageBox.Show("Dropdown CLick");
}
This is as simple as it gets, but nothing is firing. Any ideas of what I might be doing wrong? The only other code that exists in this ribbon right now is what loads the data.
Thank you
From my understanding
private void dropDown1_Click(object sender, RibbonControlEventArgs e)
{
MessageBox.Show("Dropdown CLick");
}
is what you wanna do. No where did I see ButtonClick as the proper tag.

Categories

Resources