Exemplo n.º 1
0
        public SunButton CreateOperateButton(ClickType clickType)
        {
            float fontSize    = 9F;
            int   leftPadding = 0;

            var fontStyle = FontStyle.Regular;

            SunButton sunButton = new SunButton()
            {
            };

            sunButton.AutoSize = true;
            sunButton.Cursor   = System.Windows.Forms.Cursors.Hand;
            sunButton.FlatAppearance.BorderSize = 0;
            sunButton.FlatStyle               = System.Windows.Forms.FlatStyle.Flat;
            sunButton.Font                    = new System.Drawing.Font(familyName, fontSize, fontStyle);
            sunButton.Location                = new System.Drawing.Point(0, 0);
            sunButton.Margin                  = new System.Windows.Forms.Padding(0);
            sunButton.Name                    = MenuHelper.CreateName("btn");
            sunButton.Padding                 = new System.Windows.Forms.Padding(leftPadding, 0, 0, 0);
            sunButton.RightToLeft             = System.Windows.Forms.RightToLeft.No;
            sunButton.Size                    = new System.Drawing.Size(0, height);
            sunButton.Text                    = MenuHelper.GetNameByClickType(clickType);
            sunButton.TextAlign               = System.Drawing.ContentAlignment.MiddleCenter;
            sunButton.UseVisualStyleBackColor = true;

            switch (clickType)
            {
            case ClickType.Ignore:
                sunButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(191)))), ((int)(((byte)(102)))));
                break;

            case ClickType.AbsentMark:
                sunButton.ForeColor = System.Drawing.ColorTranslator.FromHtml("#4B9AFF");
                break;

            default:
                sunButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(102)))), ((int)(((byte)(102)))));
                break;
            }
            sunButton.Click += new System.EventHandler((object sender, EventArgs e) =>
            {
                var button = (SunButton)sender;
                //针对 菜单的点击事件
                this.ClickHandler?.Invoke(clickType, this.Param);
            });
            return(sunButton);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 颜色改变事件
 /// </summary>
 /// <param name="menu"></param>
 public void SetButtonClick(SunMenu menu)
 {
     //加入二三级菜单的点击颜色变化事件
     if (menu.Level > 1 && menu.TitleButton != null)
     {
         menu.TitleButton.Click += (object sender, EventArgs e) =>
         {
             //恢复颜色
             if (this.CurrentTitleButton != null)
             {
                 CurrentTitleButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
             }
             CurrentTitleButton = (SunButton)sender;
             //设置点击后的颜色
             CurrentTitleButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(188)))), ((int)(((byte)(135)))));
         };
     }
     menu.Children.ForEach(c =>
     {
         SetButtonClick(c);
     });
 }
Exemplo n.º 3
0
        public SunButton CreateSunButton()
        {
            float fontSize    = 10.5F;
            int   leftPadding = 20;

            var fontStyle = FontStyle.Regular;

            SunButton sunButton = new SunButton()
            {
            };

            switch (this.Level)
            {
            case 1:
                sunButton.Image           = this.Expand ? Properties.Resources.up : Properties.Resources.down;
                sunButton.BackgroundImage = Properties.Resources.backFull2x;
                fontStyle = System.Drawing.FontStyle.Bold;
                break;

            case 2:
                fontSize        = 9F;
                sunButton.Image = this.Expand ? Properties.Resources.upFull : Properties.Resources.downFull;
                //sunButton.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
                break;

            case 3:
                fontSize    = 9F;
                leftPadding = 22;
                break;

            default:
                break;
            }


            sunButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            sunButton.AutoSize   = true;
            sunButton.Cursor     = System.Windows.Forms.Cursors.Hand;
            sunButton.FlatAppearance.BorderSize = 0;
            sunButton.FlatStyle   = System.Windows.Forms.FlatStyle.Flat;
            sunButton.Font        = new System.Drawing.Font(familyName, fontSize, fontStyle);
            sunButton.Location    = new System.Drawing.Point(0, 0);
            sunButton.Margin      = new System.Windows.Forms.Padding(0);
            sunButton.Name        = MenuHelper.CreateName("btn");
            sunButton.Padding     = new System.Windows.Forms.Padding(leftPadding, 0, 0, 0);
            sunButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
            sunButton.Size        = new System.Drawing.Size(width, height);
            sunButton.Text        = this.Title + (this.level != 3 ? $"({this.Count})" : "");
            sunButton.TextAlign   = System.Drawing.ContentAlignment.MiddleLeft;
            //margin和padding
            if (this.Level == 3)
            {
                sunButton.Size = new System.Drawing.Size(0, height);
                int offset      = 4;
                int marginRight = 0;
                sunButton.Margin  = new Padding(leftPadding + offset, 0, marginRight, 0);
                sunButton.Padding = new System.Windows.Forms.Padding(0);
            }
            sunButton.UseVisualStyleBackColor = true;
            sunButton.Click += new System.EventHandler((object sender, EventArgs e) =>
            {
                var button        = (SunButton)sender;
                var currentExpend = this.Expand;
                this.Toggle(!currentExpend);

                //显示或者隐藏
                //switch (button.SunMenu.Level)
                //{
                //    case 1:
                //    case 2:
                //        var tmpParent = button.Parent;
                //        if (tmpParent.Parent == null)
                //        {
                //            return;
                //        }
                //        foreach (var item in tmpParent.Controls)
                //        {
                //            if (item is FlowLayoutPanel)
                //            {
                //                var tmpPanel = ((FlowLayoutPanel)item);
                //                tmpPanel.Visible = !tmpPanel.Visible;

                //            }
                //        }

                //        break;
                //    default:
                //        break;
                //}

                //改变图标


                //针对 菜单的点击事件
                this.ClickHandler?.Invoke(ClickType.Title, this.Param);
            });
            //给最后一级 布局,自动填充中间的空隙宽度
            if (this.Level == 3)
            {
                sunButton.SizeChanged += new EventHandler((object sender, EventArgs e) =>
                {
                    var button = (SunButton)sender;
                    //Console.WriteLine(button.Width);
                    int marginRight = width - 4 - button.Width - button.Margin.Left - button.Padding.Left - this.OperateButtonList.Count * 40;
                    var tmpMargin   = button.Margin;
                    tmpMargin.Right = Math.Max(0, marginRight);
                    button.Margin   = tmpMargin;
                });
            }
            //给 第二级 菜单 点击前后的颜色变化
            //if (this.Level == 2 || this.Level==3)
            //{
            //    sunButton.Enter += new EventHandler((object sender, EventArgs e) =>
            //    {
            //        var button = (SunButton)sender;
            //        button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(188)))), ((int)(((byte)(135)))));

            //    });
            //    sunButton.Leave += new EventHandler((object sender, EventArgs e) =>
            //    {
            //        var button = (SunButton)sender;
            //        button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
            //    });
            //}

            return(sunButton);
        }