📄 wndlessfolder.cs
字号:
namespace Imps.Client.Pc.WndlessControls
{
using Imps.Client.Pc;
using Imps.Client.Utils;
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
public class WndlessFolder : WndlessControl
{
private Color _clrFolder;
private bool _hoverHor;
private bool _hoverVer;
private Image _img;
private FolderState _state;
private Size _triangleSize;
public WndlessFolder()
{
try
{
Assembly asm = Assembly.GetAssembly(typeof(WndlessFolder));
this.FolderImage = ResourceHelper.GetResImage(asm, "Imps.Client.Pc.Resource.FolderBg.png");
MiscStyle.Instance.StyleChanged += new EventHandler(this.Instance_StyleChanged);
}
catch
{
}
}
public override void Dispose()
{
base.Dispose();
MiscStyle.Instance.StyleChanged -= new EventHandler(this.Instance_StyleChanged);
}
private void Instance_StyleChanged(object sender, EventArgs e)
{
Image folderBg = MiscStyle.Instance.FolderBg;
if (folderBg == null)
{
folderBg = this._img;
}
if (folderBg != null)
{
base.Size = folderBg.Size;
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
System.Drawing.Point pt = e.get_Location();
Rectangle bounds = base.Bounds;
bounds.Height /= 2;
if (bounds.Contains(pt))
{
this._state ^= FolderState.Down;
base.Invalidate();
}
else
{
bounds.Offset(0, bounds.Height);
if (bounds.Contains(pt))
{
this._state ^= FolderState.Right;
base.Invalidate();
}
}
base.OnMouseClick(e);
}
}
protected override void OnMouseLeave(EventArgs e)
{
this.SetHoverState(false, false);
}
protected override void OnMouseMove(MouseEventArgs e)
{
System.Drawing.Point pt = e.get_Location();
Rectangle bounds = base.Bounds;
bounds.Height /= 2;
bool hoverVer = bounds.Contains(pt);
bounds.Offset(0, bounds.Height);
bool hoverHor = !hoverVer && bounds.Contains(pt);
this.SetHoverState(hoverVer, hoverHor);
}
protected override void OnPaint(PaintEventArgs e)
{
Image folderBg = MiscStyle.Instance.FolderBg;
if (folderBg == null)
{
folderBg = this._img;
}
if (folderBg != null)
{
e.Graphics.DrawImage(folderBg, base.Bounds, 0, 0, folderBg.Width, folderBg.Height, GraphicsUnit.Pixel);
}
Direction direct = ((this._state & FolderState.Right) == FolderState.Right) ? Direction.Right : Direction.Left;
Direction direction2 = ((this._state & FolderState.Down) == FolderState.Down) ? Direction.Down : Direction.Up;
Rectangle rect = this.HorizontalTriangleRect;
if (this._hoverHor)
{
rect.Offset(0, -1);
}
Imps.Client.Utils.DrawHelper.DrawTriangle(e.Graphics, rect, direct, this.FolderColor);
rect = this.VerticalTriangleRect;
if (this._hoverVer)
{
rect.Offset(0, -1);
}
Imps.Client.Utils.DrawHelper.DrawTriangle(e.Graphics, rect, direction2, this.FolderColor);
}
private void SetHoverState(bool hoverVer, bool hoverHor)
{
if ((hoverHor != this._hoverHor) || (hoverVer != this._hoverVer))
{
this._hoverVer = hoverVer;
this._hoverHor = hoverHor;
base.Invalidate();
}
}
public Color FolderColor
{
get
{
return this._clrFolder;
}
set
{
this._clrFolder = value;
}
}
public Image FolderImage
{
get
{
return this._img;
}
set
{
if (this._img != value)
{
this._img = value;
base.Size = this._img.Size;
}
}
}
public Rectangle HorizontalTriangleRect
{
get
{
int x = (((base.Left + base.Right) - this.TriangleSize.Width) / 2) + 1;
return new Rectangle(x, ((base.Top + base.Bottom) + ((base.Bottom - this.TriangleSize.Width) * 2)) / 4, this.TriangleSize.Height, this.TriangleSize.Width);
}
}
public FolderState State
{
get
{
return this._state;
}
set
{
this._state = value;
}
}
public Size TriangleSize
{
get
{
return this._triangleSize;
}
set
{
this._triangleSize = value;
}
}
public Rectangle VerticalTriangleRect
{
get
{
int x = (((base.Left + base.Right) - this.TriangleSize.Width) / 2) + 1;
return new Rectangle(x, ((base.Top + base.Bottom) + ((base.Top - this.TriangleSize.Height) * 2)) / 4, this.TriangleSize.Width, this.TriangleSize.Height);
}
}
public enum FolderState
{
Down = 2,
Right = 1
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -