powershell Multiform project how to pass textbox message to childform textbox message

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
edgarmoreno27856
Posts: 3
Joined: Mon Jul 24, 2017 8:54 am

powershell Multiform project how to pass textbox message to childform textbox message

Post by edgarmoreno27856 »

Hi Admin

I would like to know if i created a multiform project
I would like to pass the data fill in from the main form text box to appear on the text box on a child form

mainform
$textboxmessagedisplay.text

Child form
$textboxchildcomputerdisplay

Is this possible in 2017 show-childform_psf , whats whould be the structure?
I cant find a help formwat for the show childform to which object properties i need to store the data from main form to child form .

powershell Multiform project how to pass textbox message to childform textbox message

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by jvierra »

PSS forms have no specific method for returning data from a form. You can use a global or assign the current form to a global in the "load" event. Another method is to define a custom property on the parent form and set it from the child.

Define "Param" on the child and pass the parent form object to the child.

User avatar
e27856
Posts: 5
Joined: Sat Jul 15, 2017 1:04 am

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by e27856 »

Hi Thanks for the reply

I did create the 2nd option creating the child with input parameter eg below
But the input text coming from the parent is not delivered to the object param in the child
I saw this was working in Don Jones Call-logproperties_pff as child form but not on 2017
Let me know what i need to change below



===================child=========
param(

[String]$computername
)


#form event load{

$textboxchildform.text = $Computer

}
===================child=========



===================parent=========

#Form event callchild form
$comp=$textboxmainform.text
if ((show-childform_psf -Computer $comp ) -eq 'ok')
{
show-childform_psf
}

===================parent=========

Thanks in Advance

User avatar
e27856
Posts: 5
Joined: Sat Jul 15, 2017 1:04 am

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by e27856 »

orginal code below is not working
===================child=========
param(

[String]$computername
)


#form event load{

$textboxchildform.text = $computername

}
===================child=========



===================parent=========

#Form event callchild form
$comp=$textboxmainform.text
if ((show-childform_psf -computername $comp ) -eq 'ok')
{
show-childform_psf
}

===================parent=========

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by jvierra »

You have to pass the object.

In the child form:

Code: Select all

Param(
	[System.Windows.Forms.TextBox]$parentTextbox
)

$buttonSave_Click={
	$parentTextbox.Text = $textbox1.Text
}
Call the child:

Code: Select all

$buttonCallChild_Click={
	Show-MyChild_psf $textbox1
}

User avatar
edgarmoreno27856
Posts: 3
Joined: Mon Jul 24, 2017 8:54 am

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by edgarmoreno27856 »

Hi JVierra

Thanks , i got the output


$MainForm_Load={
#TODO: Initialize Form Controls here

}

$buttonCallChildForm_Click={
#TODO: Place custom script here
if((Show-ChildForm_psf) -eq 'OK')
{
$computername=$parentTextbox.text
Show-ChildForm_psf $computername
}
}

$parentTextbox_TextChanged={
#TODO: Place custom script here

}

Param (
[String]$computername
)

$formChildForm_Load= {
#TODO: Initialize Form Controls here
$textbox1.text = $computername
}


$buttonOK_Click={
#TODO: Place custom script here


}

User avatar
edgarmoreno27856
Posts: 3
Joined: Mon Jul 24, 2017 8:54 am

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by edgarmoreno27856 »

Hi Admin

Follow up question on the refresh or notify handle to child form
Though the textbox message from mainform to child form has been passed it is manually refresh by a button to appear the output from the child form , is there a method from main form to refresh the data being set from on the childform param created?

THanks in Advance

Edgar Moreno

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: powershell Multiform project how to pass textbox message to childform textbox message

Post by jvierra »

You cannot use controls on a form that has a childform showing. The child form blocks the parent form.

Locked