我有一个小工具窗口,通常有FormBorderStyle到FixedDialog,没有标题文本,也没有控制框,所以它看起来像一个带有凸起的3d效果的无边框形式。
当用户将鼠标移到工具窗口上时,它会从无边框的FixedDialog模式更改为带有标题文本和控制框的SizableToolWindow。
结果是客户区移动。
以下代码有效,但我不想硬编码顶部/左侧delta,我认为它根据用户的主题/用户界面而有所不同
void Reposition()
{
var topDelta = 12; // this number is wrong, i have not found the right number for aero yet
var leftDelta = 3;
if (this.Bounds.Contains(MousePosition))
{
if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.SizableToolWindow)
{
this.Location = new Point(this.Location.X - leftDelta, this.Location.Y - topDelta);
this.ControlBox = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
}
}
else
{
if (this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.SizableToolWindow)
{
this.Location = new Point(this.Location.X + leftDelta, this.Location.Y + topDelta);
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
}
}
}