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

  • 相关阅读:
    分布式爬虫
    前端页面展示
    fillter根据value来匹配字段
    element ui 怎么去修改el-date-picker的时间
    element ui,input框输入时enter健进行搜索
    element ui 里面的table怎么弹出一个框让表中数据点击出现弹框
    修改数据结构记录,将同级数据改成父子集数据
    h5的复制功能的使用,Clipboard.js的使用,主要是在app里面使用
    在安卓手机下按钮会悬浮在键盘上,怎么解决vue.js
    last-child为啥不生效
  • 原文地址:https://www.cnblogs.com/dachuang/p/4785701.html
Copyright © 2011-2022 走看看