//当有多个消息的时候,消息框会重叠在一起;多个消息时,需要将消息窗口按一定的规则排列,这里我们设置每个消息窗口间隔一定的距离 public void Show(string message, AlertType type, AlertDuration duration = AlertDuration.Short) { this.duration = duration; // 设置窗口启始位置 this.StartPosition = FormStartPosition.Manual; // 设置程序每个打开的消息窗口的位置,超过10个就不做处理,这个可以根据自己的需求设定 string fname; for (int i = 1; i < 10; i++) { fname = "alert" + i.ToString(); Toast alert = (Toast)Application.OpenForms[fname]; if (alert == null) { this.Name = fname; this.x = Screen.PrimaryScreen.WorkingArea.Width - this.Width; this.y = Screen.PrimaryScreen.WorkingArea.Height - this.Height * i - 5 * i; this.Location = new Point(x, y); break; } } labelContent.Text = message; this.Opacity = 0.0; SetAlertTheme(type); this.Show(); action = AlertFormAction.Start; //启动时钟 timer1.Start(); // 注销鼠标事件 this.MouseLeave += new System.EventHandler(this.AlertMessageForm_MouseLeave); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.AlertMessageForm_MouseMove); }
public Toast(string message, AlertType type, Form form = null, AlertDuration duration = AlertDuration.Short) { InitializeComponent(); Show(message, type, duration); form?.Activate(); }