那里的人都知道如何使您的.net Windows窗体应用程序像Winamp一样具有粘性/ liveness ,从而使其贴紧屏幕的边缘吗?
目标框架将是使用VS08用C#编写的.NET 2.0 Windows窗体。我希望将此功能添加到自定义用户控件中,但是我认为,为应用程序及其主要形式进行描述会令更多的人受益。
谢谢你。
最佳答案
这工作得很好,可以在多个监视器上工作,观察任务栏:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private const int SnapDist = 100;
private bool DoSnap(int pos, int edge) {
int delta = pos - edge;
return delta > 0 && delta <= SnapDist;
}
protected override void OnResizeEnd(EventArgs e) {
base.OnResizeEnd(e);
Screen scn = Screen.FromPoint(this.Location);
if (DoSnap(this.Left, scn.WorkingArea.Left)) this.Left= scn.WorkingArea.Left;
if (DoSnap(this.Top, scn.WorkingArea.Top)) this.Top = scn.WorkingArea.Top;
if (DoSnap(scn.WorkingArea.Right, this.Right)) this.Left = scn.WorkingArea.Right - this.Width;
if (DoSnap(scn.WorkingArea.Bottom, this.Bottom)) this.Top = scn.WorkingArea.Bottom - this.Height;
}
}