[英]Select all text in textbox with autocomplete (C# winforms)
我創建了具有自動完成功能的文本框,但是遇到以下問題。 每當我按Ctrl + A選擇文本框中的所有文本時,該文本就會消失。
這是我的文本框源代碼:
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.AutoCompleteCustomSource.AddRange(new string[] {
"hello",
"test",
"ahha",
"haha"});
this.textBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.textBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
this.textBox1.Location = new System.Drawing.Point(13, 13);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
我希望文本突出顯示而不是消失。 提前致謝。
如果進行此更改,則它似乎可以工作:
this.textBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
如果添加以下代碼,則行為停止:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.A))
{
SelectAll();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
但是我仍然不確定為什么自動完成模式下的附加功能會在不覆蓋Ctrl + A的情況下刪除文本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.