예제 #1
0
        public CommandBarCheckBox AddCheckBox(Image image, string text)
        {
            CommandBarCheckBox checkBox = this.AddCheckBox(text);

            checkBox.Image = image;
            return(checkBox);
        }
예제 #2
0
        public CommandBarCheckBox AddCheckBox(string text, Keys shortcut)
        {
            CommandBarCheckBox checkBox = this.AddCheckBox(text);

            checkBox.Shortcut = shortcut;
            return(checkBox);
        }
예제 #3
0
        public CommandBarCheckBox AddCheckBox(string text)
        {
            CommandBarCheckBox checkBox = new CommandBarCheckBox(text);

            this.Add(checkBox);
            return(checkBox);
        }
예제 #4
0
        private void NotifyCustomDrawToolBar(ref Message m)
        {
            m.Result = (IntPtr)NativeMethods.CDRF_DODEFAULT;

            NativeMethods.DLLVERSIONINFO dvi = new NativeMethods.DLLVERSIONINFO();
            dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVERSIONINFO));
            NativeMethods.DllGetVersion(ref dvi);
            if (dvi.dwMajorVersion < 6)
            {
                NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW)m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW));
                NativeMethods.RECT             rc   = tbcd.nmcd.rc;

                Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                Graphics       graphics = Graphics.FromHdc(tbcd.nmcd.hdc);
                CommandBarItem item     = items[(int)tbcd.nmcd.dwItemSpec];

                bool hot      = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0);
                bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0);
                bool disabled = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_DISABLED) != 0);

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;
                if ((checkBox != null) && (checkBox.IsChecked))
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (selected)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (hot)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
                }

                Image image = item.Image;
                if (image != null)
                {
                    Size  size  = image.Size;
                    Point point = new Point(rc.left + ((rc.right - rc.left - size.Width) / 2), rc.top + ((rc.bottom - rc.top - size.Height) / 2));
                    NativeMethods.DrawImage(graphics, image, point, disabled);
                }

                m.Result = (IntPtr)NativeMethods.CDRF_SKIPDEFAULT;
            }
        }
예제 #5
0
        private NativeMethods.TBBUTTONINFO GetButtonInfo(int index)
        {
            CommandBarItem item = items[index];

            NativeMethods.TBBUTTONINFO buttonInfo = new NativeMethods.TBBUTTONINFO();
            buttonInfo.cbSize = Marshal.SizeOf(buttonInfo);

            buttonInfo.dwMask    = NativeMethods.TBIF_IMAGE | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE | NativeMethods.TBIF_COMMAND;
            buttonInfo.idCommand = index;
            buttonInfo.iImage    = NativeMethods.I_IMAGECALLBACK;
            buttonInfo.fsStyle   = NativeMethods.BTNS_BUTTON | NativeMethods.BTNS_AUTOSIZE;
            buttonInfo.fsState   = 0;
            buttonInfo.cx        = 0;
            buttonInfo.lParam    = IntPtr.Zero;
            buttonInfo.lpszText  = string.Empty;
            buttonInfo.cchText   = 0;

            if (!item.Visible)
            {
                buttonInfo.fsState |= NativeMethods.TBSTATE_HIDDEN;
            }

            CommandBarComboBox comboBox = item as CommandBarComboBox;

            if (comboBox != null)
            {
                buttonInfo.cx     = (short)(comboBox.Width + 4);
                buttonInfo.dwMask = NativeMethods.TBIF_SIZE;
            }

            if (item is CommandBarSeparator)
            {
                buttonInfo.fsStyle |= NativeMethods.BTNS_SEP;
            }
            else
            {
                if (item.Enabled)
                {
                    buttonInfo.fsState |= NativeMethods.TBSTATE_ENABLED;
                }

                CommandBarMenu menu = item as CommandBarMenu;
                if ((menu != null) && (menu.Items.Count > 0))
                {
                    buttonInfo.fsStyle |= NativeMethods.BTNS_DROPDOWN;
                }

                if (style == CommandBarStyle.ToolBar)
                {
                    if (item is CommandBarMenu)
                    {
                        buttonInfo.fsStyle |= NativeMethods.BTNS_WHOLEDROPDOWN;
                    }
                }

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;
                if ((checkBox != null) && (checkBox.IsChecked))
                {
                    buttonInfo.fsState |= NativeMethods.TBSTATE_CHECKED;
                }
            }

            if (item is CommandBarSeparator)
            {
                buttonInfo.iImage = NativeMethods.I_IMAGENONE;
            }
            else if (item.Image != null)
            {
                buttonInfo.iImage = index;
            }

            if ((this.Style == CommandBarStyle.Menu) && (item.Text != null) && (item.Text.Length != 0))
            {
                buttonInfo.dwMask  |= NativeMethods.TBIF_TEXT;
                buttonInfo.lpszText = item.Text + '\0';
                buttonInfo.cchText  = item.Text.Length;
            }

            return(buttonInfo);
        }
            private void DrawImage(Graphics graphics, Rectangle bounds, bool selected, bool disabled)
            {
                Rectangle rectangle = new Rectangle(bounds.X, bounds.Y, imageSize.Width + 6, bounds.Height);

                Size      checkSize      = SystemInformation.MenuCheckSize;
                Rectangle checkRectangle = new Rectangle(bounds.X + 1 + ((imageSize.Width + 6 - checkSize.Width) / 2), bounds.Y + ((bounds.Height - checkSize.Height) / 2), checkSize.Width, checkSize.Height);

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;

                if (this.IsFlatMenu)
                {
                    DrawBackground(graphics, rectangle, selected);

                    if ((checkBox != null) && (checkBox.IsChecked))
                    {
                        int height = bounds.Height - 2;
                        graphics.DrawRectangle(SystemPens.Highlight, new Rectangle(bounds.X + 1, bounds.Y + 1, imageSize.Width + 3, height - 1));
                        graphics.FillRectangle(SystemBrushes.Menu, new Rectangle(bounds.X + 2, bounds.Y + 2, imageSize.Width + 2, height - 2));
                    }

                    Image image = item.Image;
                    if (image != null)
                    {
                        Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
                        NativeMethods.DrawImage(graphics, image, point, disabled);
                    }
                    else
                    {
                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            Color color = (disabled ? SystemColors.GrayText : SystemColors.MenuText);
                            this.DrawCheck(graphics, checkRectangle, color);
                        }
                    }
                }
                else
                {
                    Image image = item.Image;
                    if (image == null)
                    {
                        this.DrawBackground(graphics, rectangle, selected);

                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            Color color = (disabled ? (selected ? SystemColors.GrayText : SystemColors.ControlDark) : (selected ? SystemColors.HighlightText : SystemColors.MenuText));
                            this.DrawCheck(graphics, checkRectangle, color);
                        }
                    }
                    else
                    {
                        DrawBackground(graphics, rectangle, false);
                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                        }
                        else if (selected)
                        {
                            ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
                        }

                        Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
                        NativeMethods.DrawImage(graphics, image, point, disabled);
                    }
                }
            }