在 OpenFileDialog 中选择文件后,RichTextBox 不可编辑

问题描述 投票:0回答:1

选择输入文件后,我正在用文件路径填充两个文本字段。我希望文本字段仍然可编辑,以便可以更改输出文件的名称,例如如果该文件已经存在。在选择文件之前,文本字段是可写的,但之后就不再可写了。我检查了 ReadOnly 属性,但它始终设置为 false。 当我单击其他任何内容时都会发生这种行为,因此我无法想象代码的另一部分会干扰文本框。

普通的 TextBox 不会出现这种情况,但它们很难看:)

我的部分代码:

# 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)

编辑:这似乎仅在从 psIDE 启动脚本时才会发生。从 VSCode 运行脚本时没有任何问题。

powershell
1个回答
0
投票

© www.soinside.com 2019 - 2024. All rights reserved.