/// <summary> /// 显示弹出警告 /// </summary> public void ShowPopupAlert() { if (this.currentStatus == PopupStatus.Appearing) { return; } this.currentStatus = PopupStatus.Appearing; // 设置窗体初始位置 this.Location = InitialPos; // 设置透明变量 double TotalOpacity = 1.00; if (UseTransparency) { TotalOpacity = SpecificOpacity; } if (spreadDirection == Spread.Horizontally) { this.opacityIncrement = TotalOpacity / (PopupSize.Width / slideUpIncrement); } else { this.opacityIncrement = TotalOpacity / (PopupSize.Height / slideUpIncrement); } // 显示窗体避免抢占焦点 ShowWindow(this.Handle, 4); this.Opacity = FadeInOut ? 0 : 1; // 设置初始显示间隔 popupTimer.Interval = 10; popupTimer.Start(); }
// 右键隐藏 private void frmAlarmPopup_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (PopupStatus.Visible == currentStatus) { closeAction = true; isMouseOver = false; popupTimer.Interval = 10; popupTimer.Start(); currentStatus = PopupStatus.Disappearing; } } }
// 弹出Timer protected void PopupTimer_Tick(object sender, EventArgs e) { switch (currentStatus) { case PopupStatus.Appearing: if (spreadDirection == Spread.Vertically) { #region 垂直显示 if (this.Location.Y <= primaryScreen.WorkingArea.Height + primaryScreen.WorkingArea.Y - PopupSize.Height) { popupTimer.Stop(); currentStatus = PopupStatus.Visible; this.Location = new Point( InitialPos.X, primaryScreen.WorkingArea.Height + primaryScreen.WorkingArea.Y - PopupSize.Height ); this.Activate(); // 设置显示之后的等待时间间隔 popupTimer.Interval = stayDealy; popupTimer.Start(); } else { this.Location = new Point( InitialPos.X, this.Location.Y - slideUpIncrement ); if (FadeInOut) { this.Opacity = this.Opacity + this.opacityIncrement; } } #endregion } else if (spreadDirection == Spread.Horizontally) { #region 水平显示 if (this.Location.X <= primaryScreen.Bounds.Width - PopupSize.Width) { popupTimer.Stop(); currentStatus = PopupStatus.Visible; this.Location = new Point( primaryScreen.Bounds.Width - PopupSize.Width, initialPos.Y); this.Activate(); // 设置显示之后的等待时间间隔 popupTimer.Interval = stayDealy; popupTimer.Start(); } else { this.Location = new Point(this.Location.X - slideUpIncrement, initialPos.Y); if (FadeInOut) { this.Opacity = this.Opacity + opacityIncrement; } } #endregion } break; case PopupStatus.Visible: popupTimer.Stop(); popupTimer.Interval = 10; if (!isMouseOver) // 如果鼠标没有悬浮 { currentStatus = PopupStatus.Disappearing; } popupTimer.Start(); break; case PopupStatus.Disappearing: if (spreadDirection == Spread.Vertically) { #region 垂直隐藏 if (isMouseOver && !closeAction) { currentStatus = PopupStatus.Appearing; } else { if (this.Location.Y >= primaryScreen.Bounds.Height) { popupTimer.Stop(); currentStatus = PopupStatus.Hidden; //this.Opacity = SpecificOpacity; base.Hide(); } else { this.Location = new Point( InitialPos.X, this.Location.Y + slideDownIncrement ); if (FadeInOut) { this.Opacity = this.Opacity - opacityIncrement; } } } #endregion } else if (spreadDirection == Spread.Horizontally) { #region 水平隐藏 if (isMouseOver && !closeAction) { currentStatus = PopupStatus.Appearing; } else { if (this.Location.X >= primaryScreen.Bounds.Width) { popupTimer.Stop(); currentStatus = PopupStatus.Hidden; //this.Opacity = SpecificOpacity; base.Hide(); } else { this.Location = new Point(this.Location.X + slideDownIncrement, initialPos.Y); if (FadeInOut) { this.Opacity = this.Opacity - opacityIncrement; } } } #endregion } break; } }