Solved

VB.net Error in convering code behind a form from C# to VB.net

Posted on 2014-02-02
3
378 Views
Last Modified: 2014-02-02
Hi

I am trying to convert the C# code at the bottom to the VB.net code just above.
I have one error at the line:
  Me.toolStrip1.LocationChanged = Sub(sender As Object, e As EventArgs) Me.panel1.Height = Me.toolStrip1.Top
The error is
Error      1      '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



Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1

    Public Sub New()
        InitializeComponent()

        ' Make your controls movable by a mouseclick
        Helper.ControlMover.Init(Me.button1)
        Helper.ControlMover.Init(Me.checkBox1)
        Helper.ControlMover.Init(Me.groupBox1)
        Helper.ControlMover.Init(Me.textBox1)
        Helper.ControlMover.Init(Me.label1)

        ' Move a panel by its toolstrip
        Helper.ControlMover.Init(Me.toolStrip2, Me.panel3, Helper.ControlMover.Direction.Any)

        ' Make a splitter from toolstrip
        Helper.ControlMover.Init(Me.toolStrip1, Helper.ControlMover.Direction.Vertical)
        Me.toolStrip1.LocationChanged = Sub(sender As Object, e As EventArgs) Me.panel1.Height = Me.toolStrip1.Top
    End Sub

   
End Class

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

namespace MoveYourControls
{
      public partial class Form1 : Form
      {
            public Form1()
            {
                  InitializeComponent();

                  // Move your controls
                  Helper.ControlMover.Init(this.button1);
                  Helper.ControlMover.Init(this.checkBox1);
                  Helper.ControlMover.Init(this.groupBox1);
                  Helper.ControlMover.Init(this.textBox1);
                  Helper.ControlMover.Init(this.label1);

                  // Move a panel by its toolstrip
                  Helper.ControlMover.Init(this.toolStrip2, this.panel3, Helper.ControlMover.Direction.Any);

                  // Make a splitter from toolstrip
                  Helper.ControlMover.Init(this.toolStrip1, Helper.ControlMover.Direction.Vertical);
                  this.toolStrip1.LocationChanged += delegate(object sender, EventArgs e)
                  {
                        this.panel1.Height = this.toolStrip1.Top;
                  };
            }

        private void button1_Click(object sender, EventArgs e)
        {

        }

      }
}
0
Comment
Question by:murbro
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 250 total points
Comment Utility
Change this:
Me.toolStrip1.LocationChanged = Sub(sender As Object, e As EventArgs) Me.panel1.Height = Me.toolStrip1.Top
    End Sub

Open in new window


To this:
AddHandler Me.toolStrip1.LocationChanged, Sub(sender As Object, e As EventArgs) Me.panel1.Height = Me.toolStrip1.Top
    End Sub

Open in new window

0
 
LVL 14

Assisted Solution

by:Matti
Matti earned 250 total points
Comment Utility
Hi!

try this http://www.icsharpcode.net/OpenSource/SD/Default.aspx

it even creates better .NET code than you if you do convert it back to vb.net
0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks for the help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now