Misbah Ahmad

How can I get Select EventHandler for ToolStripMenuItem as I we can get Select EventHandler for MenuItem

In Case of MenuItem:

MenuItem mi = new MenuItem("File");

mi.Select +=new EventHandler(mi_Select);

In Case of ToolStripMenuItem:

ToolStripMenuItem tsmi = new ToolStripMenuItem("File");

Tsmi. What should I do



Re: Windows Forms General How can I get Select EventHandler for ToolStripMenuItem

TilakGopi

Hi,

u can use any one of the following.

CheckedChanged Occurs when the value of the Checked property changes.
CheckStateChanged Occurs when the value of the CheckState property changes.
Click

Occurs when the ToolStripItem is clicked. (Inherited from ToolStripItem.)

FYI: http://msdn2.microsoft.com/en-us/library/system.windows.forms.toolstripmenuitem.aspx

Thanx,

Ch.T.Gopi Kumar






Re: Windows Forms General How can I get Select EventHandler for ToolStripMenuItem

Misbah Ahmad

These Event Handlers don't work for me. I need an Event Handler that work when the user places the pointer over a menu item.

Please help me.





Re: Windows Forms General How can I get Select EventHandler for ToolStripMenuItem

TilakGopi

May any one of the following

MouseDown Occurs when the mouse pointer is over the item and a mouse button is pressed. (inherited from ToolStripItem)
MouseEnter Occurs when the mouse pointer enters the item. (inherited from ToolStripItem)
MouseHover Occurs when the mouse pointer hovers over the item. (inherited from ToolStripItem)
MouseLeave Occurs when the mouse pointer leaves the item. (inherited from ToolStripItem)
MouseMove Occurs when the mouse pointer is moved over the item. (inherited from ToolStripItem)
MouseUp Occurs when the mouse pointer is over the item and a mouse button is released. (inherited from ToolStripItem)

these work for u

I guess, the bolded one may work for u.

Thanx,

Ch.T.Gopi Kumar.






Re: Windows Forms General How can I get Select EventHandler for ToolStripMenuItem

Misbah Ahmad

Dear I want to display menu command information on status bar as it is done in Internet Exprlorer. If you know a good solution then plz guide me. I have done using MenuItem but I want to do it using ToolStripItem.

Here is code using MenuItem

public partial class Form1 : Form
{
StatusBarPanel sbpMenuHelp;
string strSavePanelText;

public Form1()
{
InitializeComponent();

StatusBar sb = new StatusBar();
sb.Parent = this;
sb.ShowPanels = true;

sbpMenuHelp = new StatusBarPanel();
sbpMenuHelp.Text = " Ready";
sbpMenuHelp.AutoSize = StatusBarPanelAutoSize.Spring;

sb.Panels.Add(sbpMenuHelp);

Menu = new MainMenu();
EventHandler ehSelect = new EventHandler(MenuOnSelect);

MenuItem mi = new MenuItem("File");
mi.Select += ehSelect;
Menu.MenuItems.Add(mi);

mi = new MenuItem("Open");
mi.Select += ehSelect;
Menu.MenuItems[0].MenuItems.Add(mi);
}
protected override void OnMenuStart(EventArgs e)
{
strSavePanelText = sbpMenuHelp.Text;
}
protected override void OnMenuComplete(EventArgs e)
{
sbpMenuHelp.Text = strSavePanelText;
}
void MenuOnSelect(object obj, EventArgs e)
{
MenuItem mi = (MenuItem)obj;

string str;

switch(mi.Text)
{
case "File": str="Commands for working with files"; break;
case "Open": str = "Opens an existing docment"; break;

default: str = ""; break;
}
sbpMenuHelp.Text = str;
}
}





Re: Windows Forms General How can I get Select EventHandler for ToolStripMenuItem

TilakGopi

Hi,

Drag a ToolStrip on to ur form from toolbox.

Click on it (on the form) , u will get a drop down menu.

Select 'DropDownButton' item.

Then u'll be prompted to enter items as like menu items.Add items(File,Open).

Double click on each item, handlers will be created.

and modify ur code slightly like..

---------------------------------------------

public Form1()
{
InitializeComponent();

StatusBar sb = new StatusBar();
sb.Parent = this;
sb.ShowPanels = true;

sbpMenuHelp = new StatusBarPanel();
sbpMenuHelp.Text = " Ready";
sbpMenuHelp.AutoSize = StatusBarPanelAutoSize.Spring;

sb.Panels.Add(sbpMenuHelp);

//removed menu related code.

}


//Define handlers like followin

private void fileToolStripMenuItem_Click(object sender, EventArgs e)

{

sbpMenuHelp.Text = "Commands for working with files";

}

private void openToolStripMenuItem_Click(object sender, EventArgs e)

{

sbpMenuHelp.Text = "Opens an existing docment";

}

//Also remove protected override void OnMenuStart,OnMenuComplete and MenuOnSelect functions - menu related

Thanx,

Ch.T.Gopi Kumar.