[RESOLVED] Help With some errors in a class convertion from C# To VB.NET
Hello guys!!! :wave:
I have found this class which gives shadow on a borderless form. It's written in C# and I had to convert it in VB.NET so to use it in my project. My problem is that the converter can't convert some parts correctly and I get some errors which I can't managed to fix.
First errors located here...
vb.net Code:
Public Sub New(f As Form)
Owner = f
ShadowRadius = 10
ShadowColor = Color.Black
'This bit of code makes the form click-through.
' So you can click forms that are below it in z-space
Dim wl As Integer = Win32.GetWindowLong(Handle, -20)
wl = wl Or &H80000 Or &H20
Win32.SetWindowLong(Handle, -20, wl)
FormBorderStyle = FormBorderStyle.None
' bind event
Owner.LocationChanged += UpdateLocation()
Owner.FormClosing += Function(sender, eventArgs) Close()
Owner.VisibleChanged += Function(sender, eventArgs)
If Owner IsNot Nothing Then
Visible = Owner.Visible
End If
'Owner.Activated += (sender, args) => Owner.BringToFront();
End Function
End Sub
Quote:
Line 16: Error:BC32022 'Public Event LocationChanged As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Quote:
Line 16: Error:BC30491 Expression does not produce a value.
Quote:
Line 17: Error:BC32022 'Public Event FormClosing As FormClosingEventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Quote:
Line 18: Error:BC32022 'Public Event VisibleChanged As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Quote:
Line 25: Warning:BC42105 Function '<anonymous method>' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
And the rest here...
vb.net Code:
Private Function DrawShadow() As Bitmap
' 窗体的大小
Dim fw As Integer = Owner.Width + ShadowRadius * 2
Dim fh As Integer = Owner.Height + ShadowRadius * 2
Dim gp As New GraphicsPath()
gp.AddRectangle(New RectangleF(0, 0, fw, fh))
'gp.AddEllipse(ClientRectangle);
'gp.AddRectangle(new RectangleF(ShadowRadius + WithBorderRadius
' , ShadowRadius + WithBorderRadius, ow, oh));
Dim pgb As New PathGradientBrush(gp)
pgb.CenterPoint = New PointF(fw / 2.0F, fh / 2.0F)
pgb.CenterColor = ShadowColor
pgb.SurroundColors = New() {Color.Transparent}
'pgb.ScaleTransform(1,1);
Dim bitmap As New Bitmap(fw, fh)
Dim g As Graphics = Graphics.FromImage(bitmap)
'var ctr = new Bitmap(Width, Height, CreateGraphics());
'g.DrawImage(ctr, new Point(0,0));
'var g = CreateGraphics();
g.FillPath(pgb, gp)
pgb.Dispose()
gp.Dispose()
'
Width = fw
Height = fh
Return bitmap
End Function
Quote:
Line 17: Error:BC30182 Type expected.
Quote:
Line 17: Error:BC37259 Tuple must contain at least two elements.
Quote:
Line 17: Error:BC30311 Value of type '(?, ?)' cannot be converted to 'Color()'.
Quote:
Line 17: Error:BC37280 'New' cannot be used with tuple type. Use a tuple literal expression instead.
If for some reason you need to check the full vb.net converted version of the class, I have uploaded it here. Thank you in advance!!! :)
Re: [RESOLVED] Help With some errors in a class convertion from C# To VB.NET
I also uploaded a demo project at GitHub... Here is the link!!!