Results 1 to 3 of 3

Thread: [2008] Friend WithEvents

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    [2008] Friend WithEvents

    Hello,

    If I drag a button to the form, when the user clicks the button to fire an event.

    The code looks like

    Code:
    Private Sub button1_Click(ByVal sender As System.Object,_
        ByVal e As System.EventArgs) Handles button1.Click
        text1.Text = "Hello World!"
    End Sub
    It's very short and simple.
    My question is shall I define the button as

    Code:
    Friend WithEvents button1 As Button
    I haven't defined it but it works well.

    I saw some books define it.
    Is it unnecessary?

    Thanks for your time.
    Last edited by zhshqzyc; Jan 6th, 2009 at 05:13 PM.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2008] Friend WithEvents

    The designer automatically does that for you. In 2005 it is in the Form.Designer.vb file. I don't have 2008 on this machine, so it might be a little different, but that code is there.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Friend WithEvents

    In Solution Explorer, click on the 'show all files' icon if all the files aren't already showing. You should see a Form1.designer.vb file in there. Open it up and have a look.

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