Solved

Passing startup parameters to child from MDI parent

Posted on 2010-09-09
7
709 Views
Last Modified: 2013-12-17
First time using Multiple Document Interface Windows forms.    

How does one pass startup parameters from the parent?  
Including a URL with examples would be gratefully accepted.

Thank you.
0
Comment
Question by:RichardKline
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Assisted Solution

by:ghayasurrehman
ghayasurrehman earned 125 total points
ID: 33640924
Create new constructors, eg. the code is for a sub form
public class subForm
{
string m_param1;

public subForm()
{
    InitializeComponents();
}

public subForm(string param1)
{
     this.m_param1 = param1;
    InitializeComponents();
}


}

Open in new window

0
 
LVL 1

Author Comment

by:RichardKline
ID: 33641184
Going to be stupid about this. Converting this to vb.net, I have the SUBFORM code below which seems very reasonable.. But how do I code the parent?  

Thank you.

PARENT (does not work).
        Dim NewChild As subform = New subform("thisParameter")
        With NewChild
            .MdiParent = Me
            .Show()
        End With

SUBFORM
Public Class subform
    Private m_param1 As String

    Private Sub subform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Public Sub subform()
        InitializeComponent()
    End Sub

    Public Sub subform(ByVal param1 As String)
        Me.m_param1 = param1
        InitializeComponent()
    End Sub

End Class
0
 
LVL 3

Expert Comment

by:ghayasurrehman
ID: 33641234
what is the error?
have you set parent midcontainer property = true ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:ghayasurrehman
ID: 33641245
or change the constructor as follows
Public Sub subform(ByVal param1 As String)
        InitializeComponent()
        Me.m_param1 = param1
End Sub

Open in new window

0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 375 total points
ID: 33641482
if you need to pass parameters form one form to another even if it is MDI parent ,Child you can use the following:
1.using directCast like
Dim f As Form2 = DirectCast(Me.MdiParent, Form2)
f.Text = ...
2.Using Public Variables
3.Or...
'Below the public Class...



Private _passedText As String



    Public Property [PassedText]() As String

        Get

            Return _passedText

        End Get

        Set(ByVal Value As String)

            _passedText = Value

        End Set

    End Property





'so you have label text named LAbel1



Before you open the child set

PassedText=me.label1.text

'....then When you open then child try (let's say in toolstrip Button)

            Dim ChildForm As New Form   'or an existing form 

            ChildForm = FormWindowState.Normal

            ChildForm.MdiParent = Me

'Then in a label control in chikd Form (Named ChildLabel)

            ChildLabel.Text=PassedText   'And there you go

Open in new window

0
 
LVL 1

Author Comment

by:RichardKline
ID: 33642756
Sorry that I could not respond earlier.
ghayasurrehman, Error = VS 2010's Intellisense objected with an "unknown constructor" error.  But this parent code works fine with the subForm code as you presented it.
        Dim NewChild As subform = New subform()
        With NewChild
            .subform("ThisParameter")
            .MdiParent = Me
            .Show()
        End With
*************
jtoutou,
Very Cool.  I knew that you could directcast to/from a child form's element (label, textbox) but that was much too limiting.   Never thought about using Public Properties.  

Thank you, Both!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33644017
Very Welcome...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

19 Experts available now in Live!

Get 1:1 Help Now