📄 wndlesscontainerengine.cs
字号:
namespace Imps.Client.Pc.WndlessControls
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
internal class WndlessContainerEngine
{
private WndlessControlCollection _col;
private WndlessControl _downCtrl;
private WndlessControl _hoverCtrl;
private Size _szOld;
public WndlessContainerEngine(WndlessControlCollection col)
{
if (col == null)
{
throw new ArgumentNullException("col");
}
this._col = col;
this.AttachEventHandlers(true);
this._szOld = col.OwnerControl.Size;
}
private void AttachEventHandlers(bool doAttach)
{
if ((this._col != null) && (this._col.OwnerControl != null))
{
if (doAttach)
{
this._col.OwnerControl.Disposed += new EventHandler(this.host_Disposed);
this._col.OwnerControl.SizeChanged += new EventHandler(this.host_SizeChanged);
this._col.OwnerControl.Paint += new PaintEventHandler(this.host_Paint);
this._col.OwnerControl.MouseDown += new MouseEventHandler(this.host_MouseDown);
this._col.OwnerControl.MouseUp += new MouseEventHandler(this.host_MouseUp);
this._col.OwnerControl.add_MouseClick(new MouseEventHandler(this.host_MouseClick));
this._col.OwnerControl.MouseMove += new MouseEventHandler(this.host_MouseMove);
this._col.OwnerControl.MouseLeave += new EventHandler(this.host_MouseLeave);
}
else
{
this._col.OwnerControl.Disposed -= new EventHandler(this.host_Disposed);
this._col.OwnerControl.SizeChanged -= new EventHandler(this.host_SizeChanged);
this._col.OwnerControl.Paint -= new PaintEventHandler(this.host_Paint);
this._col.OwnerControl.MouseDown -= new MouseEventHandler(this.host_MouseDown);
this._col.OwnerControl.MouseUp -= new MouseEventHandler(this.host_MouseUp);
this._col.OwnerControl.remove_MouseClick(new MouseEventHandler(this.host_MouseClick));
this._col.OwnerControl.MouseMove -= new MouseEventHandler(this.host_MouseMove);
this._col.OwnerControl.MouseLeave -= new EventHandler(this.host_MouseLeave);
}
}
}
private void host_Disposed(object sender, EventArgs e)
{
this.AttachEventHandlers(false);
using (IEnumerator<WndlessControl> enumerator = this._col.GetEnumerator())
{
while (enumerator.MoveNext())
{
enumerator.get_Current().Dispose();
}
}
this._col.Clear();
this._col = null;
}
private void host_MouseClick(object sender, MouseEventArgs e)
{
using (IEnumerator<WndlessControl> enumerator = this._col.GetEnumerator())
{
while (enumerator.MoveNext())
{
WndlessControl control = enumerator.get_Current();
if ((control.Visible && control.Enabled) && control.InnerHitTest(e.get_Location()))
{
control.InnerDoMouseClick(e);
return;
}
}
}
}
private void host_MouseDown(object sender, MouseEventArgs e)
{
using (IEnumerator<WndlessControl> enumerator = this._col.GetEnumerator())
{
while (enumerator.MoveNext())
{
WndlessControl control = enumerator.get_Current();
if ((control.Visible && control.Enabled) && control.InnerHitTest(e.get_Location()))
{
this.DownControl = control;
return;
}
}
}
this.DownControl = null;
}
private void host_MouseLeave(object sender, EventArgs e)
{
this.HoverControl = null;
}
private void host_MouseMove(object sender, MouseEventArgs e)
{
if (this.DownControl == null)
{
using (IEnumerator<WndlessControl> enumerator = this._col.GetEnumerator())
{
while (enumerator.MoveNext())
{
WndlessControl control = enumerator.get_Current();
if ((control.Visible && control.Enabled) && control.InnerHitTest(e.get_Location()))
{
control.InnerDoMouseMove(e);
if (this.HoverControl != control)
{
this.HoverControl = control;
this._col.OwnerControl.Cursor = control.Cursor;
}
return;
}
}
}
this.HoverControl = null;
this._col.OwnerControl.Cursor = Cursors.Default;
}
}
private void host_MouseUp(object sender, MouseEventArgs e)
{
this.DownControl = null;
}
private void host_Paint(object sender, PaintEventArgs e)
{
int count = this._col.Count;
while (--count >= 0)
{
if (this._col[count].Visible)
{
try
{
this._col[count].InnerDraw(e);
continue;
}
catch (Exception exception)
{
Trace.WriteLine(exception.ToString());
continue;
}
}
}
}
private void host_SizeChanged(object sender, EventArgs e)
{
this._col.SuspendInvalidate();
try
{
using (IEnumerator<WndlessControl> enumerator = this._col.GetEnumerator())
{
while (enumerator.MoveNext())
{
int x;
int width;
int y;
int height;
WndlessControl control = enumerator.get_Current();
if ((control.Anchor & AnchorStyles.Left) == AnchorStyles.None)
{
if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.None)
{
x = control.Left + ((this._col.OwnerControl.Size.Width - this._szOld.Width) / 2);
}
else
{
x = control.Left + (this._col.OwnerControl.Size.Width - this._szOld.Width);
}
width = control.Width;
}
else
{
x = control.Left;
if ((control.Anchor & AnchorStyles.Right) == AnchorStyles.None)
{
width = control.Width;
}
else
{
width = control.Width + (this._col.OwnerControl.Size.Width - this._szOld.Width);
}
}
if ((control.Anchor & AnchorStyles.Top) == AnchorStyles.None)
{
if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.None)
{
y = control.Top + ((this._col.OwnerControl.Size.Height - this._szOld.Height) / 2);
}
else
{
y = control.Top + (this._col.OwnerControl.Size.Height - this._szOld.Height);
}
height = control.Height;
}
else
{
y = control.Top;
if ((control.Anchor & AnchorStyles.Bottom) == AnchorStyles.None)
{
height = control.Height;
}
else
{
height = control.Height + (this._col.OwnerControl.Size.Height - this._szOld.Height);
}
}
control.SetBounds(x, y, width, height, BoundsSpecified.All);
}
}
this._szOld = this._col.OwnerControl.Size;
}
finally
{
this._col.ResumeInvalidate();
}
}
private WndlessControl DownControl
{
get
{
return this._downCtrl;
}
set
{
if (this._downCtrl != null)
{
this._downCtrl.SetIsDown(false);
}
this._downCtrl = value;
if (this._downCtrl != null)
{
this._downCtrl.SetIsDown(true);
}
}
}
private WndlessControl HoverControl
{
get
{
return this._hoverCtrl;
}
set
{
if (this._hoverCtrl != null)
{
this._hoverCtrl.InnerDoMouseLeave(EventArgs.Empty);
this._hoverCtrl.SetIsHover(false);
}
this._hoverCtrl = value;
if (this._hoverCtrl != null)
{
this._hoverCtrl.InnerDoMouseEnter(EventArgs.Empty);
this._hoverCtrl.InnerDoMouseHover(EventArgs.Empty);
this._hoverCtrl.SetIsHover(true);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -