WinForms - Invoking events on one form from another form
Posted on 2009-05-14
I have an app that opens a form that contains a CR Viewer control. I have added a button so that when you click the button on the (reportForm) it fires the click event in the mainform and starts a download for data. This way I can refresh the data without closing and reopening the form.
The problem is that when I click the "refresh" button on the reportForm, it fires on the main form, is caught, but it seems to run through the code 2 times...like I clicked the main download button twice. That really isn't possible since the main button is disabled as soon as it is clicked, but I know it runs 2 times because the thread that does the download, its thread_complete code runs 2 times causing me errors.
in the main form I have declared a ToolStripButton, since that is what is used on the reportForm, as the following:
Private WithEvents refreshDataButton as ToolStripButton
Then when the reportForm is created, I "link" the buttons...
dim viewer as new reportForm
refreshDataButton = viewer.reportRefreshButton
I then catch the click event of the refreshDataButton in the mainform, but the code that runs gets ran 2 times...I will post more code if needed...
Any help is appreciated...