[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


PerformClick from form2

Posted on 2004-10-28
Medium Priority
Last Modified: 2006-11-17
Hi guys,

I've got Form1 as MDIChild with a Button1. I need to Button1.PerformClick from Form2. Form2 is a DataForm.


Question by:bmquintas
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 12441018
You mean you want to trap a button click on Form One from Form2? Is Form2 a child of Form1?

If so, you I suggest this approach:


Private WithEvents frm2 As Form2

Then when you want to call up form 2:
frm2 = New Form2

In FORM 2 add a custom event:

Public Event MyButtonClick()

In form 2's button click event handler you have this:

Private Sub Button.Click(sender as object, e as eventargs) Handles Button.click
    RaiseEvent MyButtonClick
End Sub

Now back to FORM 1
Write an event handler for the frm2.MyButtonClick event and you are good to go.
LVL 18

Expert Comment

ID: 12441279
easiset way is pass form1's object to form2 and on any instance call the function Button1.PerformClick with null parameters, if there is no processing in the function

Author Comment

ID: 12442625
Thanks ptakja, but it still does nothing. Could it be that the button1 in question is in a TabControl?

Author Comment

ID: 12442811
This is the whole picture:

Form0 is a mdicontainer therefore mdiParent
Form1 is mdichild of form0
and form2 is called from form1

It only works if Form1 is NOT mdichild of Form0.

ANy solutions?
LVL 86

Accepted Solution

Mike Tomlinson earned 750 total points
ID: 12449046
Below is how it should look.  When Form0 loads, it loads Form1 as an MDI child.  There are two buttons on Form1.  The first opens up Form2 as a child.  The second simply displays a MsgBox that says it was clicked.  On Form2, there is one button that when clicked, causes the second button on Form1 to be clicked.


Public Class Form0
    Inherits System.Windows.Forms.Form

    Private Sub Form0_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f1 As New Form1
        f1.MdiParent = Me
    End Sub
End Class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        f2.MdiParent = Me.MdiParent
        f2.Button_Reference = Me.Button2
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Button2 on Form1 Clicked")
    End Sub
End Class

Public Class Form2
    Inherits System.Windows.Forms.Form

    Public Button_Reference As Button

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not (Button_Reference Is Nothing) Then
        End If
    End Sub
End Class

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question