VB.net " sfButton1.Paint += sfButton1_Paint "
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
Thanks for contacting syncfusion support.
We have prepared the sample to added SfButton programmatically and draw the rounded rectangle border in Paint event. But we were unable to reproduce the reported issue.
Here is the sample that works as expected.
https://www.syncfusion.com/downloads/support/forum/156091/ze/Button1316331440.zip
Regards,
Duraimurugan V.
Thank you for your update.
As already depicted in our sample, you need to use AddHandler to invoke the events in VB.NET. We are glad that you have addressed it at your end.
Please let us know if you need any other further assistance on this.
Regards,
Vijayalakshmi VR