예제 #1
0
            /// <summary>
            /// Adds a <see cref="CheckableMenuItem"/> to the end of the <see cref="MenuItemCollection"/>.
            /// </summary>
            /// <param name="name">The name of the <see cref="Control"/> to be added to the end of the <see cref="MenuItemCollection"/>.</param>
            /// <param name="click">The action invoked when the child is clicked.</param>
            public void AddCheckable(string name, Action <IntPtr> click = null)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException(nameof(name));
                }
                if (Owner.IsInvalid)
                {
                    throw new InvalidHandleException();
                }

                CheckableMenuItem item = new CheckableMenuItem(new SafeControlHandle(Libui.MenuAppendCheckItem(Owner.Handle, name)), name);

                if (click != null)
                {
                    item.Clicked += (data) =>
                    {
                        if (data != null)
                        {
                            click(data);
                        }
                    };
                }
                base.Add(item);
            }
예제 #2
0
        static void Main(string[] args)
        {
            Application.Init();

            Menu fM = new Menu("File");
            CheckableMenuItem nI = fM.AppendCheckableItem("Hello world", true);
            MenuItem          qI = fM.AppendQuitItem();

            Window w = new Window("Hello world", 300, 300, true);
            Button b = new Button("Increment me");

            s = new Slider(0, 100);
            n = new Spinbox(0, 100);
            p = new ProgressBar();
            Checkbox         c  = new Checkbox("Error");
            ColorButton      cb = new ColorButton();
            EditableCombobox m  = new EditableCombobox();

            m.Text = w.Title;
            VBox x = new VBox();

            b.Clicked += (o, e) =>
            {
                val++;
                ApplyValues(val);
            };
            EventHandler <EventArgs> handle = (o, e) =>
            {
                var v = ((INumInput)o).Value;
                ApplyValues(v);
            };

            n.Changed  += handle;
            s.Changed  += handle;
            cb.Changed += (o, e) =>
            {
                w.MessageBox("Color", String.Format("{0} {1} {2} {3}",
                                                    cb.Color.R, cb.Color.G, cb.Color.B, cb.Color.A));
            };
            nI.Clicked += (o, e) =>
            {
                w.MessageBox("result", nI.Checked.ToString());
            };
            w.Closing += (o, e) =>
            {
                w.MessageBox("Bye!", "See you later", c.Checked);
                w.Destroy();
                Application.Quit();
            };

            w.Margins = 5;
            w.Child   = x;

            x.Padding = 5;
            x.Append(b);
            x.Append(s);
            x.Append(n);
            x.Append(p);
            x.Append(c);
            x.Append(cb);
            x.Append(m);
            w.Visible = true;

            Application.Main();
            Application.Finish();
        }