toolstripmenuitem ————是工具条的一个项
toolstripdropdownitem ————是 一个工具条项
步骤1语法:在menustrip工具条里添加 3个toolstripmenuitem项
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuFile,
this.menuClose,
this.menuView,
});
步骤2语法: 又在 this.menuFile这个项里添加一个 this.menu_Load项
this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menu_Load});
步骤3:添加contextmenustrip菜单
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuImage});
步骤4:再在contextmenustrip添加子菜单
this.menuImage.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuImageScale,
this.menuImageActual,
this.menuImageStretch});
步骤5:工具条里的(this.menuView)菜单项共享上下文(this.menuImage)菜单项 的语法:
this.menuView.dropdown=contextmenustrip;
步骤6:注册(this.menuImage)菜单项事件处理方法menuImage_DropDownItemClicked() 语法:
this.menuImage.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuImage_DropDownItemClicked);
方法的定义:
private void menuImage_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ProcessImageClick(e);
}
private void ProcessImageClick(ToolStripItemClickedEventArgs e)
{
ToolStripItem item=e.ClickedItem;
string enumVal=item.Tag as string;
if(enumVal!=null)
{
pictureBox1.SizeMode=(PictureBoxSizeMode)
Enum.Parse(typeof(PictureBoxSizeMode),enumVal);
}
}