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.
Passing data to child form control
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.
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.
- PsCustomObject
- Posts: 137
- Last visit: Thu Mar 28, 2024 3:34 am
- PsCustomObject
- Posts: 137
- Last visit: Thu Mar 28, 2024 3:34 am
Re: Passing data to child form control
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.
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
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.
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
Here is an example of what you can do with an MDI form:
- Attachments
-
- Demo-MDIForm.ps1
- (6.72 KiB) Downloaded 278 times
- PsCustomObject
- Posts: 137
- Last visit: Thu Mar 28, 2024 3:34 am
Re: Passing data to child form control
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?
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
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>')
$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>')
- PsCustomObject
- Posts: 137
- Last visit: Thu Mar 28, 2024 3:34 am
Re: Passing data to child form control
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-
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
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 270 times
- PsCustomObject
- Posts: 137
- Last visit: Thu Mar 28, 2024 3:34 am
Re: Passing data to child form control
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 .
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 .