显示在通知区域一个winform [英] Show a winform over the notification area
问题描述
我想只显示系统托盘上面非常右下角一个WinForm,
我该怎么办呢?这里是我的代码:
公共静态无效的通知()
{
矩形workingArea = Screen.PrimaryScreen 。工作区域;
组成FM =新表();
fm.ClientSize =新的大小(200,200);
INT左= workingArea.Width - fm.Width;
INT顶部= workingArea.Height - fm.Height;
fm.Location =新的点(左侧,顶部);
fm.ShowInTaskbar = FALSE;
fm.ShowIcon = FALSE;
fm.MinimizeBox = FALSE;
fm.MaximizeBox = FALSE;
fm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
fm.Text =测试;
fm.TopMost = TRUE;
fm.Show();
}
我只是尝试这样做,它工作对我来说(注意:此代码必须出现的之后的形式被显示的第一次 - 例如,你可以把它放在窗体的加载
事件处理程序,或者干脆将其包含到显示
)的调用之后:
矩形workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
INT左= workingArea.Width - this.Width;
INT顶部= workingArea.Height - this.Height;
this.Location =新的点(左侧,顶部);
是否使用 WorkingArea
或边界
取决于你的意思是过度的内容:如果你的意思是前面,然后用边界
,因为它包括覆盖整个屏幕(包括由系统托盘占据的空间)的面积;如果你的意思是上面,然后用 WorkingArea
,它仅仅包括用户的桌面。
也让我澄清的是,你希望你的实际的格式的显示那里,对不对?如果你想在通知区域的图标,这就是在 NotifyIcon的
组件是。
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();
}
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.
这篇关于显示在通知区域一个winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!