Results 1 to 3 of 3

Thread: Help in learning C#

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    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.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145
    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
  •  



Click Here to Expand Forum to Full Width