Re: C# event Handles
- From: Simon Hart [MVP] <srhartone@xxxxxxxxx>
- Date: Thu, 12 Jun 2008 11:33:06 -0700
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;
}
}
- References:
- C# event Handles
- From: Nina
- Re: C# event Handles
- From: Chris Tacke, eMVP
- C# event Handles
- Prev by Date: RE: CAB installation
- Next by Date: Re: Installing CF app on a desktop or server
- Previous by thread: Re: C# event Handles
- Index(es):
Relevant Pages
|