BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
Hi All,
I'm trying to use the 'Rounded Rectangle Button' function of the SfButton in a WinForm app. The button are added programmatically however I can't get "sfButton1.Paint += sfButton1_Paint" to work as I get the following error,
"Public Event Paint As PaintEventHandler is an event, and cannot be called directly. Use a 'RaiseEvent' Statement to raise the event "
The code I'm using is;
Public Function BuildTagButton() As SfButton
Dim tag As New SfButton()
tag.AutoSize = True
tag.AutoSizeMode = AutoSizeMode.GrowAndShrink
tag.Paint += sfButton1_Paint()
Return tag
End Function
Public Sub sfButton1_Paint(ByVal sender As SfButton, ByVal e As PaintEventArgs)
Dim radius As Integer = 5
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim rect As Rectangle = New Rectangle(sender.ClientRectangle.X + 1, sender.ClientRectangle.Y + 1, sender.ClientRectangle.Width - 2, sender.ClientRectangle.Height - 2)
sender.Region = New Region(GetRoundedRect(rect, radius))
rect = New Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2)
e.Graphics.DrawPath(New Pen(Color.Red), GetRoundedRect(rect, radius))
End Sub
Private Function GetRoundedRect(ByVal bounds As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim diameter As Integer = radius * 2
Dim size As Size = New Size(diameter, diameter)
Dim arc As Rectangle = New Rectangle(bounds.Location, size)
Dim path As GraphicsPath = New GraphicsPath()
If radius = 0 Then
path.AddRectangle(bounds)
Return path
End If
path.AddArc(arc, 180, 90)
arc.X = bounds.Right - diameter
path.AddArc(arc, 270, 90)
arc.Y = bounds.Bottom - diameter
path.AddArc(arc, 0, 90)
arc.X = bounds.Left
path.AddArc(arc, 90, 90)
path.CloseFigure()
Return path
End Function
Thanks Andy