[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.net Errors in converting C# to VB.net

Posted on 2014-02-02
6
Medium Priority
?
592 Views
Last Modified: 2014-02-02
Hi

I get these errors when converting the C# code at the bottom to the VB.net code just above

Error      4      Single-line statement lambdas must include exactly one statement.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      36      68      Infra_WinForms
Error      2      'Public Event MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      31      13      Infra_WinForms
Error      3      'Public Event MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      36      4      Infra_WinForms
Error      1      'Public Event MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      25      13      Infra_WinForms
Error      8      'Public Event LocationChanged(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.      C:\Users\murbro\documents\visual studio 2010\Projects\Infra_WinForms\Infra_WinForms\Form1.vb      22      9      Infra_WinForms
Error      7      'End If' must be preceded by a matching 'If'.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      43      4      Infra_WinForms
Error      5      'e' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      38      46      Infra_WinForms
Error      6      'e' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Infra_WinForms\Infra_WinForms\ControlMover.vb      41      45      Infra_WinForms




Imports System.Drawing
Imports System.Windows.Forms


Namespace Helper
    Class ControlMover
        Public Enum Direction
            Any
            Horizontal
            Vertical
        End Enum

        Public Shared Sub Init(control As Control)
            Init(control, Direction.Any)
        End Sub

        Public Shared Sub Init(control As Control, direction As Direction)
            Init(control, control, direction)
        End Sub

        Public Shared Sub Init(control As Control, container As Control, direction__1 As Direction)
            Dim Dragging As Boolean = False
            Dim DragStart As Point = Point.Empty
            control.MouseDown += Sub(sender As Object, e As MouseEventArgs)
                                     Dragging = True
                                     DragStart = New Point(e.X, e.Y)
                                     control.Capture = True

                                 End Sub
            control.MouseUp += Sub(sender As Object, e As MouseEventArgs)
                                   Dragging = False
                                   control.Capture = False

                               End Sub
                  control.MouseMove += Sub(sender As Object, e As MouseEventArgs) If Dragging Then
            If direction__1 <> Direction.Vertical Then
                container.Left = Math.Max(0, e.X + container.Left - DragStart.X)
            End If
            If direction__1 <> Direction.Horizontal Then
                container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y)
            End If
                  End If
        End Sub
    End Class
End Namespace

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Helper
{
      class ControlMover
      {
            public enum Direction
            {
                  Any,
                  Horizontal,
                  Vertical
            }

            public static void Init(Control control)
            {
                  Init(control, Direction.Any);
            }

            public static void Init(Control control, Direction direction)
            {
                  Init(control, control, direction);
            }

            public static void Init(Control control, Control container, Direction direction)
            {
                  bool Dragging = false;
                  Point DragStart = Point.Empty;
                  control.MouseDown += delegate(object sender, MouseEventArgs e)
                  {
                        Dragging = true;
                        DragStart = new Point(e.X, e.Y);
                        control.Capture = true;
                  };
                  control.MouseUp += delegate(object sender, MouseEventArgs e)
                  {
                        Dragging = false;
                        control.Capture = false;
                  };
                  control.MouseMove += delegate(object sender, MouseEventArgs e)
                  {
                        if (Dragging)
                        {
                              if (direction != Direction.Vertical)
                                    container.Left = Math.Max(0, e.X + container.Left - DragStart.X);
                              if (direction != Direction.Horizontal)
                                    container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y);
                        }
                  };
            }
      }
}
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 total points
ID: 39827657
Here is the compilable code. Please check if the logic is what you want.
Imports System.Drawing
Imports System.Windows.Forms


Namespace Helper
	Class ControlMover
		Public Enum Direction
			Any
			Horizontal
			Vertical
		End Enum

		Public Shared Sub Init(control As Control)
			Init(control, Direction.Any)
		End Sub

		Public Shared Sub Init(control As Control, direction As Direction)
			Init(control, control, direction)
		End Sub

		Public Shared Sub Init(control As Control, container As Control, direction__1 As Direction)
			Dim Dragging As Boolean = False
			Dim DragStart As Point = Point.Empty
			AddHandler control.MouseDown, Sub(sender As Object, e As MouseEventArgs)
													   Dragging = True
													   DragStart = New Point(e.X, e.Y)
													   control.Capture = True

												   End Sub
			AddHandler control.MouseUp, Sub(sender As Object, e As MouseEventArgs)
													 Dragging = False
													 control.Capture = False

												 End Sub
			AddHandler control.MouseMove, Sub(sender As Object, e As MouseEventArgs)
													   If Dragging Then
														   If direction__1 <> Direction.Vertical Then
															   container.Left = Math.Max(0, e.X + container.Left - DragStart.X)
														   End If
														   If direction__1 <> Direction.Horizontal Then
															   container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y)
														   End If
													   End If
												   End Sub
		End Sub
	End Class
End Namespace

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39827665
To declare anonymous delegate in VB.Net, you need to use this syntax:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Button1.Click,
            Sub()
                MessageBox.Show("Click")
            End Sub
    End Sub
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39827666
Try this (NOT tested):
Imports System.Drawing
Imports System.Windows.Forms


Namespace Helper
    Class ControlMover
        Public Enum Direction
            Any
            Horizontal
            Vertical
        End Enum

        Public Shared Sub Init(control As Control)
            Init(control, Direction.Any)
        End Sub

        Public Shared Sub Init(control As Control, direction As Direction)
            Init(control, control, direction)
        End Sub

        Public Shared Sub Init(control As Control, container As Control, direction__1 As Direction)
            Dim Dragging As Boolean = False
            Dim DragStart As Point = Point.Empty
            AddHandler control.MouseUp, Sub(sender As Object, e As MouseEventArgs)
                                            Dragging = True
                                            DragStart = New Point(e.X, e.Y)
                                            control.Capture = True
                                        End Sub

            AddHandler control.MouseUp, Sub(sender As Object, e As MouseEventArgs)
                                            Dragging = False
                                            control.Capture = False
                                        End Sub

            AddHandler control.MouseUp, Sub(sender As Object, e As MouseEventArgs)
                                            If Dragging Then
                                                If direction__1 <> Direction.Vertical Then
                                                    container.Left = Math.Max(0, e.X + container.Left - DragStart.X)
                                                End If
                                                If direction__1 <> Direction.Horizontal Then
                                                    container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y)
                                                End If
                                            End If
                                        End Sub
        End Sub

    End Class
End Namespace

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:MacroShadow
ID: 39827670
Oops looks like TheAvenger beat me to it!
0
 

Author Closing Comment

by:Murray Brown
ID: 39827700
Thanks very much
0
 

Author Comment

by:Murray Brown
ID: 39827712
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question