Cags
Well-known member
No it will not need the onPaintBackground as the control only draws what is within the region and yes the region is made up of the 4 lines and 4 corners that make the shape of your control.
Dim filler As System.Drawing.Drawing2D.LinearGradientBrush
Dim rect As System.Drawing.Rectangle = Me.ClientRectangle
Dim topCorn As Rectangle
Dim graphPath As System.Drawing.Drawing2D.GraphicsPath
If memGraphics.CanDoubleBuffer() Then
If Not Me._HasDrawn Then
Me._HasDrawn = True
Draw the curved border
graphPath = Me.GetPath()
If Me.ClientRectangle.Width = 0 Then
rect.Width += 1
End If
If Me.ClientRectangle.Height = 0 Then
rect.Height += 1
End If
If Me._GradientMode = LinearGradientMode.None Then
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour1, System.Drawing.Drawing2D.LinearGradientMode.Vertical)
Else
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour1, CType(Me._GradientMode, System.Drawing.Drawing2D.LinearGradientMode))
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour2, CType(Me._GradientMode, System.Drawing.Drawing2D.LinearGradientMode))
End If
memGraphics.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
memGraphics.Graphics.FillPath(filler, graphPath)
Me.Region = New Region(graphPath)
Select Case Me._BorderStyle
Case System.Windows.Forms.BorderStyle.FixedSingle
Dim borderPen As New System.Drawing.Pen(Me._BorderColour, Me._BorderWidth)
memGraphics.Graphics.DrawPath(borderPen, graphPath)
borderPen.Dispose()
Case System.Windows.Forms.BorderStyle.Fixed3D
Me.DrawBorder3D(memGraphics.Graphics, Me.ClientRectangle)
Case System.Windows.Forms.BorderStyle.None
End Select
Render to the form
memGraphics.Render(e.Graphics)
filler.Dispose()
graphPath.Dispose()
End If
End If
Protected Function GetPath() As System.Drawing.Drawing2D.GraphicsPath
Dim graphPath As New System.Drawing.Drawing2D.GraphicsPath
If Me._BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Then
graphPath.AddRectangle(Me.ClientRectangle)
Else
Try
Dim curve As Integer = 0
Dim rect As System.Drawing.Rectangle = Me.ClientRectangle
Dim offset As Integer = 0
Select Case Me._BorderStyle
Case System.Windows.Forms.BorderStyle.FixedSingle
If Me._BorderWidth > 1 Then
offset = DoubleToInt(Me.BorderWidth / 2)
End If
curve = Me.adjustedCurve
Case System.Windows.Forms.BorderStyle.Fixed3D
Case System.Windows.Forms.BorderStyle.None
curve = Me.adjustedCurve
End Select
If curve = 0 Then
graphPath.AddRectangle(rect.Inflate(rect, -offset, -offset))
Else
Dim rectWidth As Integer = rect.Width - 1 - offset
Dim rectHeight As Integer = rect.Height - 1 - offset
Dim curveWidth As Integer = 1
If (Me._CurveMode And CornerCurveMode.TopRight) <> 0 Then
curveWidth = (curve * 2)
Else
curveWidth = 1
End If
graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90)
If (Me._CurveMode And CornerCurveMode.BottomRight) <> 0 Then
curveWidth = (curve * 2)
Else
curveWidth = 1
End If
graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90)
If (Me._CurveMode And CornerCurveMode.BottomLeft) <> 0 Then
curveWidth = (curve * 2)
Else
curveWidth = 1
End If
graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90)
If (Me._CurveMode And CornerCurveMode.TopLeft) <> 0 Then
curveWidth = (curve * 2)
Else
curveWidth = 1
End If
graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90)
graphPath.CloseFigure()
End If
Catch ex As System.Exception
graphPath.AddRectangle(Me.ClientRectangle)
End Try
End If
Return graphPath
End Function
Public Sub Render(ByVal g As Graphics)
If Not Me._memoryBitmap Is Nothing Then
g.DrawImage(Me._memoryBitmap, New Rectangle(0, 0, Me._width, Me._height), 0, 0, Me._width, Me._height, GraphicsUnit.Pixel)
End If
End Sub
Cags said:In your OnPaint method how are you drawing the Background of the control are you calling e.Graphics.Clear(this.BackColor); or are you drawing a region/ rectangle?
graphPath = Me.GetPath()
If Me.ClientRectangle.Width = 0 Then
rect.Width += 1
End If
If Me.ClientRectangle.Height = 0 Then
rect.Height += 1
End If
If Me._GradientMode = LinearGradientMode.None Then
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour1, System.Drawing.Drawing2D.LinearGradientMode.Vertical)
Else
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour2, CType(Me._GradientMode, System.Drawing.Drawing2D.LinearGradientMode))
End If
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.FillPath(filler, graphPath)
Me.Region = New Region(graphPath)
Public graphPath As New System.Drawing.Drawing2D.GraphicsPath
Private Sub CalcLayout()
graphPath = Me.GetPath()
If Me.ClientRectangle.Width = 0 Then
rect.Width += 1
End If
If Me.ClientRectangle.Height = 0 Then
rect.Height += 1
End If
Me.Region = graphPath
Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Me._GradientMode = LinearGradientMode.None Then
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour1, System.Drawing.Drawing2D.LinearGradientMode.Vertical)
Else
filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour2, CType(Me._GradientMode, System.Drawing.Drawing2D.LinearGradientMode))
End If
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.FillPath(filler, graphPath)
End Sub
Protected Overrides Sub OnResize(ByVal e As EventArgs)
MyBase.OnResize(e)
CalcLayout()
End Sub
e.Graphics.FillPath(filler, graphPath)
e.Graphics.FillRegion(filler, this.Region);
new Rectangle(0, 0, this.Width, this.Height)
private sub CalcLayout()
_BorderPath = GetPath(new Rectangle(1, 1, this.Bounds.Width, this.Bounds.Height))
Me.Region = new Region(GetPath(this.Bounds))
Invalidate();
end sub