Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

Quick Fix: How to make a Powershell textbox read only

25 November,2019 by Tom Collins

Question: I'm in the process of creating a Powershell form . As part of the Powershell form there are various objects - such as textbox , labels, buttons. 

As part of the programming logic - I'd like to manage the read  or read only - of the textbox. What is the flag to enable\disable the edit of a textbox?

Answer: For a Powershell forms where you're using these assembly libraries and instantiating the form , there are flags you can use on the different objects to control their behaviour

Add-Type -assembly System.Windows.Forms

New-Object System.Windows.Forms.Form


For example - if we had a Powershell  code snippet , which adds a textbox to a form referenced as $main_form , we could use the Enabled flag. In the example below we are making the form textbox object as read-only . 

$CompNameTextBox = New-Object System.Windows.Forms.TextBox
$CompNameTextBox.Location = '150,180'
$CompNameTextBox.Size = '280,150'
$CompNameTextBox.Height = 70


Progressing further with this concept - it is possible to manipulate the object state - by enabling the TextBox. 

If you are using this Powershell form don't fall into the trap of relying on these properties to enforce data integrity. Be clear on where to maintain data integrity rules?

Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on Quick Fix: How to make a Powershell textbox read only | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer