Solved

Executing procedure/functions in child form from MDI form - Question repeating with more clarification

Posted on 2004-09-24
5
344 Views
Last Modified: 2012-05-05
Sir,

I have one MDI form and 20 child forms.  In each child form I have command button named cmd_add.  According requirement, in each form, procedure/function coming under click event of cmd_add is different.  I have one command button in MDI form.  when I will click command button in MDI form, I want to execute procedure/function written under the cmd_add command button of active child form.  if I give msgbox inside procedure or function in child form, it is executing, but other satement are not executing or negleting. I hope, now question is clear.  Please help me.
0
Comment
Question by:adwat
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12144521
What you need to do is create an interface that all of you child forms implement:

' --------------------------------------------------------------------------------
' Create this interface in a Module
' --------------------------------------------------------------------------------
Module Module1

    Public Interface cmdAddClicker

        Sub cmdAddClick()

    End Interface

End Module

' --------------------------------------------------------------------------------
' All of your child forms need to implement interface cmdAddClicker
' --------------------------------------------------------------------------------
Public Class Form2    
    Inherits System.Windows.Forms.Form
    Implements cmdAddClicker

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = DateTime.Now()
    End Sub

    Private Sub cmd_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_add.Click
        MsgBox(Me.Text)
    End Sub

    Public Sub cmdAddClick() Implements Module1.cmdAddClicker.cmdAddClick
        cmd_add_Click(Nothing, Nothing)
    End Sub

End Class

' --------------------------------------------------------------------------------
' Now your MDI Form can grab the active MDI Child, cast it
' to a cmdAddClicker and call the cmdAddClick sub for that form.
' --------------------------------------------------------------------------------
Public Class Form1 ' This is your MDI form
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim f As Form = Me.ActiveMdiChild
        If Not (f Is Nothing) Then
            Dim clickIt As cmdAddClicker
            clickIt = CType(f, cmdAddClicker)
            clickIt.cmdAddClick()
        End If
    End Sub

End Class
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 250 total points
ID: 12147109
You can do this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
     Dim f As Object = Me.ActiveMdiChild
     f.cmd_add.PerformClick()
end sub

You have to change the modifiers property of the button in your child form to public in order to be accessible.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 62
Need help making a program or form for inventory that exports to txt 8 43
VB.NET 1 28
Generate Numbers in JQuery file 11 66
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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