想将一个ComboBox变成不可用,设置Enable成False虽然简单,但文字变成灰色了。
不知道怎么能让ComboBox不可用,而现实的文字还是黑色的,就类似TextBox的ReadOnly设置成True那样。

public class m_ComboBox : ComboBox   { 

  private bool _ReadOnle; 

  public m_ComboBox() 
  { 
  this._ReadOnle = true; 
  this.DropDownStyle = ComboBoxStyle.DropDownList; 
  this.TabStop = false; 
  } 

  public bool ReadOnly 
  { 
  get 
  { 
  return this._ReadOnle; 
  } 
  set 
  { 
  this._ReadOnle = value; 
  } 
  } 

  protected override void WndProc(ref Message m) 
  { 
  if (this._ReadOnle && (m.Msg == 0xa1 || m.Msg == 0x201 || m.Msg == 0x203)) 
  { 
  return; 
  } 
  base.WndProc(ref m); 
  }  
  }

相关文章:

  • 2021-06-26
  • 2021-10-04
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
猜你喜欢
  • 2022-02-10
  • 2021-07-18
  • 2021-07-26
  • 2021-12-19
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案