如何让我的 winforms c# 应用程序位于屏幕左侧?
我想要显示一个小标签,这样当我将鼠标光标移动到屏幕的那个区域时,它就会显示在屏幕上。但是,当我最小化它时,它会回到那个位置。
请您参考如下方法:
所以听起来你想让你的表单粘在计算机屏幕的一侧,然后当鼠标悬停时,它会展开或做一些事情。
这是基于 Microsoft here 记录的形状窗口.
以下使用贴在屏幕一侧的矩形。对于我的 MouseHover,我只是再次将表单变大。您可能会展示第二种形式或制作一些动画。
将这些链接到表单的 Load 和 MouseHover 事件。 MouseEnter 可能也会起作用。
private void Form1_Load(object sender, EventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
shape.AddRectangle(new Rectangle(8, 40, 200, 200));
// I just picked a shape. The user will see whatever exists in these pixels of the form.
// After you get it going, make sure that things not on the visible area are disabled.
// A user can't click on them but they could tab to them and hit ENTER.
// Give the user a way to close it other than Alt-F4, stuff like that.
this.Region = new System.Drawing.Region(shape);
this.Top = (Screen.PrimaryScreen.WorkingArea.Height - 160) / 2;
this.Left = Screen.PrimaryScreen.WorkingArea.Left;
}
private void Form1_MouseHover(object sender, EventArgs e)
{
this.Region = new Region(new Rectangle(0, 0, this.Width, this.Height));
}
