Solved

Passing startup parameters to child from MDI parent

Posted on 2010-09-09
7
712 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Filesystemobject or .NET version 3 33
Replace &lt; with < 14 54
SSL https .net web site force redirect 3 34
How to add <appSettings> to the webconfig file 2 20
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

911 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

22 Experts available now in Live!

Get 1:1 Help Now