Solved

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

Posted on 2004-09-24
5
356 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
[X]
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
5 Comments
 
LVL 86

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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