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.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
craigjb
Posts: 11
Last visit: Mon Oct 05, 2020 7:31 am

Keep child form open and append data to main form

Post by craigjb »

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: 1669
Last visit: Fri Apr 12, 2024 2:35 pm
Answers: 39
Been upvoted: 31 times

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

Post by brittneyr »

[TOPIC MOVED TO POWERSHELL GUI FORUM BY MODERATOR]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 11
Last visit: Mon Oct 05, 2020 7:31 am

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

Post by craigjb »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 11
Last visit: Mon Oct 05, 2020 7:31 am

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

Post by craigjb »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Not really. You would have to code all of that and I wouldn't use an RTB,
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Here is how to create a scrolling label control.
https://stackoverflow.com/questions/259 ... in-c-sharp
User avatar
craigjb
Posts: 11
Last visit: Mon Oct 05, 2020 7:31 am

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

Post by craigjb »

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
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked