PowerShell Studio 2017 Version 5.4.136 64 bit
Running on Windows 10 64 bit
Hopefully I can explain this simply
I am building a tool for our general IT usage. One of the ideas I am perusing is having a richtextbox that reports information. When you select a user from a combobox, it runs the function to write a report on the user and it prints in a report box.
That part is easy.
If you make changes to the user, I wanted a second richtextbox to get a report that showed the same report, but with the changes made, that way the original report and the updated report are next to each other in separate richtextboxes.
In the Function Write-Report, I pass the user information in, and then things like this happen …
## Selected AD Name
$rtbReport.SelectionFont = $ReportFonts.SubTitleFont
$rtbReport.SelectionColor = $ReportFonts.SubTitleColor
$rtbReport.AppendText($SelectedUser.Name)
$rtbReport.AppendText("`n")
I create different font styles for different lines, and then put the name in the box.
So here is the problem.
I don’t want to have two reports, one with $rtbReport being written too, and another that writes the same stuff to $rtbReportUpdate.
I can't seem to figure out a way to create the function Write-Report, so that I can choose which richtextbox to use.
Theoretically it would be something like Write-Report -ADSelectedUser $selecteduser -Report rtbReport (or rtbReportUpdate)
Perhaps there is a better way to do this, or I am just spinning my wheels thinking there is a way to do this
Anyone with a suggestion?
Output to Multiple RichTextBoxes
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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Output to Multiple RichTextBoxes
You will need to build the logic to compare original vs updated line by line in order to identify the difference.
A good start would be to use the Compare-Object that can identify difference. You will need to be creative and create the PSObject to compare against line by line.
Use the following command and look at the examples:
Get-Help Compare-Object -ShowWindow
Or,
Get-Help Compare-Object -Examples
A good start would be to use the Compare-Object that can identify difference. You will need to be creative and create the PSObject to compare against line by line.
Use the following command and look at the examples:
Get-Help Compare-Object -ShowWindow
Or,
Get-Help Compare-Object -Examples
Re: Output to Multiple RichTextBoxes
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Output to Multiple RichTextBoxes
Just pass the control to the function.
Code: Select all
function Write-Report{
Param(
$RtbControl
)
$RtbControl.SelectionFont = $ReportFonts.SubTitleFont
$RtbControl.SelectionColor = $ReportFonts.SubTitleColor
$RtbControl.AppendText($SelectedUser.Name)
$RtbControl.AppendText("`n")
}
Write-Report -RtbControl $rtbReport1
Write-Report -RtbControl $rtbReport2
- purchasingADM
- Posts: 2
- Last visit: Mon Jan 20, 2020 4:59 pm
Re: Output to Multiple RichTextBoxes
The first thing I tried was passing it into the function as a parameter, but it didn't work. I tried it again today on a smaller scale test form and it did work.
I think what I did the first time was just copy a template parameter that I keep for using over and over. The template parameter though has [string]$variable, and I didn't notice it. That's probably why it failed. Thanks. I need to use this board more often.
I think what I did the first time was just copy a template parameter that I keep for using over and over. The template parameter though has [string]$variable, and I didn't notice it. That's probably why it failed. Thanks. I need to use this board more often.
Re: Output to Multiple RichTextBoxes
The default parameter is [object]. Any argument passed to [object] will not be converted. Any other type will cause an attempt to convert to that type. Using [string] will convert the argument to a string if possible.
If you want to type check a control then use the full base type or the actual control type.
[System.Windows.Forms.Control] or [System.Windows.Forms.RichTextBox]
The default or [object] will work. Internal utility functions do not have to be strongly typed. In an external function library then we may want to do specific type declaration.
If you want to type check a control then use the full base type or the actual control type.
[System.Windows.Forms.Control] or [System.Windows.Forms.RichTextBox]
The default or [object] will work. Internal utility functions do not have to be strongly typed. In an external function library then we may want to do specific type declaration.
Code: Select all
function DoSomething{
param (
[System.Windows.Forms.RichTextBox]$rtb
)
}