当鼠标移动到滚动条时触发了MouseLeave事件,期待效果为:当鼠标离开CheckedListBox控件区域时触发MouseLeave事件。
最终采用方法:当鼠标进入父控件工作区时,隐藏CheckedListBox控件
相关参考链接:http://social.msdn.microsoft.com/Forums/en/winforms/thread/d13e98e5-c2be-4fbe-b392-8074ac0cb926
获取控件相对父窗体的坐标(不知道是否有更简捷的方法,就递归一下了)
private Point CaculateLocation(Control c) { Control cParent = c.Parent; Point pResult = c.Location; if (cParent is Form) { return pResult; } else { Point pParent = CaculateLocation(cParent); return new Point(pResult.X + pParent.X, pResult.Y + pParent.Y); } } |
创建自定义控件时,判断是否处于设计模式
/// <summary>
/// 指示当前控件是否处于设计模式。
/// </summary>
private new bool DesignMode
{
get
{
bool result = false; // return value
Control ctl = this; // checked control for design mode
do
{
ISite site = ctl.Site; // get the site object, which is set by designer
if (site != null)
{
result = site.DesignMode; // check for design mode
if (result) { break; } // if control is in design mode then loop ends
}
} while ((ctl = ctl.Parent) != null); // track the parent control
//
return result;
}
}
参考链接:http://www.cnblogs.com/deerchao/archive/2007/11/06/950675.html
http://www.codeproject.com/Articles/13584/How-to-avoid-WSODs-in-the-Visual-Studio-2005-Desig