2009-07-29 49 views
1

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/e04e9308-bff5-4fbb-8cd6-0b2cd957aa68/?prof=required改變組合框的原始行爲 - 組合框在突出顯示時改變其大小

根據另一個論壇,這不是一個MS的問題,因爲他們說是CombBox的「原生」的行爲。

如果ComboBox具有DropDownStyle = DropDown並更改其大小,則文本將高亮顯示,如果窗體中有許多ComboBox似乎選擇了該控件。

爲了避免這個問題,一個人建議覆蓋WndProc。 寄託都工作正常,直到僅有一個客戶端報告了一個未處理的錯誤

System.ArgumentOutOfRangeException: InvalidArgument=Value of '-2136611475' is not valid for 'start'. 
Parameter name: start 
    at System.Windows.Forms.ComboBox.Select(Int32 start, Int32 length) 
    at System.Windows.Forms.ComboBox.set_SelectionLength(Int32 value)............... 

類ComboBoxEx:組合框 { const int的WM_SIZE = 5;

protected override void WndProc(ref Message m) 
{ 
    switch(m.Msg) 
    { 
     case WM_SIZE: 
      string text = Text; 
      base.WndProc(ref m); 

      //The exception strangely is trown here 
      SelectionLength = 0; 

      Text = text; 
      break; 

     default: 
      base.WndProc(ref m); 
      break; 
    } 
} 

}

我不知道爲什麼這僅僅是一個客戶端發生的原因。任何想法? 謝謝,luisnike19

+0

我不不知道答案,但您應該爲此添加一個窗體窗體標籤。可以幫助在面對這些問題花更多時間的人面前。 – Mallioch 2009-07-29 16:27:51

回答

0

我想不出會導致這種情況,但我有一個解決方法。我在反射檢查set_SelectionLength(的Int32值):

this.Select(this.SelectionStart, value); 

我不無爲什麼SelectionStart突然變成負數,但你可以減少中間商,瓶坯此變通辦法代碼:

this.Select(0, 0); 
+0

感謝HuBeza,這個解決方法工作得很好,很簡單,這是個好主意。 – Luisnike19 2009-08-05 13:27:37