|
-
May 5th, 2018, 08:06 AM
#1
Thread Starter
Lively Member
[RESOLVED] Help With some errors in a class convertion from C# To VB.NET
Hello guys!!! 
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
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.
Line 16: Error:BC30491 Expression does not produce a value.
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.
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.
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
Line 17: Error:BC30182 Type expected.
Line 17: Error:BC37259 Tuple must contain at least two elements.
Line 17: Error:BC30311 Value of type '(?, ?)' cannot be converted to 'Color()'.
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!!!
Last edited by Simonetos The Greek; May 5th, 2018 at 09:21 AM.
Reason: Title correction
-
May 5th, 2018, 08:17 AM
#2
Thread Starter
Lively Member
Re: Help
Sorry for the "Help" title... I forgot to change it when I finished my post!!!
-
May 5th, 2018, 08:21 AM
#3
Re: Help
Firstly, do you need to convert it at all? Can you not just compile the C# code into a DLL and reference that to use the class?
If you are determined to convert, are you using Instant VB from Tangible Software Solutions? If not, I suggest that you download and install it. The free version may or may not be able to convert your class in one go but, if not, you could do each method separately. That's easily the best C# to VB converter you'll find.
-
May 5th, 2018, 08:53 AM
#4
Thread Starter
Lively Member
Re: Help
 Originally Posted by jmcilhinney
If you are determined to convert, are you using Instant VB from Tangible Software Solutions? If not, I suggest that you download and install it. The free version may or may not be able to convert your class in one go but, if not, you could do each method separately. That's easily the best C# to VB converter you'll find.
Thank you for the converter, worked 100%!!! Later I'll upload the converted class. Maybe someone need it!!!
 Originally Posted by jmcilhinney
Firstly, do you need to convert it at all? Can you not just compile the C# code into a DLL and reference that to use the class?
It sounds very interesting... I'll search on the web for this. I imagined it could be done, but I do not know how.
-
May 5th, 2018, 09:08 AM
#5
Thread Starter
Lively Member
Re: Help
Here is a correct converted version of Dropshadow class, from C# to VB.NET, if someone need it. And here is the original one, in C#.
Last edited by Simonetos The Greek; May 9th, 2018 at 05:26 AM.
Reason: Link correction.
-
May 9th, 2018, 05:27 AM
#6
Thread Starter
Lively Member
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!!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|