Solved

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

Posted on 2004-09-24
5
330 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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now