private void button26_Click(object sender, EventArgs e)
{
listBox1.Items.Add("万万2邻期和尾");
listBox1.Items.Add("万万3邻期和尾");
..
..
.. //加了很多项 while(...) //轮询,如果listBox1每一项都自绘之后,就执行里面的代码
{
textBox1.Text = "熊俊";
}
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// listBox1自绘
}
请问,上面的代码, listBox1添加项,会导致自绘,如何轮询,当listBox1每一项都自绘了之后,就执行textBox1.Text = "熊俊";
{
listBox1.Items.Add("万万2邻期和尾");
listBox1.Items.Add("万万3邻期和尾");
..
..
.. //加了很多项 while(...) //轮询,如果listBox1每一项都自绘之后,就执行里面的代码
{
textBox1.Text = "熊俊";
}
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// listBox1自绘
}
请问,上面的代码, listBox1添加项,会导致自绘,如何轮询,当listBox1每一项都自绘了之后,就执行textBox1.Text = "熊俊";
例如你的代码:
listBox1.BeginUpdate();
listBox1.Items.Add("万万2邻期和尾");
listBox1.Items.Add("万万3邻期和尾");
..
..
.. //加了很多项
listBox1.EndUpdate();
Application.DoEvents();//此时界面立刻显示所有添加的内容。
textBox1.Text = "熊俊";//自绘之后,就执行里面的代码
添加一个属性或者方法来接受item,并且在这个属性或方法在add的时候,触发一个event,这个event在外面执行自绘这样说
新建一个mylistview控件,继承自listview。
增加一个属性items{get;set}
在set的时候,判断item的数量是增加还是减少,反正就是item变化了,如果变化了数量,那么就触发一个自定义的event,这样就达到了每次新增或者减少item的时候,event会自动触发自绘。
或者增加一个方法,add,用于新增item。在每次调用这个item的时候,方法中就触发event自绘。
listBox1.BeginUpdate() 基本没用, Add 不立即执行,我估计它只是发出了要重绘的消息给 ListBox ,想要立即效果就在所有的添加完了后 Application.DoEvents() ,把积压的重绘消息处理掉。
还有会不会有这种可能,Application.DoEvents()自绘还没完成,textBox1.Text = "熊俊";就执行了?
“这样写法它们在同一个线程里处理的”..........这句话,是不是MSDN的意思
private void button26_Click(object sender, EventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
listBox1.Items.Add("万万2邻期和尾");
Application.DoEvents();
textBox1.Text = "熊俊";
}private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// listBox1自绘
}
你在 textBox1.Text = "熊俊"; 和 listBox1_DrawItem 方法里各设置一个断点,你看看哪个断点先到