在通知区域显示 winform

发布于 2024-09-17 21:33:53 字数 608 浏览 6 评论 0原文

我想在系统托盘上方的右下角显示一个winform,

我该怎么做?这是我的代码:

public static void Notify()
{        
    Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
    Form fm = new Form();
    fm.ClientSize = new Size(200, 200);
    int left = workingArea.Width - fm.Width;
    int top = workingArea.Height - fm.Height;
    fm.Location = new Point(left, top);
    fm.ShowInTaskbar = false;
    fm.ShowIcon = false;
    fm.MinimizeBox = false;
    fm.MaximizeBox = false;
    fm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    fm.Text = "Test";
    fm.TopMost = true;
    fm.Show();
}

I want to show a winform in the very right down corner just above the system tray,

How do I do that? Here is my code:

public static void Notify()
{        
    Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
    Form fm = new Form();
    fm.ClientSize = new Size(200, 200);
    int left = workingArea.Width - fm.Width;
    int top = workingArea.Height - fm.Height;
    fm.Location = new Point(left, top);
    fm.ShowInTaskbar = false;
    fm.ShowIcon = false;
    fm.MinimizeBox = false;
    fm.MaximizeBox = false;
    fm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    fm.Text = "Test";
    fm.TopMost = true;
    fm.Show();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话难免假 2024-09-24 21:33:53

我刚刚尝试过这个,它对我有用(注意:此代码必须出现在表单首次显示之后 - 例如,您可以将其放入表单的 Load 事件处理程序,或者只是在调用 Show 之后将其包含在内):

Rectangle workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
int left = workingArea.Width - this.Width;
int top = workingArea.Height - this.Height;

this.Location = new Point(left, top);

是否使用 WorkingAreaBounds > 取决于“over”的含义:如果您的意思是“在前面”,则使用 Bounds,因为它包括覆盖整个屏幕的区域(包括系统托盘占用的空间) ;如果您的意思是“上面”,则使用 WorkingArea,它只包括用户的桌面。

另外让我澄清一下,您希望实际的表单显示在下面,对吧?如果您想要在通知区域中显示图标,则可以使用 NotifyIcon 组件是用于。

I just tried this and it worked for me (note: this code must appear after the form has been displayed for the first time -- for example, you can put it in the form's Load event handler, or simply include it after any call to Show):

Rectangle workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
int left = workingArea.Width - this.Width;
int top = workingArea.Height - this.Height;

this.Location = new Point(left, top);

Whether to use WorkingArea or Bounds depends on what you mean by "over": if you mean "in front of," then use Bounds, as it includes the area covering the entire screen (including that space occupied by the system tray); if you mean "above," then use WorkingArea, which just includes the user's desktop.

Also let me just clarify that you want your actual form displayed down there, right? If you wanted an icon in the notification area, that's what the NotifyIcon component is for.

二智少女 2024-09-24 21:33:53

您忘记了这一点:

        fm.StartPosition = FormStartPosition.Manual;

接下来您要做的就是将任务栏放在屏幕的左侧,并在视频 DPI 设置为不同值(例如 125)的计算机上运行代码。您只能在其 Load 事件中准确定位表单。不要设置客户端大小。

You forgot this one:

        fm.StartPosition = FormStartPosition.Manual;

What you'll have to work on next is putting the taskbar at, say, the left side of the screen and running the code on a machine that has the video DPI setting at a different value (like 125). You can only position the form accurately in its Load event. Don't set the client size.

满天都是小星星 2024-09-24 21:33:53

如果要将表单放置在任务栏上方/前面:

将表单 TopMost 属性设置为 true。您可以使用 Screen.PrimaryScreen.Bounds 获取屏幕分辨率,然后适当地设置表单位置。


如果您只想将窗体放置在右下角任务栏上方,则可以执行以下操作:

在窗体设计器中,转到“属性”->“事件”并将“加载”事件添加到窗体中。

添加以下内容:

private void Form1_Load(object sender, EventArgs e)
{
    this.StartPosition = FormStartPosition.Manual;
    int x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
    int y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
    this.Bounds = new Rectangle(x, y, this.Width, this.Height);
}

If you wanted to position the form over/infront of the taskbar:

Set the forms TopMost property to true. You can use Screen.PrimaryScreen.Bounds to get the screen resolution then set your forms position appropriately.


If you just want to position the form just above the taskbar in the bottom right then you can do as follows:

In the form designer, goto Properties->Events and add the Load event to your form.

Add the following:

private void Form1_Load(object sender, EventArgs e)
{
    this.StartPosition = FormStartPosition.Manual;
    int x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
    int y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
    this.Bounds = new Rectangle(x, y, this.Width, this.Height);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文