public void AnimatedExit() { // 注销上一实例 _PrevInstance = null; _ExitTimer.Stop(); _Up = false; _MoveTimer.Start(); }
/// <summary> /// 构造一个提示框 /// </summary> /// <param name="title">提示框标题</param> /// <param name="message">提示框文本</param> /// <param name="time">自动退出时间</param> public CornerTips(string title, string message, int time) { // Form 的基本参数 this.ShowInTaskbar = false; this.TopMost = true; this.StartPosition = FormStartPosition.Manual; // 强制退出上一实例 if (_PrevInstance != null) { _PrevInstance.AnimatedExit(); _PrevInstance = null; } // 注册当前为上一实例 _PrevInstance = this; // 增加关闭控件 _CloseButton.Size = Resource.ts_close.Size; _CloseButton.Location = new Point(186, 1); _CloseButton.Image = Resource.ts_close; _CloseButton.Click += new EventHandler(Close_Clicked); _CloseButton.MouseEnter += new EventHandler(CloseButton_MouseEnter); _CloseButton.MouseLeave += new EventHandler(CloseButton_MouseLeave); // Controls.Add(_CloseButton); this.label1 = new System.Windows.Forms.Label(); this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(53, 89); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(191, 12); this.label1.TabIndex = 0; this.label1.Text = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"; Controls.Add(label1); // 显示时间 _ShowTime = time; // 画图并设窗体图像 //Graphics g = Graphics.FromImage(_Bmp); //Rectangle rect = new Rectangle(17, 5, 160, 22); //StringFormat sf = new StringFormat(); //sf.Alignment = StringAlignment.Center; //sf.LineAlignment = StringAlignment.Center; //g.DrawString(title, new Font(TipFont, FontStyle.Bold), new SolidBrush(Color.Black), rect, sf); //rect = new Rectangle(67, 68, 165, 75); //sf.Alignment = StringAlignment.Near; //sf.LineAlignment = StringAlignment.Near; //g.DrawString(message, TipFont, new SolidBrush(Color.Black), rect, sf); //g.DrawImage(_CloseButton.Image, _CloseButton.Left, _CloseButton.Top, _CloseButton.Width, _CloseButton.Height); //this.Width = 400; //this.SetBitmap(_Bmp, 222); // 计算X,Y超始值 Rectangle rt = Screen.PrimaryScreen.Bounds; _TaskHeight = rt.Height - Screen.PrimaryScreen.WorkingArea.Height; this.Location = new Point(rt.Right, rt.Bottom); _X = rt.Right - this.Width; _Y = rt.Bottom; // 上移开坮 _Up = true; _MoveTimer.Interval = 25; _MoveTimer.Tick += new EventHandler(MoveTimer_Tick); _MoveTimer.Start(); }