Beispiel #1
0
        public static void DrawCheckBox(Graphics g, Rectangle rect, string text, Font font,
                                        Color foreColor, Color backColor,
                                        RightToLeft rightToLeft, bool isEnabled,
                                        bool isMouseOver, bool isFocused, bool drawLine, bool isChecked, CheckState checkState,
                                        Appearance appearance)
        {
            Rectangle checkRect = Rectangle.Empty;
            Rectangle textRect  = Rectangle.Empty;

            textRect = new Rectangle(rect.X + 4, rect.Y, rect.Width - 4, rect.Height);
            if (rightToLeft == RightToLeft.No)
            {
                checkRect = new Rectangle(rect.X, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }
            else
            {
                checkRect = new Rectangle(rect.Right - 15, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }

            if (appearance == Appearance.Normal)
            {
                if (rightToLeft == RightToLeft.No)
                {
                    textRect.X     += 10;
                    textRect.Width -= 10;
                }
                else
                {
                    textRect.Width -= 16;
                }

                #region PaintLine
                if (drawLine)
                {
                    using (Pen penLight = new Pen(StiColorUtils.Light(SystemColors.Control, 30)),
                           penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 50)))
                    {
                        int strWidth = (int)g.MeasureString(text, font).Width;

                        int posX = strWidth + 16 + rect.X;
                        int posY = rect.Y + rect.Height / 2;

                        if (posX < rect.Right)
                        {
                            g.DrawLine(penDark, posX, posY, rect.Right, posY);
                            g.DrawLine(penLight, posX, posY + 1, rect.Right, posY + 1);
                        }
                    }
                }
                #endregion

                if (isEnabled)
                {
                    using (var brush = new LinearGradientBrush(checkRect, StiColors.ContentDark, SystemColors.ControlLightLight, 45))
                    {
                        g.FillRectangle(brush, checkRect);
                    }
                }
                else
                {
                    g.FillRectangle(SystemBrushes.Control, checkRect);
                }

                if (isEnabled && (isMouseOver || isFocused))
                {
                    g.DrawRectangle(StiPens.SelectedText, checkRect);
                }
                else
                {
                    g.DrawRectangle(SystemPens.ControlDark, checkRect);
                }

                if (isChecked || checkState == CheckState.Indeterminate)
                {
                    StiControlPaint.DrawCheck(g, checkRect.X + 6, checkRect.Y + 6, isEnabled);
                }

                if (checkState == CheckState.Indeterminate)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(200, SystemColors.Control)))
                    {
                        g.FillRectangle(brush,
                                        checkRect.X + 1, checkRect.Y + 1, checkRect.Width - 2, checkRect.Height - 2);
                    }
                }

                #region Paint focus
                if (isFocused)
                {
                    Rectangle focusRect = textRect;
                    SizeF     sizeText  = g.MeasureString(text, font);
                    focusRect.Width  = (int)sizeText.Width;
                    focusRect.Y      = (focusRect.Height - ((int)sizeText.Height + 2)) / 2;
                    focusRect.Height = (int)sizeText.Height + 2;

                    if (rightToLeft == RightToLeft.Yes)
                    {
                        focusRect.X = textRect.Right - focusRect.Width;
                    }

                    ControlPaint.DrawFocusRectangle(g, focusRect);
                }
                #endregion
            }
            else
            {
                StiButton.DrawButton(g, rect, text, font, foreColor, backColor, null, -1, null, rightToLeft,
                                     false, isEnabled, isMouseOver, isChecked, false, isFocused,
                                     ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter);
            }

            #region Paint string
            if (appearance == Appearance.Normal)
            {
                using (var sf = new StringFormat())
                    using (var foreBrush = new SolidBrush(foreColor))
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        sf.HotkeyPrefix  = HotkeyPrefix.Show;

                        if (rightToLeft == RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }

                        if (isEnabled)
                        {
                            g.DrawString(text, font, foreBrush, textRect, sf);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(g, text, font, backColor,
                                                            textRect, sf);
                        }
                    }
            }
            #endregion
        }
        public StiColorBoxPopupForm(Control colorBox, Color selectedColor, IWindowsFormsEditorService edSrv) :
            base(colorBox)
        {
            try
            {
                SuspendLayout();

                #region InitializeComponent
                TabControl = new StiTabControl();
                TabControl.SuspendLayout();
                TabControl.Dock   = DockStyle.Fill;
                TabControl.Paint += new System.Windows.Forms.PaintEventHandler(TabControl_Paint);
                this.Controls.Add(TabControl);

                tbCustom = new StiTabPage();
                tbCustom.SuspendLayout();
                tbCustom.Text            = "Custom";
                tbCustom.DockPadding.All = 4;
                TabControl.Controls.Add(tbCustom);

                tbWeb = new StiTabPage();
                tbWeb.SuspendLayout();
                tbWeb.Text            = "Web";
                tbWeb.DockPadding.All = 4;
                TabControl.Controls.Add(tbWeb);

                tbSystem = new StiTabPage();
                tbSystem.SuspendLayout();
                tbSystem.DockPadding.All = 4;
                tbSystem.Text            = "System";
                TabControl.Controls.Add(tbSystem);

                lbWeb                = new ListBox();
                lbWeb.DrawMode       = System.Windows.Forms.DrawMode.OwnerDrawVariable;
                lbWeb.Dock           = DockStyle.Fill;
                lbWeb.IntegralHeight = false;
                lbWeb.TabStop        = false;
                lbWeb.MouseMove     += new System.Windows.Forms.MouseEventHandler(lbWeb_MouseMove);
                lbWeb.DrawItem      += new System.Windows.Forms.DrawItemEventHandler(lbWeb_DrawItem);

                tbWeb.Controls.Add(lbWeb);

                lbSystem                = new ListBox();
                lbSystem.DrawMode       = System.Windows.Forms.DrawMode.OwnerDrawVariable;
                lbSystem.Dock           = DockStyle.Fill;
                lbSystem.IntegralHeight = false;
                lbSystem.TabStop        = false;
                lbSystem.MouseMove     += new System.Windows.Forms.MouseEventHandler(lbWeb_MouseMove);
                lbSystem.DrawItem      += new System.Windows.Forms.DrawItemEventHandler(lbSystem_DrawItem);
                tbSystem.Controls.Add(lbSystem);

                btOther          = new StiButton();
                btOther.Location = new System.Drawing.Point(58, 216);
                btOther.Name     = "Other...";
                btOther.Size     = new System.Drawing.Size(80, 23);
                btOther.Click   += new System.EventHandler(btOther_Click);
                tbCustom.Controls.Add(btOther);

                TabControl.ResumeLayout(false);
                tbCustom.ResumeLayout(false);
                tbWeb.ResumeLayout(false);
                tbSystem.ResumeLayout(false);
                ResumeLayout(false);
                #endregion

                this.edSrv    = edSrv;
                this.colorBox = colorBox;

                #region InitColors
                this.SelectedColor = selectedColor;

                InitColors();

                this.lbSystem.SelectedIndex = -1;
                this.lbWeb.SelectedIndex    = -1;

                bool stop  = false;
                int  index = 0;

                string colorName = selectedColor.ToString();
                foreach (Color color in StiColors.SystemColors)
                {
                    if (color.ToString() == colorName)
                    {
                        this.TabControl.SelectedIndex = 2;
                        this.lbSystem.SelectedIndex   = index;
                        stop = true;
                        break;
                    }
                    index++;
                }

                if (!stop)
                {
                    index = 0;
                    int sc = selectedColor.ToArgb();
                    foreach (Color color in StiColors.Colors)
                    {
                        if (color.ToArgb() == sc)
                        {
                            this.TabControl.SelectedIndex = 1;
                            this.lbWeb.SelectedIndex      = index;
                            stop = true;
                            break;
                        }
                        index++;
                    }
                }

                if (!stop)
                {
                    this.TabControl.SelectedIndex = 0;
                }
                #endregion

                if (!this.DesignMode)
                {
                    Localize();
                }
            }
            catch
            {
            }
        }
        public static void DrawRadioButton(Graphics g, Rectangle rect, string text, Font font,
                                           Color foreColor, Color backColor,
                                           RightToLeft rightToLeft, bool isEnabled,
                                           bool isMouseOver, bool isFocused, bool isChecked,
                                           Appearance appearance)
        {
            Rectangle checkRect = Rectangle.Empty;
            Rectangle textRect  = Rectangle.Empty;

            textRect = new Rectangle(rect.X + 4, rect.Y, rect.Width - 4, rect.Height);
            if (rightToLeft == RightToLeft.No)
            {
                checkRect = new Rectangle(rect.X, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }
            else
            {
                checkRect = new Rectangle(rect.Right - 15, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }

            if (appearance == Appearance.Normal)
            {
                if (rightToLeft == RightToLeft.No)
                {
                    textRect.X     += 10;
                    textRect.Width -= 10;
                }
                else
                {
                    textRect.Width -= 16;
                }

                var oldSmoothingMode = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.AntiAlias;

                if (isEnabled && (isMouseOver || isFocused))
                {
                    g.DrawEllipse(StiPens.SelectedText,
                                  checkRect.X, checkRect.Y, checkRect.Width, checkRect.Height);
                }
                else
                {
                    if (!isEnabled)
                    {
                        using (var pen = new Pen(StiColorUtils.Dark(SystemColors.Control, 30)))
                        {
                            g.DrawEllipse(pen,
                                          checkRect.X, checkRect.Y, checkRect.Width, checkRect.Height);
                        }
                    }
                    else
                    {
                        g.DrawEllipse(SystemPens.ControlDark,
                                      checkRect.X, checkRect.Y, checkRect.Width, checkRect.Height);
                    }
                }

                if (isEnabled)
                {
                    using (var brush = new LinearGradientBrush(checkRect,
                                                               StiColors.ContentDark, SystemColors.ControlLightLight, 45))
                    {
                        g.FillEllipse(brush, checkRect.X + 1, checkRect.Y + 1, 10, 10);
                    }
                }
                else
                {
                    g.FillEllipse(SystemBrushes.Control, checkRect.X + 1, checkRect.Y + 1, 10, 10);
                }

                if (isChecked)
                {
                    if (isEnabled)
                    {
                        g.FillEllipse(Brushes.DarkGray, checkRect.X + 3, checkRect.Y + 3, 6, 6);
                        g.FillEllipse(Brushes.Black, checkRect.X + 4, checkRect.Y + 4, 4, 4);
                    }
                    else
                    {
                        g.FillEllipse(Brushes.DarkGray, checkRect.X + 3, checkRect.Y + 3, 6, 6);
                        g.FillEllipse(Brushes.DimGray, checkRect.X + 4, checkRect.Y + 4, 4, 4);
                    }
                }

                g.SmoothingMode = oldSmoothingMode;

                #region Paint focus
                if (isFocused)
                {
                    Rectangle focusRect = textRect;
                    SizeF     sizeText  = g.MeasureString(text, font);
                    focusRect.Width  = (int)sizeText.Width;
                    focusRect.Y      = (focusRect.Height - ((int)sizeText.Height + 2)) / 2;
                    focusRect.Height = (int)sizeText.Height + 2;

                    if (rightToLeft == RightToLeft.Yes)
                    {
                        focusRect.X = textRect.Right - focusRect.Width;
                    }

                    ControlPaint.DrawFocusRectangle(g, focusRect);
                }
                #endregion
            }
            else
            {
                StiButton.DrawButton(g, rect, text, font, foreColor, backColor, null, -1, null, rightToLeft,
                                     false, isEnabled, isMouseOver, isChecked, false, isFocused,
                                     ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter);
            }

            #region Paint string
            if (appearance == Appearance.Normal)
            {
                using (var sf = new StringFormat())
                {
                    sf.FormatFlags   = StringFormatFlags.NoWrap;
                    sf.LineAlignment = StringAlignment.Center;
                    sf.Trimming      = StringTrimming.EllipsisCharacter;
                    sf.HotkeyPrefix  = HotkeyPrefix.Show;

                    if (rightToLeft == RightToLeft.Yes)
                    {
                        sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }

                    using (var foreBrush = new SolidBrush(foreColor))
                    {
                        if (isEnabled)
                        {
                            g.DrawString(text, font, foreBrush, textRect, sf);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(g, text, font, backColor, textRect, sf);
                        }
                    }
                }
            }
            #endregion
        }