Results 1 to 4 of 4

Thread: RaiseEvent - Why adding to button click raises on usercontrol load

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    82

    RaiseEvent - Why adding to button click raises on usercontrol load

    This seems very odd to me. I need MainForm (Form) to be able to capture a user control event (btnConnect)

    UserControl

    Code:
        Public Event ConnectionCompletedEventArgs As EventHandler
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnConnect.Click
            RaiseEvent ConnectionCompletedEventArgs(Nothing, EventArgs.Empty)
        End Sub
    MainForm

    Code:
        Private WithEvents _server As New Server
    
    
        Private Sub ConnectEventArghs() Handles _server.ConnectionCompletedEventArgs
            Debug.WriteLine("do task here")
        End Sub
    should it be something like _server.btnConnection.click

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: RaiseEvent - Why adding to button click raises on usercontrol load

    First up, this:
    Code:
    RaiseEvent ConnectionCompletedEventArgs(Nothing, EventArgs.Empty)
    should be this:
    Code:
    RaiseEvent ConnectionCompletedEventArgs(Me, EventArgs.Empty)
    Secondly, if it's a UserControl then why are you declaring it in code when you should almost certainly be adding it to your form in the designer?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    82

    Re: RaiseEvent - Why adding to button click raises on usercontrol load

    Hi and thanks for the replys. The same issue is happening event being raised onload.

    Maybe a explanation of what i am doing will allow better assistance.

    I have 2 usercontrols and a mainform.

    Mainform docks the user controls. When mainform loads it auto loads UC1 (UserControl1). Once options have been selected and the accept button is pressed i need MainForm to read these values, load usercontrol 2 passing this information.

    am i using events wrong here?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    82

    Re: RaiseEvent - Why adding to button click raises on usercontrol load

    Opps. Managed to resolve the event error. (my own silly misstake)

    but my question stands am i doing this correctly?

    cheers as always VB

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