I’m filling two textfields with filepaths after I chose an input-file. I want the textfield to still be editable, so that the name of the ouput file can be changed, e.g. if the file already exists. The textfields are writable before a file is chosen, but not anymore after that. I checked the ReadOnly property, but it’s set to false at all times.
The behavior happens when I click nothing else, so I can’t imagine another part of the code interferes with the TextBox.
This doesn’t occur with a normal TextBox, but those are ugly 🙂
Part of my code:
# Create a Select Input TextBox
$SelectInputTextField = New-Object System.Windows.Forms.RichTextBox
$SelectInputTextField.Location = New-Object System.Drawing.Point([int]($spacer*2+$commonElementWidth), $spacer)
$SelectInputTextField.AutoSize = $false
$SelectInputTextField.Size = New-Object System.Drawing.Size($widerElementWidth, $commonElementHeight)
$SelectInputTextField.BackColor = "#FFFFFF"
$SelectInputTextField.Font = New-Object System.Drawing.Font("Arial", 14)
$SelectInputTextField.WordWrap = $false
$SelectInputTextField.ReadOnly = $false
$form.Controls.Add($SelectInputTextField)
# Create a Select Input Button
$SelectInputButton = New-Object System.Windows.Forms.Button
$SelectInputButton.Location = New-Object System.Drawing.Point([int]($spacer*3+$commonElementWidth+$widerElementWidth), $spacer)
$SelectInputButton.Size = New-Object System.Drawing.Size($commonElementWidth, $commonElementHeight)
$SelectInputButton.Text = "Open"
$SelectInputButton.Add_Click({
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Title = "Select Input File"
$openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
$openFileDialog.InitialDirectory = $PSScriptRoot
if ($openFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$SelectInputTextField.Text = $openFileDialog.FileName
$outputFilePath = [System.IO.Path]::GetDirectoryName($openFileDialog.FileName) + "SQL-Code.txt"
$SelectOutputTextField.Text = $outputFilePath
$SelectInputTextField.Select($SelectInputTextField.Text.Length, 0)
$SelectInputTextField.ScrollToCaret()
$SelectInputTextField.ReadOnly = $false
$SelectOutputTextField.Select($SelectOutputTextField.Text.Length, 0)
$SelectOutputTextField.ScrollToCaret()
$SelectOutputTextField.ReadOnly = $false
}
})
$form.Controls.Add($SelectInputButton)