Ejemplo n.º 1
0
            /// <summary>
            /// Adds a <see cref="MenuItem"/> 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 Add(string name, Action <IntPtr> click = null)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException(nameof(name));
                }
                if (Owner.IsInvalid)
                {
                    throw new InvalidHandleException();
                }

                MenuItem item = new MenuItem(new SafeControlHandle(Libui.MenuAppendItem(Owner.Handle, name)), name);

                if (click != null)
                {
                    item.Clicked += (data) =>
                    {
                        if (data != null)
                        {
                            click(data);
                        }
                    };
                }
                base.Add(item);
            }