Iak*_*ovl 49 c# string combobox
我在C#中有一个使用a的表单ComboBox.如何防止用户ComboBox在C#中手动输入文本?
this.comboBoxType.Font = new System.Drawing.Font("Arial", 15.75F);
this.comboBoxType.FormattingEnabled = true;
this.comboBoxType.Items.AddRange(new object[] {
"a",
"b",
"c"});
this.comboBoxType.Location = new System.Drawing.Point(742, 364);
this.comboBoxType.Name = "comboBoxType";
this.comboBoxType.Size = new System.Drawing.Size(89, 32);
this.comboBoxType.TabIndex = 57;
Run Code Online (Sandbox Code Playgroud)
我希望ABC成为唯一的选择.
Rei*_*ldo 127
只需将您的组合设置为DropDownList:
this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;
Run Code Online (Sandbox Code Playgroud)
Jus*_*ony 16
我相信你想把DropDownStyle设置为DropDownList.
this.comboBoxType.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以添加e.Handled = trueKeyPress事件:
private void Combo1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)