Page 1 of 2

Passing data to child form control

Posted: Tue Feb 09, 2016 12:35 am
by PsCustomObject
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.

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 12:47 am
by jvierra
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.

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 1:49 am
by PsCustomObject
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.

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 1:55 am
by jvierra
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.

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 2:17 am
by jvierra
Here is an example of what you can do with an MDI form:

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 2:22 am
by PsCustomObject
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?

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 2:40 am
by jvierra
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>')

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 3:00 am
by PsCustomObject
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-

Re: Passing data to child form control

Posted: Tue Feb 09, 2016 3:51 am
by jvierra
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.

Re: Passing data to child form control

Posted: Wed Feb 10, 2016 1:16 pm
by PsCustomObject
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 .