0
我有一个自定义的控制和我画的一些内容是这样的:为什么不重绘用户控件?
public class TextItem
{
public Font Font { get; set; }
}
public TaskBox()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
this.items = new List<TextItem>();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
foreach (TextItem item in items)
{
if (item.Bounds.Contains(e.Location))
{
item.ForeColor = Color.Red;
Cursor.Current = Cursors.Hand;
}
else
{
item.ForeColor = Color.Black;
Cursor.Current = Cursors.Default;
}
}
}
光标也随之改变,但文本不变色。我错过了一些初始化?
你没有告诉它使用新颜色重绘 – Plutonix 2014-10-19 12:55:17
这实际上是答案。该控件必须失效。 – 2014-10-19 13:02:06