Windows Develop Bookmark and Share   
 index > Windows Forms General > Manually raising an existing event
 

Manually raising an existing event

I would like to automatically raise an existing event based on a value that is passed into a form. Note the following code:

Private strAutomatedMenuItem As String = strMenuItem

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Cursor.Current = System.Windows.Forms.Cursors.AppStarting()
        StatusBar1.Panels(0).Text = "Ready..."
        StatusBar1.Panels(1).Text = strSelectedDataSource
        frmMain.ConnectionString = frmSignon.strDataSource

        Select Case strAutomatedMenuItem
            Case "A"
                'want to raise the below event (mnuOnlineItemConnectionNotice_Click). How do I automate this???
            Case "N"

            Case "F"

        End Select

    End Sub

    Private Sub mnuOnlineItemConnectionNotice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOnlineItemConnectionNotice.Click

        Dim frmObject As New frmConnectionNotice()
        frmObject.MdiParent = Me
        StatusBar1.Text = "Processing Online Connection Notice functionality..."
        frmObject.Show()

    End Sub
MigrationUser 1  Thursday, February 13, 2003 4:21 PM
mnuOnlineItemConnectionNotice.PerformClick() or you could manuall call the method e.g.
mnuOnlineItemConnectionNotice_Click(mnuOnlineItemConnectionNotice,  new System.EventArgs())

regards
erymuzuan mustapa
MigrationUser 1  Friday, February 14, 2003 2:02 AM
Raising an event is actually quite simple.   Here is one way to do it for your example


mnuOnlineItemConnectionNotice_Click(Me, New System.EventArgs())

That should do it.  What will happen is that you are sending an instance of the form for sender and an empty eventarg object for the second parameter.  

MigrationUser 1  Friday, February 14, 2003 6:55 AM
Thanks a lot. I used the PerformClick method which worked just fine.........
MigrationUser 1  Saturday, February 15, 2003 11:03 AM

You can use google to search for other answers

Custom Search

More Threads

• WinForm/Textbox - Multiple languages on the same form
• Multi-function ListBox
• Problem in visual inheritance
• "Cannot access a disposed object"
• Compilation Error
• Multi-screen/display Cofiguration?
• OpenFileDialog problem
• Winform 3.5 ????
• Resize borderless form with API?
• About Checkbox column in datagridview