Keep child form open and append data to main form

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
User avatar
craigjb
Posts: 8
Joined: Mon Apr 23, 2018 7:30 am

Keep child form open and append data to main form

Post by craigjb » Thu Nov 14, 2019 8:25 pm

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build:
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64 bit

*** Please add details and screenshots as needed below. ***

Hi, I have started a multi-form project and every time I send a message to the main form, the child form closes. What I need to be able to do is keep the child form open and append a new message to the line below on the richtextbox on the main form. Is this possible? Thanks so much!

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
brittneyr
Site Admin
Posts: 307
Joined: Thu Jun 01, 2017 7:20 am

Re: Keep child form open and append data to main form

Post by brittneyr » Fri Nov 15, 2019 7:56 am

[TOPIC MOVED TO POWERSHELL GUI FORUM BY MODERATOR]
Brittney Ryn
SAPIEN Technologies, Inc.

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

Re: Keep child form open and append data to main form

Post by jvierra » Fri Nov 15, 2019 8:00 am

The parent form is not accessible from the child by any normal means. Pass the control as a parameter to the child and add the text to the control object passed.

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

Re: Keep child form open and append data to main form

Post by jvierra » Fri Nov 15, 2019 8:15 am

Also you can access the mainform's variables directly as they should be in scope. Just refrence the variable for the textbox you want to write to. If it is called "$richtextbox1" then you can access it like this:

$richtextbox1.AppendText('my message')

If the dialog is aborting then you may have issues with your code such as bad syntax after the output or it may be throwing an exception.

User avatar
craigjb
Posts: 8
Joined: Mon Apr 23, 2018 7:30 am

Re: Keep child form open and append data to main form

Post by craigjb » Fri Nov 15, 2019 8:44 am

Thanks jvierra! The reason I'd like to do this is because I will be presenting what is on the main form so I don't need to touch it per say. The objective is to be able to use the child form on a different screen (2 screen setup) and update (append) the next line of text to the richtextbox on the main form. It looks like this is only possible to update the main form when you close out the child form

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

Re: Keep child form open and append data to main form

Post by jvierra » Fri Nov 15, 2019 9:03 am

No. You can update controls on the main form by passing the control to the child as a parameter. We do it all of the time.

User avatar
craigjb
Posts: 8
Joined: Mon Apr 23, 2018 7:30 am

Re: Keep child form open and append data to main form

Post by craigjb » Fri Nov 15, 2019 10:26 am

Got it to work, thank you! I just have one more final question about the form.

I'm currently appending the text from the child form to the main forms richtextbox. I need to center the newly appended text both horizontally and vertically in the box, so it is literally in the center of the richtextbox. The text above it needs to auto scroll up when the new text is added. Is this something that can be accomplished? Thanks again!

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

Re: Keep child form open and append data to main form

Post by jvierra » Fri Nov 15, 2019 10:30 am

Not really. You would have to code all of that and I wouldn't use an RTB,

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

Re: Keep child form open and append data to main form

Post by jvierra » Fri Nov 15, 2019 10:32 am

Here is how to create a scrolling label control.
https://stackoverflow.com/questions/259 ... in-c-sharp

User avatar
craigjb
Posts: 8
Joined: Mon Apr 23, 2018 7:30 am

Re: Keep child form open and append data to main form

Post by craigjb » Fri Nov 15, 2019 12:09 pm

Thanks jvierra, what would you recommend using on PS studio instead of richtextbox for displaying this data? Looks like I'm going to have to forget the auto-scrolling. When I click submit on my child form, I delete clear the previous string in the textbox and insert the next one however I need to this to just be horizontally centered within the form itself, whether its a richtextbox or not. It there anything in the toolbox in PS studio that can display this string within my form? Thank you

Locked