【发布时间】:2019-02-19 00:42:19
【问题描述】:
根据另一个论坛,这不是 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)...............
class ComboBoxEx : ComboBox
{
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;
}
}
}
我不知道为什么只有一个客户会发生这种情况。
【问题讨论】:
-
我不知道答案,但您可能应该为此添加一个 windows 窗体标签。可能有助于在那些花更多时间在这些问题上的人面前展示它。
标签: c#