📄 notifywindowbase.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows
{
using Imps.Client.Pc.Controls;
using Imps.Client.Resource;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public abstract class NotifyWindowBase : PopupWindow
{
protected PopupDirection direction;
protected int hideEvents;
protected int incrementHide;
protected int incrementShow;
protected bool isMouseOverPopup;
protected bool keepVisibleOnMouseOver = true;
protected PopupStates popupState;
protected int realHeight = 0x74;
protected int realWidth = 0xc9;
protected bool reShowOnMouseOver = true;
protected int showEvents;
protected Point startPosition;
protected Timer timer = new Timer();
protected int timeToHide = 500;
protected int timeToShow = 500;
protected int timeToStay = 0xbb8;
protected int visibleEvents;
protected Rectangle workAreaRectangle;
public event EventHandler PopupHide;
public NotifyWindowBase()
{
this.timer.Enabled = true;
this.timer.Tick += new EventHandler(this.OnTimer);
base.Icon = ImpsIcons.Logo;
}
protected override void Dispose(bool disposing)
{
if (this.timer != null)
{
this.timer.Tick -= new EventHandler(this.OnTimer);
this.timer.Dispose();
}
this.PopupHide = null;
base.Dispose(disposing);
}
public void Hide()
{
if (this.popupState != PopupStates.Hidden)
{
this.timer.Stop();
this.popupState = PopupStates.Hidden;
if (this.PopupHide != null)
{
this.PopupHide(this, new EventArgs());
}
base.Close();
}
}
public void Notify(Point startPosition, PopupDirection direction)
{
int num;
this.startPosition = startPosition;
this.direction = direction;
this.workAreaRectangle = Screen.GetWorkingArea(this.workAreaRectangle);
this.visibleEvents = this.timeToStay;
if (this.timeToShow > 10)
{
num = Math.Min(this.timeToShow / 10, this.RealHeight);
this.showEvents = this.timeToShow / num;
this.incrementShow = this.RealHeight / num;
}
else
{
this.showEvents = 10;
this.incrementShow = this.RealHeight;
}
if (this.timeToHide > 10)
{
num = Math.Min(this.timeToHide / 10, this.RealHeight);
this.hideEvents = this.timeToHide / num;
this.incrementHide = this.RealHeight / num;
}
else
{
this.hideEvents = 10;
this.incrementHide = this.RealHeight;
}
switch (this.popupState)
{
case PopupStates.Hidden:
base.MoveWindow(startPosition.X, startPosition.Y, this.RealWidth, 0);
base.ShowWindow(false);
this.popupState = PopupStates.Appearing;
this.timer.Interval = this.showEvents;
this.timer.Start();
return;
case PopupStates.Appearing:
this.Refresh();
return;
case PopupStates.Visible:
this.timer.Stop();
this.timer.Interval = this.visibleEvents;
this.timer.Start();
this.Refresh();
return;
case PopupStates.Disappearing:
{
this.timer.Stop();
this.popupState = PopupStates.Visible;
int top = (direction == PopupDirection.Down) ? startPosition.Y : (startPosition.Y - this.RealHeight);
base.MoveWindow(startPosition.X, top, this.RealWidth, this.RealHeight);
this.timer.Interval = this.visibleEvents;
this.timer.Start();
this.Refresh();
return;
}
}
}
protected override void OnMouseEnter(EventArgs ea)
{
base.OnMouseEnter(ea);
this.isMouseOverPopup = true;
}
protected override void OnMouseLeave(EventArgs ea)
{
base.OnMouseLeave(ea);
this.isMouseOverPopup = false;
}
protected void OnTimer(object obj, EventArgs ea)
{
switch (this.popupState)
{
case PopupStates.Appearing:
{
if (base.Height >= this.RealHeight)
{
this.timer.Stop();
base.Height = this.RealHeight;
this.timer.Interval = this.visibleEvents;
this.popupState = PopupStates.Visible;
this.timer.Start();
return;
}
int top = (this.direction == PopupDirection.Down) ? base.Top : (base.Top - this.incrementShow);
base.MoveWindow(base.Left, top, base.Width, base.Height + this.incrementShow);
return;
}
case PopupStates.Visible:
this.timer.Stop();
this.timer.Interval = this.hideEvents;
if ((this.keepVisibleOnMouseOver && !this.isMouseOverPopup) || !this.keepVisibleOnMouseOver)
{
this.popupState = PopupStates.Disappearing;
}
this.timer.Start();
return;
case PopupStates.Disappearing:
if (!this.reShowOnMouseOver || !this.isMouseOverPopup)
{
if (this.direction == PopupDirection.Down)
{
if (base.Height > this.incrementHide)
{
base.MoveWindow(base.Left, base.Top, base.Width, base.Height - this.incrementHide);
return;
}
this.Hide();
}
else if (base.Top < this.startPosition.Y)
{
base.MoveWindow(base.Left, base.Top + this.incrementShow, base.Width, base.Height - this.incrementHide);
}
else
{
this.Hide();
}
return;
}
this.popupState = PopupStates.Appearing;
return;
}
}
public bool KeepVisibleOnMousOver
{
get
{
return this.keepVisibleOnMouseOver;
}
set
{
this.keepVisibleOnMouseOver = value;
}
}
public int RealHeight
{
get
{
return this.realHeight;
}
set
{
this.realHeight = value;
}
}
public int RealWidth
{
get
{
return this.realWidth;
}
set
{
this.realWidth = value;
}
}
public bool ReShowOnMouseOver
{
get
{
return this.reShowOnMouseOver;
}
set
{
this.reShowOnMouseOver = value;
}
}
public PopupStates TaskbarState
{
get
{
return this.popupState;
}
}
public int TimeToHide
{
get
{
return this.timeToHide;
}
set
{
this.timeToHide = value;
}
}
public int TimeToShow
{
get
{
return this.timeToShow;
}
set
{
this.timeToShow = value;
}
}
public int TimeToStay
{
get
{
return this.timeToStay;
}
set
{
this.timeToStay = value;
}
}
public enum PopupStates
{
Hidden,
Appearing,
Visible,
Disappearing
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -