none
Changing border color of GroupBox RRS feed

Answers

  • Hi,Kapalic

    I'm not familiar with VB, but I'm able to translate it through a tool,here is the code translated:

    Public Class myGroupBox
        
    Inherits 
    GroupBox
        
        
    Private borderColor As 
    Color
        
        
    Public Sub New
    ()
            
    MyBase.
    New
            Me
    .borderColor 
    Color.Black
        
    End Sub
        
        Public Property 
    BorderColor As 
    Color
            
    Get
                Return Me
    .borderColor
            
    End Get
            Set
                Me
    .borderColor 
    value
            
    End Set
        End Property
        
        Protected Overrides Sub 
    OnPaint(ByVal As 
    PaintEventArgs)
            
    Dim tSize As Size TextRenderer.MeasureText(Me.Text, Me
    .Font)
            
    Dim borderRect As Rectangle 
    e.ClipRectangle
            borderRect.Y 
    (borderRect.Y  _
                        + (tSize.Height / 
    2
    ))
            borderRect.Height 
    (borderRect.Height  _
                        - (tSize.Height / 
    2
    ))
            ControlPaint.DrawBorder(e.Graphics, borderRect, 
    Me
    .borderColor, ButtonBorderStyle.Solid)
            
    Dim textRect As Rectangle 
    e.ClipRectangle
            textRect.X 
    (textRect.X + 6
    )
            textRect.Width 
    tSize.Width
            textRect.Height 
    tSize.Height
            e.Graphics.FillRectangle(
    New SolidBrush(Me
    .BackColor), textRect)
            e.Graphics.DrawString(
    Me.Text, Me.Font, New SolidBrush(Me
    .ForeColor), textRect)
        
    End Sub
    End Class

    Sunday, February 25, 2007 1:51 AM
  • Open the Solution Explorer, right click on the root,choose "Add",then "Class", name the class as "myGroupBox",and put my code in this class, rebuild your project, the you will see a "myGroupBox" control on your toolbox, it has a "BorderColor" property on the Misc group in the property view.
    Sunday, February 25, 2007 5:05 AM

All replies

  • Hi Kapalic

    What's on a group box is a chiseled line, probably a ControlPaint.DrawBorder3d.  There's no color option with that because it's very thin.  To make a group box with custom appearance, I'd create a derived control that inherits from Panel, add a Paint event handler, and draw the border myself.  This will, for all practical purposes, act just like a group box (A group box, after all, is just a panel with a border...)

    This is much easier than it sounds!  Let me know if you need an example.

     

    Thursday, February 22, 2007 2:01 PM
  • Dear Alan

    Thank you so much for your reply.

    Yes, surely I need an example how to do this, because I haven't ever done this before.

    Regards.

    Saturday, February 24, 2007 2:48 AM
  • Sub-class the GroupBox class, override the onPaint event:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

     

    namespace Sample2

    {

        public partial class GroupBoxTest : Form

        {

            public GroupBoxTest()

            {

                InitializeComponent();

            }

     

            private void GroupBoxTest_Load(object sender, EventArgs e)

            {

                myGroupBox myGroupBox = new myGroupBox();

                myGroupBox.Text = "GroupBox1";

                myGroupBox.BorderColor = Color.Red;

                this.Controls.Add(myGroupBox);

            }

        }

     

        public class myGroupBox : GroupBox

        {

            private Color borderColor;

     

            public Color BorderColor

            {

                get { return this.borderColor; }

                set { this.borderColor = value; }

            }

     

            public myGroupBox()

            {

                this.borderColor = Color.Black;

            }

     

            protected override void OnPaint(PaintEventArgs e)

            {

                Size tSize = TextRenderer.MeasureText(this.Text, this.Font);

     

                Rectangle borderRect = e.ClipRectangle;

                borderRect.Y += tSize.Height / 2;

                borderRect.Height -= tSize.Height / 2;

                ControlPaint.DrawBorder(e.Graphics, borderRect, this.borderColor, ButtonBorderStyle.Solid);

     

                Rectangle textRect = e.ClipRectangle;

                textRect.X += 6;

                textRect.Width  = tSize.Width;

                textRect.Height = tSize.Height;

                e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);

                e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);

            }

        }

    }

    Rebuid my sample, you will see a custom control named "myGroupBox" on your toolbox, you can drag it to your form just like the normal groupbox control. At the property view, a "BorderColor" is available in the Misc group for you to set the border color.

    Hope it helps. 
    Best Regards.
    Zhixin Ye

     

    Saturday, February 24, 2007 5:22 AM
  • Dear Zhi

    Understanding VC++ code is as foreign to me as Chinese language! Please provide me the VB version of the code.

    Xie xie nin!

    Saturday, February 24, 2007 12:36 PM
  • Hi,Kapalic

    I'm not familiar with VB, but I'm able to translate it through a tool,here is the code translated:

    Public Class myGroupBox
        
    Inherits 
    GroupBox
        
        
    Private borderColor As 
    Color
        
        
    Public Sub New
    ()
            
    MyBase.
    New
            Me
    .borderColor 
    Color.Black
        
    End Sub
        
        Public Property 
    BorderColor As 
    Color
            
    Get
                Return Me
    .borderColor
            
    End Get
            Set
                Me
    .borderColor 
    value
            
    End Set
        End Property
        
        Protected Overrides Sub 
    OnPaint(ByVal As 
    PaintEventArgs)
            
    Dim tSize As Size TextRenderer.MeasureText(Me.Text, Me
    .Font)
            
    Dim borderRect As Rectangle 
    e.ClipRectangle
            borderRect.Y 
    (borderRect.Y  _
                        + (tSize.Height / 
    2
    ))
            borderRect.Height 
    (borderRect.Height  _
                        - (tSize.Height / 
    2
    ))
            ControlPaint.DrawBorder(e.Graphics, borderRect, 
    Me
    .borderColor, ButtonBorderStyle.Solid)
            
    Dim textRect As Rectangle 
    e.ClipRectangle
            textRect.X 
    (textRect.X + 6
    )
            textRect.Width 
    tSize.Width
            textRect.Height 
    tSize.Height
            e.Graphics.FillRectangle(
    New SolidBrush(Me
    .BackColor), textRect)
            e.Graphics.DrawString(
    Me.Text, Me.Font, New SolidBrush(Me
    .ForeColor), textRect)
        
    End Sub
    End Class

    Sunday, February 25, 2007 1:51 AM
  • Hi Zhi,

    Thank you so much for your kind help. Will you please tell me how to use this class? Should I create a control project and build first with this class? Please give me an example. I haven't done this kind of thing before!

    By the way, how do u format the code block in the forum when you post?

    Regards!

     

     

    Sunday, February 25, 2007 4:59 AM
  • Open the Solution Explorer, right click on the root,choose "Add",then "Class", name the class as "myGroupBox",and put my code in this class, rebuild your project, the you will see a "myGroupBox" control on your toolbox, it has a "BorderColor" property on the Misc group in the property view.
    Sunday, February 25, 2007 5:05 AM
  • Dear Zhi,

    An error occurs saying naming scop conflict with the borderColor variable while attempting to build the project. Here is the modified version which runs all right. Thank you s....o much for teaching a nice technic. Can I modify other controls in this way? Suppose the scrollBar color of a multiline textbox?

    Private _borderColor As Color

    Public Sub New()

    MyBase.New()

    Me._borderColor = Color.Black

    End Sub

    Public Property BorderColor() As Color

    Get

    Return Me._borderColor

    End Get

    Set(ByVal Value As Color)

    Me._borderColor = Value

    End Set

    End Property

    Regards

    Kapalic

    Sunday, February 25, 2007 9:53 AM
  • Hi Zhi,

    Will you please explain how the code works?

    Regards!

    Sunday, February 25, 2007 12:04 PM
  • in vb code error occurs.............

     

    in folowing class ............

    Private Sub InitializeComponent()

     

    Me.MyGroupBox1 = New projectname.MyGroupBox ' type projectname.MyGroupBox is not define......... <-- error

     

    End Sub

     

     

    Friend WithEvents MyGroupBox1 As projectname.MyGroupBox ' type projectname.MyGroupBox is not define.........<-- error

     

     

    reply fast..........

    plz help me..........

     

    Tuesday, June 26, 2007 7:01 AM
  • Great Post!!  I was wondering if you could add code to draw rounded edges for the GroupBox.  Thanks in advance!
    Thursday, August 14, 2008 5:33 PM
  • Works great, but when I change the BackColor to 'Transparent' the line runs through the Title text MyGroupBox...

    I didn't test every color, but the ones I did preformed as they should.  I would guess it is just with transparency...

     

    Tuesday, August 26, 2008 9:14 AM
  • Could this be because there is another control that sits where the text 'MyGroupBox' sits?  Maybe this was created using a panel and a label and so when the panel goes transparent the label does too?

     

    I would like to be able to change the color of the text as well if that is possible....

    Tuesday, August 26, 2008 9:22 AM
  • Zhi-Xin Ye,

     

    Thank you. Just what I was looking for. Took less than a minute and I was ready to go. Anyway, thank you.

     

    Tuesday, November 18, 2008 2:24 PM
  • THis works great but what happened to the rounded corners in with visual styles enabled?

    Tuesday, November 25, 2008 12:20 AM
  • Hi Zhi-Xin Ye,
    Thanks for the sample code for changing border color of Group Box. I was searching for this sample and it worked well with mine (C#). However when I change the back color of this group box to transparent it paints rectangle around the group box text and also to any labels control that I may have in the control.

    I need the back color of the group box to be transparent because I have a gradient form and it looks cool if the back color of group box is transparent.

    In addition, how to do get the curve corners of the group box

    Thank you in advise

    Marsh
    Wednesday, October 14, 2009 9:27 PM
  • class myGroupBox : GroupBox
    {
     public myGroupBox()
            {
                base.BackColor = Color.Transperent;

             }
    [Browsable(false)]
            public override Color BackColor
            {
                get
                {
                    return base.BackColor;
                }
                set
                {
                    base.BackColor = value;
                }
            }

    private Color backColor = Color.Transparent;

     public Color ActualBackColor
            {
                get { return this.backColor; }

                set { this.backColor = value; }
            }

     protected override void OnPaint(PaintEventArgs e)
            {                                        
            
                Size tSize = TextRenderer.MeasureText(this.Text, this.Font);

                Rectangle borderRect = e.ClipRectangle;

                borderRect.Y += tSize.Height / 2;

                borderRect.Height -= tSize.Height / 2;

                GraphicsPath gPath = CreatePath(0, borderRect.Y,(float)(this.Width - 1), borderRect.Height - 1, 5, true, true, true, true);           

                e.Graphics.FillPath(new SolidBrush(ActualBackColor), gPath);

                e.Graphics.DrawPath(new Pen(this.borderColor), gPath);

                borderRect.X += 6;
                borderRect.Y -= 7;

                e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), borderRect);
            }
    }


    Friday, March 12, 2010 6:23 AM
  •   public GraphicsPath CreatePath(float x, float y, float width, float height,
                                          float radius, bool RoundTopLeft, bool RoundTopRight, bool RoundBottomRight, bool RoundBottomLeft)
            {
                float xw = x + width;
                float yh = y + height;
                float xwr = xw - radius;
                float yhr = yh - radius;
                float xr = x + radius;
                float yr = y + radius;
                float r2 = radius * 2;
                float xwr2 = xw - r2;
                float yhr2 = yh - r2;

                GraphicsPath p = new GraphicsPath();
                p.StartFigure();

                //Top Left Corner

                if (RoundTopLeft)
                {
                    p.AddArc(x, y, r2, r2, 180, 90);
                }
                else
                {
                    p.AddLine(x, yr, x, y);
                    p.AddLine(x, y, xr, y);

                }

                //Top Edge
                p.AddLine(xr, y, xwr, y);

                //Top Right Corner

                if (RoundTopRight)
                {
                    p.AddArc(xwr2, y, r2, r2, 270, 90);
                }
                else
                {
                    p.AddLine(xwr, y, xw, y);
                    p.AddLine(xw, y, xw, yr);
                }


                //Right Edge
                p.AddLine(xw, yr, xw, yhr);

                //Bottom Right Corner

                if (RoundBottomRight)
                {
                    p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
                }
                else
                {
                    p.AddLine(xw, yhr, xw, yh);
                    p.AddLine(xw, yh, xwr, yh);
                }


                //Bottom Edge
                p.AddLine(xwr, yh, xr, yh);

                //Bottom Left Corner           

                if (RoundBottomLeft)
                {
                    p.AddArc(x, yhr2, r2, r2, 90, 90);
                }
                else
                {
                    p.AddLine(xr, yh, x, yh);
                    p.AddLine(x, yh, x, yhr);
                }

                //Left Edge
                p.AddLine(x, yhr, x, yr);

                p.CloseFigure();
                return p;
            }
    Friday, March 12, 2010 6:24 AM
  • Hello I am a newbee in vb and try to figure out how your code works together with the one at the top of this post. There is a little bug I can't manage with... How to make the label not be striked when the background is transparent?
     thanks in advance

    Private Class myGroupBox
    	Inherits GroupBox
    	Public Sub New()
    
    		MyBase.BackColor = Color.Transperent
    	End Sub
    	<Browsable(False)> _
    	Public Overrides Property BackColor() As Color
    		Get
    			Return MyBase.BackColor
    		End Get
    		Set
    			MyBase.BackColor = value
    		End Set
    	End Property
    
    	Private m_backColor As Color = Color.Transparent
    
    	Public Property ActualBackColor() As Color
    		Get
    			Return Me.m_backColor
    		End Get
    
    		Set
    			Me.m_backColor = value
    		End Set
    	End Property
    
    	Protected Overrides Sub OnPaint(e As PaintEventArgs)
    
    		Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)
    
    		Dim borderRect As Rectangle = e.ClipRectangle
    
    		borderRect.Y += tSize.Height / 2
    
    		borderRect.Height -= tSize.Height / 2
    
    		Dim gPath As GraphicsPath = CreatePath(0, borderRect.Y, CSng(Me.Width - 1), borderRect.Height - 1, 5, True, _
    			True, True, True)
    
    		e.Graphics.FillPath(New SolidBrush(ActualBackColor), gPath)
    
    		e.Graphics.DrawPath(New Pen(Me.borderColor), gPath)
    
    		borderRect.X += 6
    		borderRect.Y -= 7
    
    		e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), borderRect)
    	End Sub
    End Class
    
    
    
    Public Function CreatePath(x As Single, y As Single, width As Single, height As Single, radius As Single, RoundTopLeft As Boolean, _
    	RoundTopRight As Boolean, RoundBottomRight As Boolean, RoundBottomLeft As Boolean) As GraphicsPath
    	Dim xw As Single = x + width
    	Dim yh As Single = y + height
    	Dim xwr As Single = xw - radius
    	Dim yhr As Single = yh - radius
    	Dim xr As Single = x + radius
    	Dim yr As Single = y + radius
    	Dim r2 As Single = radius * 2
    	Dim xwr2 As Single = xw - r2
    	Dim yhr2 As Single = yh - r2
    
    	Dim p As New GraphicsPath()
    	p.StartFigure()
    
    	'Top Left Corner
    
    	If RoundTopLeft Then
    		p.AddArc(x, y, r2, r2, 180, 90)
    	Else
    		p.AddLine(x, yr, x, y)
    
    		p.AddLine(x, y, xr, y)
    	End If
    
    	'Top Edge
    	p.AddLine(xr, y, xwr, y)
    
    	'Top Right Corner
    
    	If RoundTopRight Then
    		p.AddArc(xwr2, y, r2, r2, 270, 90)
    	Else
    		p.AddLine(xwr, y, xw, y)
    		p.AddLine(xw, y, xw, yr)
    	End If
    
    
    	'Right Edge
    	p.AddLine(xw, yr, xw, yhr)
    
    	'Bottom Right Corner
    
    	If RoundBottomRight Then
    		p.AddArc(xwr2, yhr2, r2, r2, 0, 90)
    	Else
    		p.AddLine(xw, yhr, xw, yh)
    		p.AddLine(xw, yh, xwr, yh)
    	End If
    
    
    	'Bottom Edge
    	p.AddLine(xwr, yh, xr, yh)
    
    	'Bottom Left Corner      
    
    	If RoundBottomLeft Then
    		p.AddArc(x, yhr2, r2, r2, 90, 90)
    	Else
    		p.AddLine(xr, yh, x, yh)
    		p.AddLine(x, yh, x, yhr)
    	End If
    
    	'Left Edge
    	p.AddLine(x, yhr, x, yr)
    
    	p.CloseFigure()
    	Return p
    End Function

    pascal


    http://www.scalpa.info
    Sunday, November 28, 2010 10:28 AM
  • Improved version

    Thanks for sharing your sweet code, especially to deep.ashar.

    The code contained small problems. Now I applied some changes:

    • Display problems solved (pixel errors and flickering when moving/resizing the window)
    • Solved wrong border rendering (happened whenGroupBox was only partially visible)
    • Bugfix: Last letter of GroupBox Text wasn't shown
    • Added second border for decoration purpose (like original GroupBox)
    • Used SystemColors as default border colour (ControlDarkDark, ControlLightLight)
    • Modification will be disabled when VisualStyles are disabled
    • Simplified parameter collection of CreatePath()
    • My code contains the needed namespaces for easy usage (-;
    • Maybe more

    If you like it, feel free to send me a tiny e-mail: . . . . . beautyod [at] gmx.de

    Usage

    • Open the Solution Explorer, right click on the root,
    • Choose "Add", then "Code file", enter the name "GroupBoxMOD"
    • Copy & paste my code
    • Change the namespace (the same as used for your form)
    • Rebuild your project
    • Now you will see a "GroupBoxMOD" control on your toolbox
    • The "BorderXxx" properties you can change in the property view

    Notes

    • Don't forget to apply the method RedrawGroupBoxDisplay() to some window events. Details I wrote in the XML comment.
    • There are display problems when you use the GroupBoxMOD inside a TabControl. If I remember right, the solution is to set a background colour to the GroupBoxes. (I think by default the background is transparent.)

    Code

    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Text;
    using System.Windows.Forms;
    
    namespace BeautyOfDarkness
    {
    
        /// <summary>
        /// Modified GroupBox with editable border colour
        /// </summary>
        class GroupBoxMOD : GroupBox
        {
            private Color borderColor;
            private Color borderColorLight;
            private Int32 borderRadius;
    
            /// <summary>Colour of the border</summary>
            public Color BorderColor
            {
                get { return this.borderColor; }
                set { this.borderColor = value; }
            }
    
            /// <summary>Colour of second border for decoration purposes.</summary>
            public Color BorderColorLight
            {
                get { return borderColorLight; }
                set { borderColorLight = value; }
            }
    
            public Int32 BorderRadius
            {
                get { return borderRadius; }
                set { borderRadius = value; }
            }
    
    
            
            public GroupBoxMOD()
            {
                // default colours
                this.borderColor = SystemColors.ControlDarkDark;
                this.borderColorLight = SystemColors.ControlLightLight;
                this.borderRadius = 5;
                
                this.DoubleBuffered = true; // prevent flickering
                this.ResizeRedraw = true;   // prevent pixel errors when window moves/resizes
            }
    
    
    
            protected override void OnPaint(PaintEventArgs e)
            {
                // don't modify if visual styles are disabled   (in this case the default border has a good visibility)
                if (Application.RenderWithVisualStyles == false)
                {
                    base.OnPaint(e);
                    return;
                }
    
                Size textSize = TextRenderer.MeasureText(this.Text, this.Font);
    
                // dark border (main)
                Rectangle borderRect = new Rectangle(
                    0,
                    textSize.Height / 2,
                    this.ClientRectangle.Width - 1,
                    this.ClientRectangle.Height - (textSize.Height / 2) - 2
                    );
    
                // light border (decoration)
                Rectangle borderRect2 = new Rectangle(
                    1,
                    borderRect.Y + 1,
                    borderRect.Width - 2,
                    borderRect.Height
                    );
    
                // create path
                GraphicsPath gPathDark = CreatePath(borderRect, borderRadius);
                GraphicsPath gPathLight = CreatePath(borderRect2, borderRadius);
    
                // draw border
                e.Graphics.FillPath(new SolidBrush(this.BackColor), gPathDark);  // background
                e.Graphics.DrawPath(new Pen(this.borderColorLight), gPathLight); // light line
                e.Graphics.DrawPath(new Pen(this.borderColor), gPathDark);       // dark line
    
    
                // draw text
                RectangleF textRect = e.ClipRectangle;
                textRect.X += 6;
                textRect.Width = textSize.Width;
                textRect.Width += 5;  // be shure to draw the last letter
                textRect.Height = textSize.Height;
                e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);
                e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);
    
                // NOTE:
                // To avoid flickering and pixel errors
                // enable the flags "this.DoubleBuffered" and "this.ResizeRedraw" in the constructor of this class.
    
            } //  OnPaint()
    
    
    
    
    
            /// <summary>
            /// Create "box" with round corners
            /// </summary>
            private GraphicsPath CreatePath(Rectangle borderRectangle, Int32 radius)
            {
                return CreatePath(borderRectangle.X, borderRectangle.Y, borderRectangle.Width, borderRectangle.Height, radius);
            }
    
    
    
            /// <summary>
            /// Create "box" with round corners
            /// </summary>
            private GraphicsPath CreatePath(Int32 x, Int32 y, Int32 width, Int32 height, Int32 radius)
            {
                // originally published by:  deep.ashar
                // source:  http://social.msdn.microsoft.com/forums/en-US/winforms/thread/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788
                // modified by Beauty
    
                Boolean RoundTopLeft = true;
                Boolean RoundTopRight = true;
                Boolean RoundBottomRight = true;
                Boolean RoundBottomLeft = true;
    
                Int32 xw = x + width;
                Int32 yh = y + height;
                Int32 xwr = xw - radius;
                Int32 yhr = yh - radius;
                Int32 xr = x + radius;
                Int32 yr = y + radius;
                Int32 r2 = radius * 2;
                Int32 xwr2 = xw - r2;
                Int32 yhr2 = yh - r2;
    
                GraphicsPath p = new GraphicsPath();
                p.StartFigure();
    
                //Top Left Corner
    
                if (RoundTopLeft)
                {
                    p.AddArc(x, y, r2, r2, 180, 90);
                }
                else
                {
                    p.AddLine(x, yr, x, y);
                    p.AddLine(x, y, xr, y);
    
                }
    
                //Top Edge
                p.AddLine(xr, y, xwr, y);
    
                //Top Right Corner
    
                if (RoundTopRight)
                {
                    p.AddArc(xwr2, y, r2, r2, 270, 90);
                }
                else
                {
                    p.AddLine(xwr, y, xw, y);
                    p.AddLine(xw, y, xw, yr);
                }
    
    
                //Right Edge
                p.AddLine(xw, yr, xw, yhr);
    
                //Bottom Right Corner
    
                if (RoundBottomRight)
                {
                    p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
                }
                else
                {
                    p.AddLine(xw, yhr, xw, yh);
                    p.AddLine(xw, yh, xwr, yh);
                }
    
    
                //Bottom Edge
                p.AddLine(xwr, yh, xr, yh);
    
                //Bottom Left Corner           
    
                if (RoundBottomLeft)
                {
                    p.AddArc(x, yhr2, r2, r2, 90, 90);
                }
                else
                {
                    p.AddLine(xr, yh, x, yh);
                    p.AddLine(x, yh, x, yhr);
                }
    
                //Left Edge
                p.AddLine(x, yhr, x, yr);
    
                p.CloseFigure();
                return p;
    
            } //  CreatePath()
    
    
    
    
    
            /// <summary>
            /// Manual refresh of modified GroupBox controls (to avoid pixel faults). <br/>
            /// This should be called when main window was activated, moved or resized. <br/>
            /// For this create callback method by the events Form.Activated, Form.Resize and Form.Move 
            /// which calls this method.
            /// If you have more than 1 panel (or other controls), which contains the GroupBoxMOD,
            /// then call this method for each panel. 
            /// </summary>
            /// <param name="controlWithGroupboxes">Control, which contains GroupBoxMOD controls</param>
            public static void RedrawGroupBoxDisplay(Control controlWithGroupboxes)
            {
                foreach (Control control in controlWithGroupboxes.Controls)
                    if (control.GetType() == typeof(GroupBoxMOD))
                        ((GroupBoxMOD)control).Invalidate();
            }
    
    
        } // GroupBoxMOD
    
    } // namespace
    










    • Edited by Beauty of Darkness Monday, April 9, 2012 8:34 PM fixed a "website code bug", which removed linebreaks when copy&paste with IE (Firefox worked fine)
    • Proposed as answer by Beauty of Darkness Monday, April 9, 2012 11:55 PM
    Thursday, January 5, 2012 12:19 PM
  • Very helpful post - thanks guys.

    We found an alternative approach to calling the RedrawGroupBoxDisplay method that worked better for us:

            /// <summary>
            /// Parent Changed Event
            /// </summary>
            /// <param name="e">event arguments</param>
            protected override void OnParentChanged( EventArgs e )
            {
                base.OnParentChanged( e );
                Control parent = this.Parent;
                while ( null != parent )
                {               
                    if ( null != parent )
                    {                   
                        parent.Paint += new PaintEventHandler( OnParentPaint );                    
                    }
                    parent = parent.Parent;
                }           
            }
           
            /// <summary>
            /// Parent Paint Event
            /// </summary>
            /// <param name="sender">sender object</param>
            /// <param name="e">event arguments</param>
            private void OnParentPaint( object sender, PaintEventArgs e )
            {
                this.Refresh();
            }      

    Monday, June 4, 2012 11:28 PM
  • Reply to the post of JamesFromCalgary:

    Thanks you James for sharing your improvement.

    How it's possible to use your code?
    Just add the two methods to my GroupBoxMOD class? (This would be great!)
    Or is it needed to apply an additional callback method?

    ____________________
    By the way:
    It's a shame that I can't submit this post by Firefox. (The form just ignores my button clicks.)
    Microsoft forces me to use the Internet Explorer instead.

    Additionally:
    In the past I got an e-mail that my posted code caused problems (removed line breaks for copy and paste with IE).
    After some tests I found out that this bad behaviour (website bug?) happens, when I posted my code by Firefox and an other user copy this with Internet Explorer.
    The solution was to remove my post content and paste it again, using the Internet Explorer. Only then the copy&paste problems were solved.
    Now postings by Firefox are blocked at all.
    I don't like the Microsoft policy to force their visitors (forum content creators) to use the Mircosoft browser.



    Sunday, July 15, 2012 2:02 PM
  • Hi,

    I tried Zhi-Xin Ye's class but I face some troubleshooting when my new groupbox is set with a tooltip.

    when I run my app, the tooltip appears when my mouse enters teh groupbox which is normal.

    When the tooltip disappears, it leaves some trace behind :

    I can't explain why ?

    Thursday, September 19, 2013 2:12 PM
  • Where solution or Project under create class file ?
    Friday, September 18, 2015 9:07 AM
  • Hi Beauty

    I know this is an old post, but I am running into an issue where the bottom border of the GroupBoxMOD border is cut off.  Being a novice programmer I have been unable to figure out how to increase the size of the selection box so the bottom border will show through.

    The link below shows What I am talking about.

    https://www.screencast.com/t/Gxl5hnCjK3rM

    Any Ideas??

    Saturday, June 23, 2018 8:17 PM
  • 4004

    <pp><style><what is the path of the class-file?



    what is the path of the class-file?



    • Edited by j0hn1337 Saturday, June 23, 2018 9:13 PM 1337'"<>
    Saturday, June 23, 2018 9:04 PM
  • For anyone that may find this code and use in the future....

    After converting your code to VB.net I found that the bottom edge of groupBoxMOD control was cut off.

    This has a simple fix...In the function CreatePath modify the initial yh value as follows:

    Dim yh As Int32 = (y + height - 4)

    Now the groupboxmod control displays correctly (completely.)

    Huge THANK YOU to Beauty of Darkness for the above code.

    Sunday, July 1, 2018 12:02 AM
  • Hi,

    I tried Zhi-Xin Ye's class but I face some troubleshooting when my new groupbox is set with a tooltip.

    when I run my app, the tooltip appears when my mouse enters teh groupbox which is normal.

    When the tooltip disappears, it leaves some trace behind :

    I can't explain why ?

    Simple fix. Change e.ClipRectangle to this.ClientRectangle

    e.ClipRectangle is the area of the control that has to be repainted after the tooltip is moved and the code as published redraws the border and text to that small area.

    The original code is wrong to use e.ClipRectangle

    Sunday, July 22, 2018 8:14 AM
  • myGroupBox.Paint += (sender, e) =>
    {
        Graphics gfx = e.Graphics;
        var pp = sender as GroupBox;
        gfx.Clear(pp.BackColor);
        gfx.DrawString(pp.Text, pp.Font, new SolidBrush(pp.ForeColor), new PointF(7,0));
    };


    www.furkanvakfi.com

    Friday, May 17, 2019 9:37 AM