📄 eform.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Client.Utils.Win32;
using Imps.Utils;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Xml;
public class EForm : Form
{
private Bitmap _backbuffer_bitmap;
private ElementsManager _dynamicElements;
private ElementsManager _elementmgr;
private bool _inPosChanged;
private EFormStyle _style;
private bool bActived = true;
private IContainer components;
public ToolTip toolTip;
public EForm()
{
this.InitializeComponent();
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
base.SetStyle(0x20000, true);
base.SetStyle(ControlStyles.ResizeRedraw, false);
base.SetStyle(ControlStyles.UserPaint, true);
this._style = new EFormStyle();
this._style.StyleChanged += new EventHandler(this.style_StyleChanged);
this._elementmgr = new ElementsManager(this);
this._dynamicElements = new ElementsManager(this);
base.Disposed += new EventHandler(this.EForm_Disposed);
BossKey.HiddenEvent += new EventHandler(this.BossKey_HiddenEvent);
}
public void AddElement(Element element)
{
element._host = this;
this.ElementMgr.Controls.Add(element);
}
private void BossKey_HiddenEvent(object sender, EventArgs e)
{
this.HandleBossKey();
}
public virtual void ChangeThemeColor(int hue, double sat, double lum)
{
this.Style.ChangeColor(hue, sat, lum);
foreach (Element element in this.ElementMgr.Controls)
{
element._style.ChangeColor(hue, sat, lum);
}
foreach (Element element2 in this.DynamicElementsMgr.Controls)
{
element2._style.ChangeColor(hue, sat, lum);
}
}
public virtual void Clear()
{
this.DynamicElementsMgr.Controls.Clear();
this.ElementMgr.StyleDispose();
}
private void DrawBackground(Graphics g)
{
if (this._style._backgroundTL != null)
{
g.DrawImage(this._style._backgroundTL, 0, 0, this._style._backgroundTL.Width, this._style._backgroundTL.Height);
}
if (this._style._backgroundTR != null)
{
g.DrawImage(this._style._backgroundTR, base.Width - this._style._backgroundTR.Width, 0, this._style._backgroundTR.Width, this._style._backgroundTR.Height);
}
if (this._style._backgroundT != null)
{
this.DrawBackgroundTop(g);
}
if (this._style._backgroundL != null)
{
this.DrawBackgroundLeft(g);
}
if (this._style._backgroundR != null)
{
this.DrawBackgroundRight(g);
}
if (this._style._backgroundC != null)
{
this.DrawBackgroundCenter(g);
}
if (this._style._backgroundBL != null)
{
g.DrawImage(this._style._backgroundBL, 0, base.Height - this._style._backgroundBL.Height, this._style._backgroundBL.Width, this._style._backgroundBL.Height);
}
if (this._style._backgroundBR != null)
{
g.DrawImage(this._style._backgroundBR, base.Width - this._style._backgroundBR.Width, base.Height - this._style._backgroundBR.Height, this._style._backgroundBR.Width, this._style._backgroundBR.Height);
}
if (this._style._backgroundB != null)
{
this.DrawBackgroundBottom(g);
}
if (this.Style._resize != null)
{
this.DrawResize(g, this.Style._resize);
}
}
private void DrawBackgroundBottom(Graphics g)
{
int num = (this.Style._backgroundBL != null) ? this.Style._backgroundBL.Width : 0;
int num2 = (this.Style._backgroundBR != null) ? this.Style._backgroundBR.Width : 0;
int w = (base.Width - num) - num2;
int h = this._style._backgroundB.Height;
int x = num;
int y = base.Height - this._style._backgroundB.Height;
this.DrawStretchBitmap(g, this._style._backgroundB, x, y, w, h);
}
private void DrawBackgroundCenter(Graphics g)
{
int num = (this.Style._backgroundL != null) ? this.Style._backgroundL.Width : 0;
int num2 = (this.Style._backgroundR != null) ? this.Style._backgroundR.Width : 0;
int num3 = (this.Style._backgroundT != null) ? this.Style._backgroundT.Height : 0;
int num4 = (this.Style._backgroundB != null) ? this.Style._backgroundB.Height : 0;
int w = (base.Width - num) - num2;
int h = (base.Height - num3) - num4;
int x = num;
int y = num3;
this.DrawStretchBitmap(g, this._style._backgroundC, x, y, w, h);
}
private void DrawBackgroundLeft(Graphics g)
{
int num = (this.Style._backgroundTL != null) ? this.Style._backgroundTL.Height : 0;
int num2 = (this.Style._backgroundBL != null) ? this.Style._backgroundBL.Height : 0;
int w = this._style._backgroundL.Width;
int h = (base.Height - num) - num2;
int x = 0;
int y = num;
this.DrawStretchBitmap(g, this._style._backgroundL, x, y, w, h);
}
private void DrawBackgroundRight(Graphics g)
{
int num = (this.Style._backgroundTR != null) ? this.Style._backgroundTR.Height : 0;
int num2 = (this.Style._backgroundBR != null) ? this.Style._backgroundBR.Height : 0;
int w = this._style._backgroundR.Width;
int h = (base.Height - num) - num2;
int x = base.Width - this._style._backgroundR.Width;
int y = num;
this.DrawStretchBitmap(g, this._style._backgroundR, x, y, w, h);
}
private void DrawBackgroundTop(Graphics g)
{
int num = (this.Style._backgroundTL != null) ? this.Style._backgroundTL.Width : 0;
int num2 = (this.Style._backgroundTR != null) ? this.Style._backgroundTR.Width : 0;
int w = (base.Width - num) - num2;
int h = this._style._backgroundT.Height;
int x = num;
int y = 0;
this.DrawStretchBitmap(g, this._style._backgroundT, x, y, w, h);
}
private void DrawResize(Graphics g, Bitmap bmp)
{
if (this.Style.TransParentColor != null)
{
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorKey(this.Style.TransParentColor.Color, this.Style.TransParentColor.Color);
g.DrawImage(bmp, new Rectangle(base.Width - bmp.Width, base.Height - bmp.Height, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttr);
}
else
{
g.DrawImage(bmp, new Rectangle(base.Width - bmp.Width, base.Height - bmp.Height, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
}
}
private void DrawStretchBitmap(Graphics g, Bitmap bmp, int x, int y, int w, int h)
{
if ((bmp != null) && ((w > 0) && (h > 0)))
{
Brush brush = new TextureBrush(bmp, WrapMode.Tile, new Rectangle(0, 0, bmp.Width, bmp.Height));
Bitmap image = new Bitmap(w, h);
Graphics.FromImage(image).FillRectangle(brush, 0, 0, w, h);
g.DrawImage(image, x, y);
}
}
private void EForm_Disposed(object sender, EventArgs e)
{
this._style.StyleChanged -= new EventHandler(this.style_StyleChanged);
BossKey.HiddenEvent -= new EventHandler(this.BossKey_HiddenEvent);
}
private void EForm_SizeChanged(object sender, EventArgs e)
{
if (!base.DesignMode)
{
this.BackBufferBitmap = new Bitmap(base.Width, base.Height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(this.BackBufferBitmap);
this.DrawBackground(g);
if (this.Style.TransParentColor != null)
{
this.WndRegion = BitmapToRegion.Convert(this.BackBufferBitmap, this.Style.TransParentColor.Color, TransparencyMode.ColorKeyTransparent, 0, 0);
}
this.ElementMgr.OnSizeChanged(base.Width, base.Height);
this._dynamicElements.OnSizeChanged(base.Width, base.Height);
base.Invalidate();
}
}
protected virtual void HandleBossKey()
{
BossKey.HandleBossKeyEvent(this);
}
private void InitializeComponent()
{
this.components = new Container();
this.toolTip = new ToolTip(this.components);
base.SuspendLayout();
this.set_BackgroundImageLayout(0);
base.ClientSize = new Size(0x124, 0x10a);
this.set_DoubleBuffered(true);
base.Name = "EForm";
base.SizeChanged += new EventHandler(this.EForm_SizeChanged);
base.ResumeLayout(false);
}
protected override void OnActivated(EventArgs e)
{
this.bActived = true;
base.Invalidate();
base.OnActivated(e);
}
protected override void OnDeactivate(EventArgs e)
{
this.bActived = false;
base.Invalidate();
base.OnDeactivate(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.RemoveCaption();
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (!this.ElementMgr.MouseOnElement(new System.Drawing.Point(e.X, e.Y)))
{
base.OnMouseClick(e);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.ElementMgr.OnMouseDown(e);
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.ElementMgr.OnMouseLeave(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0));
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
this.ElementMgr.OnMouseMove(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -