Solved

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

Posted on 2004-09-24
5
347 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Winform Module - What is the ASP.Net equiv 2 40
Create a datatable in vb.net dynamically 1 40
Generate Numbers in JQuery file 11 72
Find date of 2nd Thursday of each month 3 34
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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