Re: C# event Handles

Tech-Archive recommends: Fix windows errors by optimizing your registry



Talk about this hungarian notation Chris, I have just spent the last week or
so looking at our clients VB.NET 1.1 apps that use just that style. Classes
prefixed with cls, object variables prefixed with o etc etc. It drives me
*mad* it's bloody awful to read, it doesn't fit at all into the .NET
framework and it gives no value at all in a OO strongly typed language like
C#/VB.NET.

If anyone still writes code this way, please read this before writing
another line of code! :)
http://www.amazon.co.uk/Framework-Design-Guidelines-Conventions-Libraries/dp/0321246756/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1200000064&sr=8-1

--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Chris Tacke, eMVP" wrote:

Sure, you never wire up the base Click event in the C# code like you do in
the VB code. (I also don't like your use of antiquated hungarian notation,
but that's anotehr story).

class clsLabel : Control
{
public delegate void labelClickEventHandler(object sender, System.EventArgs
e);
public event labelClickEventHandler labelClick;

public clsLabel()
{
base.Click += clsLabelClick;
}

private void clsLabelClick(object sender, System.EventArgs e)
{
if (labelClick != null)
labelClick(sender, e);
}
}


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"Nina" <Nina@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:96E22353-26AC-4042-98B4-A49D464D5A6C@xxxxxxxxxxxxxxxx
I have the code in VB with Handles event that creates clickable labels on a
form. I'm trying to write same code in C#. However it doesn't work. Please
help me to find a solution for event Handles in C#.

VB Handles
---------------------
Public Class clsLabel
Inherits Control

Event labelClick(ByVal sender As Object, ByVal e As System.EventArgs)

Private Sub clsLabelClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
RaiseEvent labelClick(sender, e)
End Sub
End Class


Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents lblEnTick As clsLabel

Private Sub InitializeLabels()
lblEnTick = New clsLabel
End Sub

Private Sub lblclick(ByVal lbl As Object, ByVal e As System.EventArgs)
Dim l As clsLabel = CType(lbl, clsLabel)
End Sub
End Class



C# Handles?
------------------------------------------
class clsLabel : Control
{
public delegate void labelClickEventHandler(object sender,
System.EventArgs
e);
public event labelClickEventHandler labelClick;

private void clsLabelClick(object sender, System.EventArgs e)
{
if (labelClick != null)
labelClick(sender, e);
}
}


public partial class Form1 : System.Windows.Forms.Form
{
private void InitializeLabels()
{
lblEnTick = new clsLabel();
lblEnTick.labelClick += lblclick;
}

private void lblclick(object lbl, System.EventArgs e)
{
clsLabel l = (clsLabel)lbl;
}
}






.



Relevant Pages

  • Re: C# event Handles
    ... class clsLabel: Control ... public delegate void labelClickEventHandler(object sender, ... public event labelClickEventHandler labelClick; ... private void clsLabelClick ...
    (microsoft.public.dotnet.framework.compactframework)
  • C# event Handles
    ... Event labelClick(ByVal sender As Object, ... Private Sub clsLabelClick(ByVal sender As Object, ... Friend WithEvents lblEnTick As clsLabel ... private void clsLabelClick ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: C# event Handles
    ... class clsLabel: Control ... public delegate void labelClickEventHandler(object sender, ... public event labelClickEventHandler labelClick; ... private void clsLabelClick ...
    (microsoft.public.dotnet.framework.compactframework)