我正在创建一个winforms应用程序,在这个应用程序中,我会时不时地收到一些消息或事件的通知。我期望的通知样式与Gtalk类似,如果用户发送消息,它会在屏幕右下角显示一个通知,如果同时有来自另一个用户的消息,则会在前面的通知窗口上方显示一个新的通知窗口。新窗口不会重叠或遮挡旧窗口。
到目前为止,我几乎没有什么成就。
在屏幕右下角获取窗口,使用构造函数中的代码并不是一项很大的任务
Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(workingArea.Right - Size.Width, workingArea.Bottom - Size.Height);但是现在,在屏幕右下角打开名为“”的表单之后。当一个新的通知出现时,它只是与以前的表单重叠。有什么我能做的吗。我错过了什么很明显的东西吗?
发布于 2014-04-23 12:55:34
--这是带有按钮的父窗体,它创建一个新的通知表单:
public partial class Parent_Form : Form
{
public static List<Form> activeNotifications = new List<Form>();
public Parent_Form()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Notification notification = new Notification();
activeNotifications.Add(notification);
notification.Show();
}
public static void SortNotifications()
{
int additionalHeight = 0;
foreach (Form notification in activeNotifications)
{
notification.Location = new Point(0, (0 + additionalHeight));
additionalHeight += notification.Height;
}
}
public static Point GetLocation()
{
int height = 0;
foreach (Form notification in Parent_Form.activeNotifications) { height += notification.Height; }
return new Point(0, height);
}
}父窗体包含一个button1,用于创建新的通知。
这是通知表单示例:
public partial class Notification : Form
{
public Notification()
{
InitializeComponent();
this.Location = Parent_Form.GetLocation();
this.FormClosing += Notification_FormClosing;
}
private void button1_Click(object sender, EventArgs e) { this.Close(); }
private void Notification_FormClosing(object sender, FormClosingEventArgs e)
{
Parent_Form.activeNotifications.Remove(this);
Parent_Form.SortNotifications();
}
}通知仅包括用于关闭通知表单的button1。确保通知表单使用StartPosition“手册”。
https://stackoverflow.com/questions/23216511
复制相似问题