Solved

Passing startup parameters to child from MDI parent

Posted on 2010-09-09
7
713 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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