Results 1 to 6 of 6

Thread: [RESOLVED] Help With some errors in a class convertion from C# To VB.NET

  1. #1

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Resolved [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:
    1. Public Sub New(f As Form)
    2.     Owner = f
    3.     ShadowRadius = 10
    4.     ShadowColor = Color.Black
    5.  
    6.     'This bit of code makes the form click-through.
    7.     '             So you can click forms that are below it in z-space
    8.  
    9.     Dim wl As Integer = Win32.GetWindowLong(Handle, -20)
    10.     wl = wl Or &H80000 Or &H20
    11.     Win32.SetWindowLong(Handle, -20, wl)
    12.  
    13.     FormBorderStyle = FormBorderStyle.None
    14.  
    15.     ' bind event
    16.     Owner.LocationChanged += UpdateLocation()
    17.     Owner.FormClosing += Function(sender, eventArgs) Close()
    18.     Owner.VisibleChanged += Function(sender, eventArgs)
    19.                                 If Owner IsNot Nothing Then
    20.                                     Visible = Owner.Visible
    21.                                 End If
    22.  
    23.  
    24.                                 'Owner.Activated += (sender, args) => Owner.BringToFront();
    25.                             End Function
    26. 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:
    1. Private Function DrawShadow() As Bitmap
    2.     ' 窗体的大小
    3.     Dim fw As Integer = Owner.Width + ShadowRadius * 2
    4.     Dim fh As Integer = Owner.Height + ShadowRadius * 2
    5.  
    6.     Dim gp As New GraphicsPath()
    7.  
    8.     gp.AddRectangle(New RectangleF(0, 0, fw, fh))
    9.     'gp.AddEllipse(ClientRectangle);
    10.     'gp.AddRectangle(new RectangleF(ShadowRadius + WithBorderRadius
    11.     '   , ShadowRadius + WithBorderRadius, ow, oh));
    12.  
    13.     Dim pgb As New PathGradientBrush(gp)
    14.  
    15.     pgb.CenterPoint = New PointF(fw / 2.0F, fh / 2.0F)
    16.     pgb.CenterColor = ShadowColor
    17.     pgb.SurroundColors = New() {Color.Transparent}
    18.     'pgb.ScaleTransform(1,1);
    19.  
    20.     Dim bitmap As New Bitmap(fw, fh)
    21.  
    22.     Dim g As Graphics = Graphics.FromImage(bitmap)
    23.  
    24.     'var ctr = new Bitmap(Width, Height, CreateGraphics());
    25.     'g.DrawImage(ctr, new Point(0,0));
    26.     'var g = CreateGraphics();
    27.     g.FillPath(pgb, gp)
    28.  
    29.     pgb.Dispose()
    30.     gp.Dispose()
    31.     '
    32.     Width = fw
    33.     Height = fh
    34.  
    35.     Return bitmap
    36. 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

  2. #2

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Re: Help

    Sorry for the "Help" title... I forgot to change it when I finished my post!!!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    Re: Help

    Quote Originally Posted by jmcilhinney View Post
    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!!!

    Quote Originally Posted by jmcilhinney View Post
    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.

  5. #5

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    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.

  6. #6

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    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
  •  



Click Here to Expand Forum to Full Width