コード例 #1
0
ファイル: Proton.cs プロジェクト: HJfod/proton-sharp
 public static void AddContextMenu(this Control _c, Control _par, dynamic[] _menu)
 {
     _c.MouseUp += (s, e) => {
         if (e.Button == MouseButtons.Right)
         {
             var m = new MenuWindow(_par, _menu);
             _par.Controls.Add(m);
             m.BringToFront();
         }
     };
 }
コード例 #2
0
        public int ParseMenu(dynamic[] _menu, Control _par)
        {
            int maxLength = 0;

            foreach (dynamic Sub in _menu)
            {
                try {
                    string T = Sub.Type;
                    switch (T)
                    {
                    case "Separator":
                        this.Controls.Add(new Elements.Separator(this.Width - Style.MenuPadding * 2, Style.MenuPadding, this.HoverColor));
                        break;

                    case "Table":
                        TableLayoutPanel p = new TableLayoutPanel();
                        p.AutoSize    = true;
                        p.ColumnCount = Sub.Width;
                        p.RowCount    = (int)Math.Ceiling((Decimal)Sub.Contents.Length / (Decimal)Sub.Width);
                        foreach (string s in Sub.Contents)
                        {
                            p.Controls.Add(new Elements.TinyOption(s, this.BackColor, this.HoverColor, Sub.Click));
                        }
                        this.Controls.Add(p);
                        break;

                    case "Checkbox":
                        Elements.Option b = new Elements.Option($"{Sub.Text}   #{(Sub.GetVar() ? "--BT" : "--BF")}", this.BackColor, this.HoverColor);
                        b.AutoSize = true;
                        b.Click   += (s, e) => {
                            Sub.SetVar(!Sub.GetVar());
                            b.Text = $"{Sub.Text}   #{(Sub.GetVar() ? "--BT" : "--BF")}";

                            try {
                                bool x = Sub.NoClose;
                            } catch (Exception) {
                                Main.CloseAllMenus(_par);
                            }
                        };
                        this.Controls.Add(b);

                        if (b.ClientRectangle.Width > maxLength)
                        {
                            maxLength = b.ClientRectangle.Width;
                        }
                        break;

                    case "List":
                        Elements.Option list = new Elements.Option(Sub.Text, this.BackColor, this.HoverColor);
                        list.Size     = new Size(this.Width, Style.MenuOptionSize);
                        list.AutoSize = true;

                        List <dynamic> items = new List <dynamic>();
                        foreach (dynamic item in Sub.List)
                        {
                            items.Add(new {
                                Type   = "Checkbox",
                                Text   = item.Text,
                                GetVar = new Func <bool> (() => { return(item.Encoding.Equals(Sub.GetVar())); }),
                                SetVar = new Func <bool, bool> (_val => Sub.SetVar(item.Encoding))
                            });
                        }

                        list.Text   = $"{list.Text}   #\u2bc8";
                        list.Click += (s, e) => {
                            Main.CloseAllMenus(_par, this.Level + 1);

                            MenuWindow m = new MenuWindow(_par, items.ToArray(), this.isTop,
                                                          new Point(this.Location.X + this.Width, this.Location.Y + list.Top), this.Level + 1);
                            _par.Controls.Add(m);
                            m.BringToFront();
                        };

                        this.Controls.Add(list);

                        if (list.ClientRectangle.Width > maxLength)
                        {
                            maxLength = list.ClientRectangle.Width;
                        }
                        break;
                    }
                } catch (Exception) {
                    Elements.Option b = new Elements.Option(Sub.Name, this.BackColor, this.HoverColor);
                    b.Size     = new Size(this.Width, Style.MenuOptionSize);
                    b.AutoSize = true;

                    try {
                        dynamic[] subm = Sub.Menu;
                        b.Text   = $"{b.Text}#\u2bc8";
                        b.Click += (s, e) => {
                            Main.CloseAllMenus(_par, this.Level + 1);

                            MenuWindow m = new MenuWindow(_par, subm, this.isTop,
                                                          new Point(this.Location.X + this.Width, this.Location.Y + b.Top), this.Level + 1);
                            _par.Controls.Add(m);
                            m.BringToFront();
                        };
                    } catch (Exception) {
                        b.Click += Sub.Click;
                        b.Click += (s, e) => {
                            try {
                                bool x = Sub.NoClose;
                            } catch (Exception) {
                                Main.CloseAllMenus(_par);
                            }
                        };
                    }

                    if (b.Text.Contains("#"))
                    {
                        b.Text = b.Text.Replace("#", "   #");
                    }

                    this.Controls.Add(b);

                    if (b.ClientRectangle.Width > maxLength)
                    {
                        maxLength = b.ClientRectangle.Width;
                    }
                }
            }
            return(maxLength);
        }