zoukankan      html  css  js  c++  java
  • winform自定义按钮菜单

       //填写其他报表按钮
            private void btnWriteRep_Click(object sender, EventArgs e)
            {
                try
                {
                    Point p1 = new Point();
                    Point p = this.btnWriteRep.Location;

                    p1.X = p.X;
                    p1.Y = p.Y + btnWriteRep.Height;
                    contextmenustrip.Show(this.flowLayoutPanel3, p1);              
                }
                catch (Exception ex)
                {

                }
            }
            //加载填写其他报表下拉按钮菜单
            private bool LoadDropButton()
            {
                try
                {
                    contextmenustrip = new ContextMenuStrip();//下拉菜单
                    contextmenustrip.Font = new Font("宋体", 10f);
                    List<ReportListItem> reportlist = basedeclar.GetReportListItem("Y");
                    foreach (ReportListItem rep in reportlist)
                    {
                        contextmenustrip.Items.Add(AddMenu("[" + rep.Bbzt_mc + "]" + rep.Name, rep.Value, rep.Bbzt_mc));
                    }
                    //分隔线
                    ToolStripSeparator line = new ToolStripSeparator();
                    contextmenustrip.Items.Add(line);

                    contextmenustrip.Items.Add(AddMenu("选择更多报表......", "", ""));
                    contextmenustrip.ItemClicked += new ToolStripItemClickedEventHandler(contextmenustrip_ItemClicked);
                    return true;
                }
                catch (Exception e)
                {
                    MessageBox.Show("加载按钮(填写其他报表)菜单失败");
                    return false;
                }
            }
            //下拉项单击事件
            void contextmenustrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
            {
                try
                {
                    if (isChanged)
                    {
                        if (MessageBox.Show("数据有变化,是否保存", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            btnSave_Click(sender, null);
                        }
                        else
                        {
                            //LoadAxCellData();
                            axCell1.ReadFromBuffer(PreBytes);                       
                        }
                        isChanged = false;
                    }
                    //选择更多报表显示所有报表
                    if (e.ClickedItem.Text.Contains("选择更多报表"))
                    {
                        isCloseMenu = true;
                        contextmenustrip.Items.RemoveAt(contextmenustrip.Items.Count - 1);
                        List<ReportListItem> reportlist = basedeclar.GetReportListItem("N");
                        foreach (ReportListItem rep in reportlist)
                        {
                            contextmenustrip.Items.Add(AddMenu("[" + rep.Bbzt_mc + "]" + rep.Name, rep.Value, rep.Bbzt_mc));
                        }
                        contextmenustrip.Closing += new ToolStripDropDownClosingEventHandler(contextmenustrip_Closing);
                    }
                    else
                    {
                        isCloseMenu = false;
                        //axCell1.SetSheetVisible(axCell1.GetCurSheet(), false);
                        //axCell1.SetSheetVisible(axCell1.GetSheetIndex(e.ClickedItem.Name), true);
                        axCell1.SetCurSheet(axCell1.GetSheetIndex(e.ClickedItem.Name));                   
                    }
                }
                catch (Exception ex)
                {

                }
            }
            //下拉菜单关闭判断是否关闭
            void contextmenustrip_Closing(object sender, ToolStripDropDownClosingEventArgs e)
            {
                if (isCloseMenu)
                {
                    if (e.CloseReason == ToolStripDropDownCloseReason.AppClicked || e.CloseReason == ToolStripDropDownCloseReason.Keyboard)
                        e.Cancel = false;
                    else
                        e.Cancel = true;
                }
            }

  • 相关阅读:
    flex+spring3.0+blazds 数据推送整理版
    深入理解java虚拟机学习笔记1.
    一个netty序列化引起的思考。
    万年历
    面试理论题
    EF之Database First
    20120902 09:29 SQL、LINQ、Lambda 三种用法
    内容漂浮在图片上(div漂浮)
    生成订单号
    时间对比
  • 原文地址:https://www.cnblogs.com/dachuang/p/4785701.html
Copyright © 2011-2022 走看看