G
Guest
I want to create a custom form border. By thought was to simply override the
DisplayRectangle property in order to control the border width and then draw
the border during the OnPaint event. The problem with this technique is that
controls that are outside of the ClientRectangle of the form will overlap the
form's border. You can see this in the following example:
Public Class Form1
Inherits Windows.Forms.Form
Private Const BorderWidth As Integer = 16 'This is just for demo purposes.
Public Sub New()
MyBase.New()
End Sub
Public Overrides ReadOnly Property DisplayRectangle() As
System.Drawing.Rectangle
Get
Return New Drawing.Rectangle(BorderWidth, BorderWidth, (Me.Width - (2
* BorderWidth)), (Me.Height - (2 * BorderWidth))) 'This is just for demo
purposes.
End Get
End Property
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.FillRectangle(Brushes.Blue, Me.ClientRectangle)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.Text = ""
Me.ControlBox = False
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Dim p1 As New Windows.Forms.Panel 'This panel works as desired.
p1.BackColor = Color.Red
p1.Dock = DockStyle.Fill
Me.Controls.Add(p1)
Dim p2 As New Windows.Forms.Panel 'This panel should be covered by the
border.
p2.BackColor = Color.Yellow
p2.Bounds = New Drawing.Rectangle(0, 0, (Me.ClientSize.Width \ 2),
(Me.ClientSize.Height \ 2))
Me.Controls.Add(p2)
End Sub
End Class
Is there any way to cause the border to be on top of controls that are
within the border region. My guess is that I need to specify the border
region as being a nonclient area, but I'm not sure how this is done.
Thanks for any help!
Lance
DisplayRectangle property in order to control the border width and then draw
the border during the OnPaint event. The problem with this technique is that
controls that are outside of the ClientRectangle of the form will overlap the
form's border. You can see this in the following example:
Public Class Form1
Inherits Windows.Forms.Form
Private Const BorderWidth As Integer = 16 'This is just for demo purposes.
Public Sub New()
MyBase.New()
End Sub
Public Overrides ReadOnly Property DisplayRectangle() As
System.Drawing.Rectangle
Get
Return New Drawing.Rectangle(BorderWidth, BorderWidth, (Me.Width - (2
* BorderWidth)), (Me.Height - (2 * BorderWidth))) 'This is just for demo
purposes.
End Get
End Property
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.FillRectangle(Brushes.Blue, Me.ClientRectangle)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.Text = ""
Me.ControlBox = False
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Dim p1 As New Windows.Forms.Panel 'This panel works as desired.
p1.BackColor = Color.Red
p1.Dock = DockStyle.Fill
Me.Controls.Add(p1)
Dim p2 As New Windows.Forms.Panel 'This panel should be covered by the
border.
p2.BackColor = Color.Yellow
p2.Bounds = New Drawing.Rectangle(0, 0, (Me.ClientSize.Width \ 2),
(Me.ClientSize.Height \ 2))
Me.Controls.Add(p2)
End Sub
End Class
Is there any way to cause the border to be on top of controls that are
within the border region. My guess is that I need to specify the border
region as being a nonclient area, but I'm not sure how this is done.
Thanks for any help!
Lance