Solved

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

Posted on 2014-02-02
3
383 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
[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
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 250 total points
ID: 39827721
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
ID: 39827867
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
ID: 39827872
Thanks for the help
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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