2009-08-10 58 views

回答

2

我想在代码的一些操作后提出答案。

关键是要检查控制是否聚焦在OnPaint方法并绘制透明或黑色边框:

gxOff.DrawRectangle(new Pen((this.Focused) ? Color.Black : Color.Transparent), rc); 

和OnGotFocus和OnLostFocus事件调用invalidate():

protected override void OnGotFocus(EventArgs 
{ 
    base.OnGotFocus(e); 
    this.Invalidate(); 
} 

protected override void OnLostFocus(EventArgs e) 
{ 
    base.OnLostFocus(e); 
    this.Invalidate(); 
} 

希望它会帮助某人:)

相关问题