Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Groupbox Border 2

Status
Not open for further replies.

Manch

Programmer
Jun 12, 2001
43
0
0
US
Can you make the groupbox border appear as etched. I swear I have seen this in many VB .Net screenshots. I have tried changing the flatstyle property but with no luck. If I change the flatstyle to standard I get a grey border, but not etched, and any other setting for flatstyle and I get a blue border. I am using VS .Net 2003.

Any guidance is greatly appreciated.

Manch
 
I always thought it was etched. Maybe its raised. If you have a link to a screenshot, post it. I never recall seeing anything differerent on them.

But they could be custom, as a group-box like contronl would be one of the easier ones to create.
 
Thanks for your response! It was because I had changed the backcolor of my form to a light color. It seems Visual Studio picks a color that is a good contrast to the forms background color when it can not properly display the etched effect. I should have figured that out sooner, one of those brain cramps I guesse.

Manch
 
The thing that has always bugged me about the GroupBox/Frame is the fact that when the background color is changed is the fact that there is colored space outside of the frame, at the top, by the text. IMO, it should have been made transparent outside of the border.
 
I agree. They could have done a lot more with the groupbox.
 
I use the following GroupBox implementation to provide rounded corners and a correctly coloured outside edge. It might give you what you want...
Code:
Imports System.Drawing.Drawing2D

Public Class GroupBoxEx
    Inherits System.Windows.Forms.GroupBox

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region

#Region " Properties "

    Private cBorder As Color = Color.Black

    Public Property BorderColor() As Color
        Get

            Return cBorder

        End Get

        Set(ByVal Value As Color)

            cBorder = Value

            Invalidate()

        End Set

    End Property

#End Region

#Region " Paint "

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        'Draw the border

        Dim p As New Pen(cBorder, 1)

        Dim gp As New GraphicsPath

        gp.AddArc(New Rectangle(0, 9, 16, 16), 180, 90)

        gp.AddArc(New Rectangle(Width - 17, 9, 16, 16), 270, 90)

        gp.AddArc(New Rectangle(Width - 17, Height - 18, 16, 16), 0, 90)

        gp.AddArc(New Rectangle(0, Height - 18, 16, 16), 90, 90)

        gp.AddLine(0, 17, 0, Height - 17)

        e.Graphics.FillPath(New SolidBrush(BackColor), gp)

        e.Graphics.DrawPath(p, gp)

        'Draw the caption

        Dim sf As SizeF = e.Graphics.MeasureString(Text, Font)

        e.Graphics.FillRectangle(New SolidBrush(Color.Transparent), 16, 2, sf.Width, sf.Height + 4)

        e.Graphics.DrawLine(New Pen(BackColor), 16, 9, 16 + sf.Width, 9)

        e.Graphics.DrawString(Text, Font, New SolidBrush(ForeColor), 18, 3)

        gp.Dispose()

        p.Dispose()

    End Sub

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)

        pevent.Graphics.FillRectangle(New SolidBrush(Parent.BackColor), pevent.ClipRectangle)

    End Sub

#End Region

End Class
 
Thanks SHelton,

I will give it a try!

Manch
 
thanks shelton

a star for a star

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top