toolstrip class

 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);
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值