|
-
Aug 16th, 2003, 12:57 AM
#1
Thread Starter
Addicted Member
Help in learning C#
Hi all,
I'm just starting to learn C#. What I do is I read sample code in C# and to test myself if I understand the code, I'm trying to convert the code to VB.Net. I have this particular code that I can't understand. Can somebody out there be kind enough to explain this.
Code:
class NumberBox:TextBox // I know that this is a class inherited from Textbox
{
public NumberBox() // what's the difference between this and the class declaration, what's the counterpart of this in VB.Net?
{
this.KeyPress+=new KeyPressEventHandler(NumberBox_KeyPress); // how do you write this in VB?
}
}
Thanks very much for any help.
-
Aug 16th, 2003, 11:51 AM
#2
PowerPoster
public NumberBox() is the constructor for the class. Look up constructors for VB.Net and you will have your answer.
http://www.ondotnet.com/pub/a/dotnet...4/vbooppt2.htm
this.KeyPress+=new KeyPressEventHandler(NumberBox_KeyPress);
That is just subscribing to a keypress event of the object. The KeyPressEventHandler is a delegate, and the NumberBox_KeyPress is the method that will be called when the event fires.
http://www.mvps.org/vbnet/index.html..._ms_events.htm
-
Aug 18th, 2003, 12:35 AM
#3
Thread Starter
Addicted Member
Thanks hellswraith!
I finally convert that piece of code into:
Code:
Public Sub New()
MyBase.New()
AddHandler Me.KeyPress, AddressOf NumberBox_KeyPress
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|