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.
Locked
User avatar
ServerStorage
Posts: 6
Joined: Thu Nov 08, 2012 5:40 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
Joined: Wed Dec 03, 2014 2:26 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: 14621
Joined: Tue May 22, 2007 9:57 am
Answers: 3
Has voted: 1 time
Been upvoted: 3 times
Contact:

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Populate a Textbox on GUI startup

Post by davidc »

David
SAPIEN Technologies, Inc.

User avatar
ServerStorage
Posts: 6
Joined: Thu Nov 08, 2012 5:40 am

Re: Populate a Textbox on GUI startup

Post by ServerStorage »

Awesome links from both of you! Thanks!

Locked