Support Forums

Passing data to child form control

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.
User avatar
Helocheck
Posts: 29
Joined: Tue Apr 29, 2014 1:55 am

Passing data to child form control

Postby Helocheck » Tue Feb 09, 2016 1:35 am

Ok title is not that self explanatory but could not come up with something better so let me try to explain.

I have a GUI project and a main form with couple of buttons each carrying on some task, each task (like getting mailboxes or AD users for example) writes a log through a function in a richtextbox used to keep a verbose log of every action taken.

I would like to move the aforementioned richtextbox to a child form that is shown upon user's request and was wondering how to handle this as if I try to send data to the control directly from the main form I get errors.

I thought of appending data to a variable each time an action is carried on and then display variable's data into the child richtexbox and this works but I end up with duplicate entries in the log which is not exactly what I want.

I'm sure there is a simple workaround to this or I'm doing something wrong but can't seem able to spot it.

Any idea/suggestion?

Thanks L.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Passing data to child form control

Postby jvierra » Tue Feb 09, 2016 1:47 am

If you are logging to a file just open the file in the child form. Why pass a huge chunk of data.

Consider using an MDO form and log to an MDI child.
User avatar
Helocheck
Posts: 29
Joined: Tue Apr 29, 2014 1:55 am

Re: Passing data to child form control

Postby Helocheck » Tue Feb 09, 2016 2:49 am

Well actually the initial plan was not to log to a file, even if an option to export is present, but this has more to do with my inexperience with putting GUIs in front of PowerShell than anything else.

As I understand it is not possible to do what I originally planned to do so I'll just use the log file appraoch and get rid of it once the application is closed.

Thanks again for your time and putting me on the right track.

L.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Passing data to child form control

Postby jvierra » Tue Feb 09, 2016 2:55 am

If you create the child by hand in the main form then you can write to the box and have it display when needed. Just create a default forma nd add the rtb to it and set it to fill the form. However it cannot be dynamic.

You could also use an IE object to log to and it can shown or hidden without any disruption.
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Passing data to child form control

Postby jvierra » Tue Feb 09, 2016 3:17 am

Here is an example of what you can do with an MDI form:
Attachments
Demo-MDIForm.ps1
(6.72 KiB) Downloaded 113 times
User avatar
Helocheck
Posts: 29
Joined: Tue Apr 29, 2014 1:55 am

Re: Passing data to child form control

Postby Helocheck » Tue Feb 09, 2016 3:22 am

Beg with my ignorance, may I ask you to elaborate a bit the IE part (I'm not a fan of acronyms and IE spawns Internet Explorer in my mind).

As per the child form I've created it with Add - New object and then picked up an empty form then added a button to the main form calling the load-form, is there another appraoch to this?
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Passing data to child form control

Postby jvierra » Tue Feb 09, 2016 3:40 am

IE - Internet Explorer
$ie=New-Object -ComObject InternetExplorer.Application
$ie.Navigate('about:blank')
$ie.Visible=$true
$ie.Document.Write('<style type="text/css">.red{color:blue}</style>')
$ie.Document.Write('<p class="red">Hello World</p>')
User avatar
Helocheck
Posts: 29
Joined: Tue Apr 29, 2014 1:55 am

Re: Passing data to child form control

Postby Helocheck » Tue Feb 09, 2016 4:00 am

Thanks for the demo form I did not see it.

I'll play around with it and see what I can come up with, and thanks for IE part as well :-)

I guess I should be set for the moment, I just need to play around with the demo and IE and see what better fits the tool

Thanks once again-
User avatar
jvierra
Posts: 10017
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Passing data to child form control

Postby jvierra » Tue Feb 09, 2016 4:51 am

Here is a full demo of a logging MDI Form that has one form that write to another. It's a PSF so it is easier to analyze and modify.
Attachments
Demo-MDIForm2.psf
(21.81 KiB) Downloaded 110 times
User avatar
Helocheck
Posts: 29
Joined: Tue Apr 29, 2014 1:55 am

Re: Passing data to child form control

Postby Helocheck » Wed Feb 10, 2016 2:16 pm

Thanks a lot for the demo, I ended up using a txt log file whichi serving the purpose nicely.

Still not sure if I will get rid of the file on form close but that's another story.

Many thanks for the example it will prove anyhow useful and stimulating to keep learning or when I have a doubt .

Return to “PowerShell GUIs”

Who is online

Users browsing this forum: Mitzen and 2 guests