Solved

Passing startup parameters to child from MDI parent

Posted on 2010-09-09
7
719 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 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