?
Solved

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

Posted on 2004-09-24
5
Medium Priority
?
385 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
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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