如何引发ondraw事件场景:我在窗体中使用带有onDrawItem的自定义组合框。草案就是这样的
protected override void OnDrawItem(DrawItemEventArgs e)
{...
}
Question: How do I make the custom combobox ComboLineStyle redraw 另一个cmbBoxLineColor的selectedindex上的自身已更改。最终,我需要一种方法来重新绘制每个selectedindex上的组合框的所有行。
private void cmbBoxLineColor_SelectedIndexChanged(object sender, EventArgs e)
{
Here I want the custom combobox-ComboLineStyle control to redraw itself
}编辑我需要下拉来再次绘制自己的颜色时,在另一条线颜色组合changes.Color
lineColorSel = cmbBoxLineColor.SelectedValue;
ComboBoxItemLineStyle itemSolid = new ComboBoxItemLineStyle ("Solid Line", lineColorSel); 我的linestylecomboboxitem中的color属性将具有linecolor组合框的selected值。因此,linestyle组合应该刷新/使自身无效,并使用此lineColorSel重新绘制自身。
谢谢你
发布于 2012-06-07 03:43:49
您可以在继承System.Windows.Forms.Control的任何对象上调用Invalidate()以强制其重画
下面是我如何为所选项目进行自定义绘制的示例
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.State == DrawItemState.Selected)
{
...
}
else
{
...
}
//or you could do it like this
//if(e.Index == this.SelectedIndex)
//{
//}
...
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
base.Invalidate();
}https://stackoverflow.com/questions/10920383
复制相似问题