mardi 6 décembre 2016

grey out a textbox until enabled by checkbox

im creating a script and i want the user to mark certain checkboxes to enable txtboxes. im not managing to make it work. thanks for the help! here is the part of my script with the checkbox and the textbox:

#creating the whole form
 $objForm = New-Object System.Windows.Forms.Form 
 $objForm.Text = "Ofir`s script"
 $objForm.Size = New-Object System.Drawing.Size(480,240) 
 $objForm.StartPosition = "CenterScreen"


 #This creates the TextBox1
 $objTextBox1 = New-Object System.Windows.Forms.TextBox 
 $objTextBox1.Location = New-Object System.Drawing.Size(300,40) 
 $objTextBox1.Size = New-Object System.Drawing.Size(140,150)
 $objTextBox1.TabIndex = 3 
 $objTextBox1.text = Dsp.z
 $objForm.Controls.Add($objTextBox1)

 #This creates a checkbox for textbox1
 $objDsp2Checkbox = New-Object System.Windows.Forms.Checkbox 
 $objDsp2Checkbox.Location = New-Object System.Drawing.Size(280,40) 
 $objDsp2Checkbox.Size = New-Object System.Drawing.Size(150,20)
 $objDsp2Checkbox.TabIndex = 0
 $objForm.Controls.Add($objDsp2Checkbox)

#changing the file name
if ($objDsp2Checkbox.Checked -eq $true)
{
$objTextBox1.Enabled = $true  
}

elseif ($objDsp2Checkbox.Checked -eq $false)
{
$objTextBox1.Enabled = $false
}    


 #makes the form appear on top of the screen
 $objForm.Topmost = $True

 $objForm.Add_Shown({$objForm.Activate()})
 [void] $objForm.ShowDialog()

Aucun commentaire:

Enregistrer un commentaire