📄 notifywindow.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows
{
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
public class NotifyWindow : NotifyWindowBase
{
protected Bitmap backgroundImage;
private NotifyWindowContent content;
protected INotifyWindowElement currentElement;
private object[] paramsData;
protected NotifyWindow()
{
}
public NotifyWindow(NotifyWindowContent content)
{
this.SetContent(content);
}
protected void DrawElements(Graphics g)
{
if ((this.content != null) && (this.content.Elements != null))
{
List<INotifyWindowElement>.Enumerator enumerator = this.content.Elements.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
enumerator.get_Current().Draw(g);
}
}
finally
{
enumerator.Dispose();
}
}
}
public void MakeTransparent(Color transparencyColor)
{
if (this.backgroundImage != null)
{
base.Region = BitmapToRegion.Convert(this.backgroundImage, transparencyColor);
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (((this.currentElement != null) && this.currentElement.IsMouseOver) && this.currentElement.Clickable)
{
NotifyWindowEventArgs args = new NotifyWindowEventArgs(this, this.currentElement);
this.currentElement.OnClick(args);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if ((this.content != null) && (this.content.Elements != null))
{
List<INotifyWindowElement>.Enumerator enumerator = this.content.Elements.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
INotifyWindowElement element = enumerator.get_Current();
if (element.IsMouseOver)
{
base.Invalidate(element.Rectangle);
NotifyWindowEventArgs args = new NotifyWindowEventArgs(this, element);
element.OnMouseDown(args);
return;
}
}
}
finally
{
enumerator.Dispose();
}
}
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.Refresh();
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
if ((this.content != null) && (this.content.Elements != null))
{
List<INotifyWindowElement>.Enumerator enumerator = this.content.Elements.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
INotifyWindowElement element = enumerator.get_Current();
if (element.IsMouseOver)
{
NotifyWindowEventArgs args = new NotifyWindowEventArgs(this, element);
element.OnMouseOut(args);
}
}
}
finally
{
enumerator.Dispose();
}
}
this.Refresh();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
bool flag = false;
bool flag2 = false;
if (this.content != null)
{
NotifyWindowEventArgs args;
if (this.content.Elements != null)
{
List<INotifyWindowElement>.Enumerator enumerator = this.content.Elements.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
INotifyWindowElement element = enumerator.get_Current();
if (element.Rectangle.Contains(new Point(e.X, e.Y)))
{
flag2 = true;
if (!element.IsMouseOver)
{
if ((this.currentElement != null) && this.currentElement.IsMouseOver)
{
args = new NotifyWindowEventArgs(this, this.currentElement);
this.currentElement.OnMouseOut(args);
}
args = new NotifyWindowEventArgs(this, element);
element.OnMouseOver(args);
this.currentElement = element;
if (element.Clickable)
{
this.Cursor = Cursors.Hand;
}
flag = true;
}
}
}
}
finally
{
enumerator.Dispose();
}
}
if (!flag2)
{
this.Cursor = Cursors.Default;
if ((this.currentElement != null) && this.currentElement.IsMouseOver)
{
args = new NotifyWindowEventArgs(this, this.currentElement);
this.currentElement.OnMouseOut(args);
flag = true;
}
}
}
if (flag)
{
this.Refresh();
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if ((this.content != null) && (this.content.Elements != null))
{
List<INotifyWindowElement>.Enumerator enumerator = this.content.Elements.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
INotifyWindowElement element = enumerator.get_Current();
if (element.IsMouseOver)
{
base.Invalidate(element.Rectangle);
NotifyWindowEventArgs args = new NotifyWindowEventArgs(this, element);
element.OnMouseUp(args);
return;
}
}
}
finally
{
enumerator.Dispose();
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
this.DrawElements(e.Graphics);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
graphics.PageUnit = GraphicsUnit.Pixel;
Bitmap image = new Bitmap(base.RealWidth, base.RealHeight);
Graphics graphics2 = Graphics.FromImage(image);
if (this.backgroundImage != null)
{
graphics2.DrawImage(this.backgroundImage, 0, 0, this.backgroundImage.Width, this.backgroundImage.Height);
}
graphics.DrawImage(image, 0, 0);
}
protected void SetBackgroundImage(Image image)
{
this.backgroundImage = new Bitmap(image);
base.Width = base.RealWidth = this.backgroundImage.Width;
base.Height = base.RealHeight = this.backgroundImage.Height;
}
protected void SetContent(NotifyWindowContent configuration)
{
this.content = configuration;
if ((this.content != null) && (configuration.BackgroundImage != null))
{
this.SetBackgroundImage(configuration.BackgroundImage);
}
}
public object[] ParamsData
{
get
{
return this.paramsData;
}
set
{
this.paramsData = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -