コード例 #1
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
        private void WmNotifyDropDown(ref Message m)
        {
            NativeMethods.NMTOOLBAR nmTB = (NativeMethods.NMTOOLBAR)m.GetLParam(typeof(NativeMethods.NMTOOLBAR));
            ToolBoxButton           tbb  = buttons[nmTB.iItem];
            Menu menu = tbb.DropDownMenu;

            if (menu != null)
            {
                NativeMethods.RECT      rc  = new NativeMethods.RECT();
                NativeMethods.TPMPARAMS tpm = new NativeMethods.TPMPARAMS();
                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_GETRECT, nmTB.iItem, ref rc);

                if ((menu.GetType()).IsAssignableFrom(typeof(ContextMenu)))
                {
                    ((ContextMenu)menu).Show(this, new Point(rc.left, rc.bottom));
                }
                else
                {
                    UnsafeNativeMethods.MapWindowPoints(new HandleRef(nmTB.hdr, nmTB.hdr.hwndFrom), NativeMethods.NullHandleRef, ref rc, 2);
                    tpm.rcExclude_left   = rc.left;
                    tpm.rcExclude_top    = rc.top;
                    tpm.rcExclude_right  = rc.right;
                    tpm.rcExclude_bottom = rc.bottom;
                    UnsafeNativeMethods.TrackPopupMenuEx(new HandleRef(menu, menu.Handle), NativeMethods.TPM_LEFTALIGN | NativeMethods.TPM_LEFTBUTTON | NativeMethods.TPM_VERTICAL, rc.left, rc.bottom, new HandleRef(this, Handle), tpm);
                }
            }
        }
コード例 #2
0
        public void Insert(int index, ToolBoxButton value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("无效 value");
            }
            if (index < 0 || ((owner.buttons != null) && (index > owner.buttonsCount)))
            {
                throw new ArgumentOutOfRangeException("无效 index");
            }

            if (owner.buttons == null)
            {
                owner.buttons = new ToolBoxButton[5];
            }
            else if (owner.buttons.Length == owner.buttonsCount)
            {
                ToolBoxButton[] newButtons = new ToolBoxButton[owner.buttonsCount + 5];
                Array.Copy(owner.buttons, 0, newButtons, 0, owner.buttonsCount);
                owner.buttons = newButtons;
            }
            if (index < owner.buttonsCount)
            {
                Array.Copy(owner.buttons, index, owner.buttons, index + 1, owner.buttonsCount - index);
            }

            owner.buttons[index] = value;
            owner.buttonsCount++;

            owner.NativeInsert(value, index);
        }
コード例 #3
0
        public int Add(ToolBoxButton value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            int index = owner.buttonsCount;

            if (owner.buttons == null)
            {
                owner.buttons = new ToolBoxButton[5];
            }
            else if (owner.buttons.Length == owner.buttonsCount)
            {
                ToolBoxButton[] newButtons = new ToolBoxButton[owner.buttonsCount + 5];
                Array.Copy(owner.buttons, 0, newButtons, 0, owner.buttonsCount);
                owner.buttons = newButtons;
            }

            if (index < owner.buttonsCount)
            {
                Array.Copy(owner.buttons, index, owner.buttons, index + 1, owner.buttonsCount - index);
            }
            value.owner          = owner;
            owner.buttons[index] = value;
            owner.buttonsCount++;
            owner.NativeInsert(value, index);
            return(index);
        }
コード例 #4
0
        public int Add(string text)
        {
            ToolBoxButton value = new ToolBoxButton(text);
            int           index = owner.buttonsCount;

            if (owner.buttons == null)
            {
                owner.buttons = new ToolBoxButton[5];
            }
            else if (owner.buttons.Length == owner.buttonsCount)
            {
                ToolBoxButton[] newButtons = new ToolBoxButton[owner.buttonsCount + 5];
                Array.Copy(owner.buttons, 0, newButtons, 0, owner.buttonsCount);
                owner.buttons = newButtons;
            }

            if (index < owner.buttonsCount)
            {
                Array.Copy(owner.buttons, index, owner.buttons, index + 1, owner.buttonsCount - index);
            }
            value.owner          = owner;
            owner.buttons[index] = value;
            owner.buttonsCount++;
            owner.NativeInsert(value, index);
            return(index);
        }
コード例 #5
0
        public void Remove(ToolBoxButton value)
        {
            int index = IndexOf(value);

            if (index != -1)
            {
                RemoveAt(index);
            }
        }
コード例 #6
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
 protected virtual object[] GetButtons()
 {
     ToolBoxButton[] result = new ToolBoxButton[buttonsCount];
     if (buttonsCount > 0)
     {
         Array.Copy(buttons, 0, result, 0, buttonsCount);
     }
     return(result);
 }
コード例 #7
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
 internal void NativeUpdateButtonAt(ToolBoxButton button, int index)
 {
     if (IsHandleCreated)
     {
         button.owner   = this;
         buttons[index] = button;
         NativeMethods.TBBUTTONINFO btnINFO = button.GetTBBUTTONINFO(index);
         UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.TB_SETBUTTONINFO, index, ref btnINFO);
     }
 }
コード例 #8
0
 public int IndexOf(ToolBoxButton value)
 {
     for (int index = 0; index < Count; ++index)
     {
         if (this[index] == value)
         {
             return(index);
         }
     }
     return(-1);
 }
コード例 #9
0
ファイル: ToolBoxButton.cs プロジェクト: A10000666666/Mine
 public int FindIndex(ToolBoxButton value)
 {
     for (int x = 0; x < owner.Buttons.Count; x++)
     {
         if (owner.Buttons[x] == this)
         {
             return(x);
         }
     }
     return(-1);
 }
コード例 #10
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
 internal void NativeInsert(ToolBoxButton value, int index)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (IsHandleCreated)
     {
         if ((value.Appearance & TBBAppearance.Separator) != 0)
         {
             value.Width = 0;
         }
         else
         {
             Size edge = SystemInformation.Border3DSize;
             Size size = Size.Empty;
             if (!string.IsNullOrEmpty(value.Text))
             {
                 using (Graphics g = Graphics.FromHwnd(Handle))
                 {
                     if (!string.IsNullOrEmpty(value.Text))
                     {
                         size        = Size.Ceiling(g.MeasureString(value.Text, Font));
                         size.Width += 10;
                     }
                 }
             }
             if ((appearance & TBAppearance.List) != 0)//如果有List属性
             {
                 value.Width = size.Width + ImageSize.Width + edge.Width * 3;
             }
             else
             {
                 value.Width = size.Width > ImageSize.Width ? size.Width + edge.Width * 4 : ImageSize.Width + edge.Width * 4;
             }
             if ((value.Appearance & TBBAppearance.DropDown) != 0)
             {
                 value.Width += 16;
             }
             if ((value.Appearance & TBBAppearance.WholeDropDown) != 0)
             {
                 value.Width += 8;
             }
         }
         NativeMethods.TBBUTTON tbbutton = value.GetTBBUTTON(index);
         UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_INSERTBUTTON, index, ref tbbutton);
         NativeMethods.TBBUTTONINFO tbbuttonINFO = value.GetTBBUTTONINFO(index);
         UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_SETBUTTONINFO, index, ref tbbuttonINFO);
     }
 }
コード例 #11
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
        private void WmReflectCommand(ref Message m)
        {
            int           index  = NativeMethods.Util.LOWORD(m.WParam);
            ToolBoxButton button = buttonsCollection[index];

            if (button != null)
            {
                if (ButtonClick != null)
                {
                    ButtonClick(this, new ToolBoxButtonClickEventArgs(button));
                }
            }
            base.WndProc(ref m);
            ResetMouseEventArgs();
        }
コード例 #12
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
        private void WmNotifyNeedTextA(ref Message m)
        {
            NativeMethods.TOOLTIPTEXTA ttt = (NativeMethods.TOOLTIPTEXTA)m.GetLParam(typeof(NativeMethods.TOOLTIPTEXTA));
            int           commandID        = (int)ttt.hdr.idFrom;
            ToolBoxButton tbb = (ToolBoxButton)buttons[commandID];

            if (tbb != null && tbb.ToolTipText != null)
            {
                ttt.lpszText = tbb.ToolTipText;
            }
            else
            {
                ttt.lpszText = null;
            }
            ttt.hinst = IntPtr.Zero;
            Marshal.StructureToPtr(ttt, m.LParam, false);
        }
コード例 #13
0
ファイル: ToolBox.cs プロジェクト: A10000666666/Mine
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (imageList != null)
         {
             imageList = null;
         }
         if (buttonsCollection != null)
         {
             ToolBoxButton[] buttonCopy = new ToolBoxButton[buttonsCollection.Count];
             ((ICollection)buttonsCollection).CopyTo(buttonCopy, 0);
             buttonsCollection.Clear();
             foreach (ToolBoxButton b in buttonCopy)
             {
                 b.Dispose();
             }
         }
     }
     base.Dispose(disposing);
 }
コード例 #14
0
        public void Insert(int index, string text, int imageIndex)
        {
            ToolBoxButton value = new ToolBoxButton(text, imageIndex);

            Insert(index, value);
        }
コード例 #15
0
 public bool Contains(ToolBoxButton value)
 {
     return(IndexOf(value) != -1);
 }
コード例 #16
0
 public ToolBoxButtonClickEventArgs(ToolBoxButton button)
 {
     this.button = button;
 }
コード例 #17
0
        private void WmReflectNotifyChevronPushed(ref Message m)
        {
            NativeMethods.NMREBARCHEVRON nrch = (NativeMethods.NMREBARCHEVRON)m.GetLParam(typeof(NativeMethods.NMREBARCHEVRON));
            RebarBand   band      = Bands[nrch.wID];
            ContextMenu childMenu = new ContextMenu();

            if (band.Control != null && band.Control is ToolBox)
            {
                ToolBox            toolBar = band.Control as ToolBox;
                NativeMethods.RECT lpRect  = new NativeMethods.RECT();
                UnsafeNativeMethods.GetClientRect(new HandleRef(band.Control, band.Control.Handle), ref lpRect);
                int count = (int)UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                if (count != toolBar.buttonsCount)
                {
                    throw new ArgumentOutOfRangeException("count");
                }
                for (int i = 0; i < count; i++)
                {
                    NativeMethods.RECT brc = new NativeMethods.RECT();
                    UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_GETITEMRECT, i, ref brc);
                    if (brc.right >= (lpRect.right - lpRect.left))
                    {
                        ToolBoxButton btn = toolBar.Buttons[i];
                        if ((btn.Appearance & TBBAppearance.Separator) == 0)
                        {
                            string text = string.Empty;
                            if (!string.IsNullOrEmpty(btn.Text))
                            {
                                text = btn.Text;
                            }
                            else if (!string.IsNullOrEmpty(btn.ToolTipText))
                            {
                                text = btn.ToolTipText;
                            }
                            else
                            {
                                text = btn.MenuText;
                            }
                            MenuItem menuItem = null;
                            if (btn.Enable)
                            {
                                menuItem     = new MenuItem(text, OnMenuItemClick);
                                menuItem.Tag = btn;
                                toolBar.Renderer.SetEnable(menuItem, true);
                            }
                            else
                            {
                                menuItem = new MenuItem(text);
                                toolBar.Renderer.SetEnable(menuItem, false);
                            }
                            toolBar.Renderer.SetImageIndex(menuItem, btn.ImageIndex);
                            childMenu.MenuItems.Add(menuItem);
                            if (btn.DropDownMenu != null)
                            {
                                foreach (MenuItem item in btn.DropDownMenu.MenuItems)
                                {
                                    MenuItem newMenuItem = new MenuItem(item.Text, OnMenuSubItemClick);
                                    newMenuItem.Tag = item;
                                    menuItem.MenuItems.Add(newMenuItem);
                                }
                            }
                        }
                    }
                }
            }
            if (band.Control != null && band.Control is MenuBox)
            {
                MenuBox            menuBar = band.Control as MenuBox;
                NativeMethods.RECT lpRect  = new NativeMethods.RECT();
                UnsafeNativeMethods.GetClientRect(new HandleRef(band.Control, band.Control.Handle), ref lpRect);
                int count = (int)UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                if (count != menuBar.itemsCount)
                {
                    throw new ArgumentOutOfRangeException("count");
                }
                for (int i = 0; i < count; i++)
                {
                    NativeMethods.RECT brc = new NativeMethods.RECT();
                    UnsafeNativeMethods.SendMessage(new HandleRef(band.Control, band.Control.Handle), NativeMethods.TB_GETITEMRECT, i, ref brc);
                    if (brc.right >= (lpRect.right - lpRect.left))
                    {
                        MenuBoxItem menuBarItem = menuBar.Items[i];
                        MenuItem    menuItem    = new MenuItem(menuBarItem.Text);
                        childMenu.MenuItems.Add(menuItem);
                        if (menuBarItem.DropDownMenu != null)
                        {
                            foreach (MenuItem item in menuBarItem.DropDownMenu.MenuItems)
                            {
                                MenuItem newMenuItem = new MenuItem(item.Text, OnMenuSubItemClick);
                                newMenuItem.Tag = item;
                                menuItem.MenuItems.Add(newMenuItem);
                            }
                        }
                    }
                }
            }
            childMenu.Show(this, new Point(nrch.rc.left, nrch.rc.bottom));
        }