在通知区域显示 winform
我想在系统托盘上方的右下角显示一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚尝试过这个,它对我有用(注意:此代码必须出现在表单首次显示之后 - 例如,您可以将其放入表单的
Load
事件处理程序,或者只是在调用Show
之后将其包含在内):是否使用
WorkingArea
或Bounds
> 取决于“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 toShow
):Whether to use
WorkingArea
orBounds
depends on what you mean by "over": if you mean "in front of," then useBounds
, as it includes the area covering the entire screen (including that space occupied by the system tray); if you mean "above," then useWorkingArea
, 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.您忘记了这一点:
接下来您要做的就是将任务栏放在屏幕的左侧,并在视频 DPI 设置为不同值(例如 125)的计算机上运行代码。您只能在其 Load 事件中准确定位表单。不要设置客户端大小。
You forgot this one:
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.
如果要将表单放置在任务栏上方/前面:
将表单 TopMost 属性设置为 true。您可以使用 Screen.PrimaryScreen.Bounds 获取屏幕分辨率,然后适当地设置表单位置。
如果您只想将窗体放置在右下角任务栏上方,则可以执行以下操作:
在窗体设计器中,转到“属性”->“事件”并将“加载”事件添加到窗体中。
添加以下内容:
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: