Custom panel padding

ManicCW

Well-known member
Joined
Jul 21, 2005
Messages
428
Location
Mostar
Programming Experience
Beginner
Hi I've writen simple custom panel control that is needed many times in my project. But, I have one problem. How to set top padding of the panel control so it is the size of the header? I can set it when panel is created but how can i change it when i want to use panel padding to?

Here is the code

VB.NET:
Imports System.Drawing.Drawing2D

Public Class CROPanel : Inherits System.Windows.Forms.Panel

    'nova svojstva
    Private m_Naslov As String = "Naslov panela"

    <System.ComponentModel.Category("Misc")> _
    <System.ComponentModel.Description("Upišite naslov panela u polje.")> _
    Public Property Naslov() As String
        Get
            Return m_Naslov
        End Get
        Set(ByVal value As String)
            m_Naslov = value
            If Me.DesignMode = True Then
                Me.Invalidate()
            End If
        End Set
    End Property

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

        Dim g As Graphics = Me.CreateGraphics

        'definiranje
        Const PaddingZaglavlja As Integer = 5
        Const DebljinaOkvira As Integer = 1
        Dim FontNaslova As New Font("Tahoma", 10, FontStyle.Bold)
        Dim ZaglavljePrvaBoja As Color = SystemColors.Highlight
        Dim ZaglavljeDrugaBoja As Color = SystemColors.Desktop
        Dim BojaOkvira As Color = SystemColors.Desktop
        Dim VisinaZaglavlja As Integer = CInt(FontNaslova.GetHeight + PaddingZaglavlja * 2)
        'racunanje
        Dim FormatZaglavlje As New StringFormat
        FormatZaglavlje.LineAlignment = StringAlignment.Center
        Dim RectZaglavlje As New Rectangle(0, 0, Me.Width, VisinaZaglavlja)
        Dim RectZaglavljeNaslov As New RectangleF(PaddingZaglavlja, 0, Me.Width, VisinaZaglavlja)
        Dim RectPanel As New Rectangle(0, 0, Me.Width - DebljinaOkvira, Me.Height - DebljinaOkvira)
        Dim LinearZaglavlje As New LinearGradientBrush(RectZaglavlje, ZaglavljePrvaBoja, ZaglavljeDrugaBoja, LinearGradientMode.Vertical)

        'crtanje
        g.FillRectangle(LinearZaglavlje, RectZaglavlje)
        g.DrawRectangle(New Pen(BojaOkvira, DebljinaOkvira), RectPanel)
        g.DrawString(Naslov, FontNaslova, SystemBrushes.ActiveCaptionText, PaddingZaglavlja, PaddingZaglavlja)

        'uklanjanje graphics objekta iz memorije
        g.Dispose()
    End Sub

    Public Sub New()
        InitializeComponent()
        Me.SuspendLayout()
        Me.BackColor = SystemColors.ActiveCaptionText
        Me.ResumeLayout(False)
    End Sub

End Class
 
Back
Top