下拉框ComboBox的文本不允許更改的方法

 利用KeyPress事件

private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  {e.Handled=true;
  }

或者定義類型爲:數值或空格標點等

private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  {
   char c = e.KeyChar;
   e.Handled = !(char.IsNumber(c) || char.IsWhiteSpace(c) ||
    char.IsControl(c) || char.IsPunctuation(c));
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章