Error 1 Handles clause requires a WithEvents variable defined in the type container or one of its ba

P

Pascal

hello

What's the meaning of this message ?

C# in form1.designer.cs
//
// tsbSaveFile
//
this.tsbSaveFile.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.tsbSaveFile.Image =
global::MazeApp.Properties.Resources.Save;
this.tsbSaveFile.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.tsbSaveFile.Name = "tsbSaveFile";
this.tsbSaveFile.Size = new System.Drawing.Size(23, 22);
this.tsbSaveFile.Text = "Sauver fichier";
this.tsbSaveFile.ToolTipText = "Sauver un labyrinthe";
this.tsbSaveFile.Click += new
System.EventHandler(this.tsbSaveFile_Click);

c# in form1.cs
private void tsbSaveFile_Click( object sender, EventArgs e )
{
SaveToFile( _strFile );
}

That's vb code translated from C" form1.designer.vb
'
' tsbSaveFileAs
'
Me.tsbSaveFileAs.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Image
Me.tsbSaveFileAs.Image = Global.MazeApp.Properties.Resources.SaveAs
Me.tsbSaveFileAs.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tsbSaveFileAs.Name = "tsbSaveFileAs"
Me.tsbSaveFileAs.Size = New System.Drawing.Size(23, 22)
Me.tsbSaveFileAs.Text = "Sauve le fichier sous"
Me.tsbSaveFileAs.ToolTipText = "Sauver comme nouveau labyrinthe"
AddHandler Me.tsbSaveFileAs.Click, New System.EventHandler(AddressOf
Me.tsbSaveFileAs_Click)


in form1

Private Sub tsbSaveFile_Click(sender As Object, e As EventArgs)
SaveToFile(_strFile)
End Sub


thanks
 
J

Jeff Johnson

What's the meaning of this message ?

Are you asking about code that has been translated FROM C# TO VB.NET? If so,
you should be asking in a VB.NET group.
 
P

Pascal

No I am just playing with C#, using sharpdevelopp and comparing with vs
studio behavior. I noticed this :

When i make a form with a button on it in sharpdevelopp i get this
########################in mainform.vb :

Public Partial Class MainForm
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer
support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
End Sub

Sub Button1Click(sender As Object, e As EventArgs)

End Sub
End Class

#####################and this in mainform.designer.vb :
'
' Created by SharpDevelop.
' User: pascal
' Date: 03/06/2009
' Time: 17:38
'
' To change this template use Tools | Options | Coding | Edit Standard
Headers.
'
Partial Class MainForm
Inherits System.Windows.Forms.Form

''' <summary>
''' Designer variable used to keep track of non-visual components.
''' </summary>
Private components As System.ComponentModel.IContainer

''' <summary>
''' Disposes resources used by the form.
''' </summary>
''' <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If components IsNot Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

''' <summary>
''' This method is required for Windows Forms designer support.
''' Do not change the method contents inside the source code editor. The
Forms designer might
''' not be able to load this method if it was changed manually.
''' </summary>
Private Sub InitializeComponent()
Me.button1 = New System.Windows.Forms.Button
Me.SuspendLayout
'
'button1
'
Me.button1.Location = New System.Drawing.Point(61, 51)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(73, 28)
Me.button1.TabIndex = 0
Me.button1.Text = "button"
Me.button1.UseVisualStyleBackColor = true
AddHandler Me.button1.Click, AddressOf Me.Button1Click
'
'MainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 264)
Me.Controls.Add(Me.button1)
Me.Name = "MainForm"
Me.Text = "ESSAI"
Me.ResumeLayout(false)
End Sub
Private button1 As System.Windows.Forms.Button
End Class

#######################IN VB IDE I GET this
:###############################################"

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class

#################################""IN FORM1.designer.VB and this :
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form remplace la méthode Dispose pour nettoyer la liste des composants.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Requise par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée à l'aide du Concepteur Windows Form.
'Ne la modifiez pas à l'aide de l'éditeur de code.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(100, 125)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 264)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button

End Class
#################################
When comparing just these lines :
in ShDv :
Sub Button1Click(sender As Object, e As EventArgs)
End Sub

in VB :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
End Sub

Here the Sub is"private" and there is one "handles" but no "AddHandler
Me.button1.Click, AddressOf Me.Button1Click" in the designer ?!




So I noticed : when I use sharpdevelopp to translate some C# code to VB code
an error occurs :

Handles clause requires a WithEvents variable defined in the type container
or one of its basic types.

To stop the errors I wiped all the handles instructions in the Sub and I
kept all the "AddHandler Me.cbxDirection.SelectedIndexChanged, New
System.EventHandler(AddressOf Me.cbxDirection_SelectedIndexChanged)" and It
works.... until I change something in the design mode of the form... Then VB
wipe all the "AddHandler..." in the designer code and restore all the
"handles"
in the code of the form........

It's strange and i don't why it oes that automatically.
That's the reason of my post. It is a bug or not ?
Or perhaps it's because of the "New System.EventHandler"

Thanks
pascal
 
J

Jeff Johnson

So I noticed : when I use sharpdevelopp to translate some C# code to VB
code an error occurs :

And again, you should either take these problems to a Sharpdevelop group or
a VB.NET group, because they have little to do with C#. I just think you
have a better chance of getting good answers in a group that is relevant to
your question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top