Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="fgColor"></param>
        /// <param name="style"></param>
        /// <param name="textBoxBorder"></param>
        /// <param name="borderType"></param>
        public static void PaintBorder(Graphics g, Rectangle rect, Color fgColor, ControlStyle style, bool textBoxBorder, BorderType borderType = BorderType.Thin)
        {
            Pen  pen = null;
            bool shouldPaintBorder = !(style == ControlStyle.TwoD && borderType == BorderType.NoBorder);

            if (shouldPaintBorder)
            {
                if (style == ControlStyle.TwoD)
                {
                    pen = PensCache.GetInstance().Get(fgColor);
                }

                if (style == ControlStyle.TwoD && borderType == BorderType.Thick)
                {
                    // back up the original properties of pen
                    PenAlignment originalAlligment = pen.Alignment;
                    float        originalwidth     = pen.Width;

                    // set properties of pen
                    pen.Width     = 2;
                    pen.Alignment = PenAlignment.Inset;

                    PaintBorder(g, pen, rect, style, textBoxBorder);

                    // restore the original properties of pen
                    pen.Alignment = originalAlligment;
                    pen.Width     = originalwidth;
                }
                else
                {
                    PaintBorder(g, pen, rect, style, textBoxBorder);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// paint the group box
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (ControlStyle == ControlStyle.TwoD)
            {
                Rectangle bounds    = new Rectangle(0, 0, Width, Height);
                Rectangle rectangle = bounds;
                rectangle.Width -= 14;
                TextFormatFlags flags = TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak;

                if (this.RightToLeft == RightToLeft.Yes)
                {
                    flags |= TextFormatFlags.RightToLeft | TextFormatFlags.Right;
                }

                Size size = TextRenderer.MeasureText(e.Graphics, Text, Font, new Size(rectangle.Width, rectangle.Height), flags);
                rectangle.Width  = size.Width;
                rectangle.Height = size.Height;

                if ((flags & TextFormatFlags.Right) == TextFormatFlags.Right)
                {
                    rectangle.X = ((bounds.Right - rectangle.Width) - 7) + 1;
                }
                else
                {
                    rectangle.X += 6;
                }

                TextRenderer.DrawText(e.Graphics, Text, Font, rectangle, ForeColor, flags);

                Color borderColor = BorderColor;
                if (borderColor == Color.Empty)
                {
                    borderColor = Color.Black;
                }

                Pen pen = PensCache.GetInstance().Get(borderColor);
                rectangle.Inflate(-1, 0);

                GroupRenderer.DrawBorder(e.Graphics, ClientRectangle, pen, ControlStyle.TwoD, rectangle, Font, ShouldDisplayTopBorderMargin);

                //Fixed defect 142805 & 142774: The logical controls present inside the group control were not painted.
                //Reason : The reason was the when group controls style is 2D, then we don't call base.paint() which internally calls logical control's paint event from Control.OnPaint() method.
                //Solution : Raise Control's OnPaint event so that the logical control's present inside the Group control will be painted.
                RaisePaintEvent(this, e);
            }
            else
            {
                base.OnPaint(e);
            }
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static PensCache GetInstance()
 {
     if (_instance == null)
     {
         // synchronize on the class object
         lock (typeof(PensCache))
         {
             if (_instance == null)
             {
                 _instance = new PensCache();
             }
         }
     }
     return(_instance);
 }
Beispiel #4
0
        private static void DrawTabBorder(MgTabControl tabControl, Graphics graphics, GraphicsPath path, int index)
        {
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            Color borderColor = SystemColors.ControlDark;

            // For hottracked item , border color must be the FG Color
            if (index == tabControl.ActiveIndex && index != tabControl.SelectedIndex && tabControl.HotTrackFgColor != Color.Empty)
            {
                borderColor = tabControl.HotTrackFgColor;
            }

            Pen borderPen = PensCache.GetInstance().Get(borderColor);

            graphics.DrawPath(borderPen, path);
        }
Beispiel #5
0
        /// <summary>
        /// render classic style expander (+ /- )
        /// </summary>
        /// <param name="g"></param>
        /// <param name="bounds"></param>
        /// <param name="isExpanded"></param>
        /// <param name="backColor"></param>
        /// <param name="foreColor"></param>
        public static void RenderExpanderWithClassicStyle(Graphics g, Rectangle bounds, bool isExpanded, Color backColor, Color foreColor)
        {
            Rectangle rect = new Rectangle((int)System.Math.Ceiling((bounds.Width - EXPANDER_SIZE) / 2), (int)System.Math.Ceiling((bounds.Height - EXPANDER_SIZE) / 2) + bounds.Y, (int)EXPANDER_SIZE, (int)EXPANDER_SIZE);

            if (!rect.IsEmpty)
            {
                Brush backgroundBrush = SolidBrushCache.GetInstance().Get(backColor);
                Pen   pen             = PensCache.GetInstance().Get(foreColor);

                g.FillRectangle(backgroundBrush, rect);                                // Fill rect
                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1); // draw border

                int num = 2;
                // draw horizontal line
                g.DrawLine(pen, (int)(rect.X + num), (int)(rect.Y + (rect.Height / 2)), (int)(((rect.X + rect.Width) - num) - 1), (int)(rect.Y + (rect.Height / 2)));

                if (!isExpanded)
                {
                    // draw vertical line
                    g.DrawLine(pen, (int)(rect.X + (rect.Width / 2)), (int)(rect.Y + num), (int)(rect.X + (rect.Width / 2)), (int)(((rect.Y + rect.Height) - num) - 1));
                }
            }
        }