Populate a Textbox on GUI startup

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 8 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
ServerStorage
Posts: 6
Last visit: Fri Oct 20, 2017 8:00 am

Populate a Textbox on GUI startup

Post by ServerStorage »

I have download the trial PowerShell Studio 2015 and getting familiar. I have wrote some small PS GUI in the past and new job there is a need for PS GUI's here.
As a start to get used to PS Studio 2015, I am working with creating simple form. First thing I have tried I am stuck on. I want to create a readonly text box and have it populate when the GUI opens. In my example I just want the current domain using Get-ADDomain | %{$_.DNSRoot}.
I can do this with a lable in my "manual typing"s script
PowerShell Code
Double-click the code block to select all.
$LabelDomain1 = New-Object System.Windows.Forms.Label
$LabelDomain1.Location = New-Object System.Drawing.Point(45, 205)
$LabelDomain1.Size = New-Object System.Drawing.Size(400, 310)
$CurrentDomain = Get-ADDomain | %{$_.Name}
$LabelDomain1.Text = $CurrentDomain
$Form1.Controls.Add($LabelDomain1)
When I look at my forms script I see $TextBoxCurrentDomain_TextChanged, I thought by adding
$TextBoxCurrentDomain_TextChanged.Text = $CurrentDomain, but no luck.

Also, is there a link with example GUI's I can look at? The link I was sent by Support was for very basic GUI's and not much help
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Populate a Textbox on GUI startup

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, chrisagardner.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Populate a Textbox on GUI startup

Post by jvierra »

To assign initial values to controls place the assignment code in the form's load event.

I highly recommend reading the following before you try to build forms with PS2015.

https://www.sapien.com/blog/topics/user ... istrators/
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Populate a Textbox on GUI startup

Post by davidc »

David
SAPIEN Technologies, Inc.
User avatar
ServerStorage
Posts: 6
Last visit: Fri Oct 20, 2017 8:00 am

Re: Populate a Textbox on GUI startup

Post by ServerStorage »

Awesome links from both of you! Thanks!
This topic is 8 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