Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 





How to fire a click event from another form (Sunday, September 26, 2004)

Found the following interesting discussion in the Newsgroups:

fire a click event from another form
by:Anonymous

Hello,

I have two forms - a start form running in the background and a content form in the foreground. When a timer fires on the start form, I need to fire the click event for a button on the other form. I have delcalered the 2nd form as a friend, but still cannot get to the button's click event.

Any help would be very appreciated -

thnx


 Reply:
by:Anonymous

 Hi,

If you are using the Mdiform use the following statements. and note that you need to declare the procedure which is handling the event Click of the button as public.

Dim f2 As Form2 = CType(Me.MdiParent.MdiChildren(1), Form2)
f2.Button1_Click(f2.Button1, New System.EventArgs())

where button1 is the button placed in the form2.

Actually here you are not raising the event, we are indirectly tiggering the event by calling a procedure.

If you don't have a MDI form. Have some public module and keep the instance of form2 there and access it in form2 or keep the instance in the form1 itself and access it.

I hope this may help you.

Sadha Sivam S
Malleable Minds Software Pvt Ltd.,
India


 Reply:
by:Jens Blom

 Hi
try this

------------------------------
Dim foo As New Form2
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
foo.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'call the button on form 2
foo.ButtonOnForm2.PerformClick()

'call a sub on from2
foo.subOnForm2()
End Sub
-----------------------------------

/jens



Posted by Xander Zelders
1 Comments



 
Previous Posts
    - Rich Text Box SelectionColor
    - ListBox non-Dataset load Value and discription
    - Knew how to do it the old way, but ...
    - InvalidActiveXStateException error when editing si...
    - when to use DoEvents in vb.net?
    - Playing Audio from a Filestream using MCI
    - XML in a combobox
    - Setup Project
    - WMI Com Interop exception handling
    - Problem With Mailto Start Process

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland