📄 wndlessportrait.cs
字号:
namespace Imps.Client.Pc.WndlessControls
{
using Imps.Client.Pc;
using Imps.Client.Utils;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class WndlessPortrait : WndlessControl
{
private Cursor _curPortrait;
private ToolStripDropDown _dropDown;
private bool _hoverDropDown;
private System.Drawing.Image _image;
private System.Windows.Forms.Padding _padding = new System.Windows.Forms.Padding(4);
private int _shadowDepth;
private int _size = 0x60;
private PortraitStyle _style;
private const int DefaultPadding = 4;
public event EventHandler PortraitClicked;
public WndlessPortrait()
{
this.ShadowDepth = 2;
base.BackColor = Color.FromArgb(0xec, 0xec, 0xec);
base.BorderColor = Color.FromArgb(0xc9, 0xce, 0xd1);
}
private void _dropDown_VisibleChanged(object sender, EventArgs e)
{
this.HoverDropDown = ((ToolStripDropDown) sender).get_Visible();
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (this.ImageRect.Contains(e.get_Location()) && (e.Button == MouseButtons.Left))
{
EventHandler portraitClicked = this.PortraitClicked;
if (portraitClicked != null)
{
portraitClicked(this, EventArgs.Empty);
}
}
else if (this._dropDown != null)
{
Rectangle dropDownRectOuter = this.DropDownRectOuter;
if (dropDownRectOuter.Contains(e.get_Location()))
{
this._dropDown.Show(base.OwnerControl, dropDownRectOuter.Left, dropDownRectOuter.Bottom);
}
}
base.OnMouseClick(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (this.PortraitCursor != null)
{
if (this.ImageRect.Contains(e.get_Location()))
{
base.OwnerControl.Cursor = this.PortraitCursor;
}
else
{
base.OwnerControl.Cursor = Cursors.Default;
}
}
this.HoverDropDown = this.DropDownRectOuter.Contains(e.get_Location());
base.OnMouseMove(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.Portrait != null)
{
Rectangle rect = this.ImageRect;
if (rect.IntersectsWith(e.ClipRectangle))
{
if (base.Enabled)
{
e.Graphics.DrawImage(this.Portrait, rect);
}
else
{
ControlPaint.DrawImageDisabled(e.Graphics, this.Portrait, rect.X, rect.Y, base.BackColor);
}
}
if (this._style != PortraitStyle.Normal)
{
rect = this.DropDownRect;
Rectangle dropDownRectOuter = this.DropDownRectOuter;
Color backColor = base.BackColor;
if (this.HoverDropDown)
{
using (Brush brush = new SolidBrush(Color.LightBlue))
{
e.Graphics.FillRectangle(brush, dropDownRectOuter);
}
}
if (rect.IntersectsWith(e.ClipRectangle))
{
Imps.Client.Pc.DrawHelper.DrawTriangle(e.Graphics, rect, Direction.Down, Color.Black);
}
}
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (base.Bounds.IntersectsWith(e.ClipRectangle))
{
if (base.BackgroundImage != null)
{
e.Graphics.DrawImage(base.BackgroundImage, base.Bounds);
}
else
{
Imps.Client.Utils.DrawHelper.DrawAndFillRect(e.Graphics, base.Bounds, base.BackColor, base.BorderColor, 3);
}
}
}
public ToolStripDropDown DropDown
{
get
{
return this._dropDown;
}
set
{
if (this._dropDown != null)
{
this._dropDown.VisibleChanged -= new EventHandler(this._dropDown_VisibleChanged);
}
this._dropDown = value;
if (this._dropDown != null)
{
this._dropDown.VisibleChanged += new EventHandler(this._dropDown_VisibleChanged);
}
}
}
private Rectangle DropDownRect
{
get
{
Rectangle clientRectangle = this.ClientRectangle;
switch (this._style)
{
case PortraitStyle.DropDownAtRightSide:
if (base.BackgroundImage == null)
{
return new Rectangle(clientRectangle.Right - 10, (clientRectangle.Bottom - 4) - 4, 7, 4);
}
return new Rectangle(clientRectangle.Right - 15, (clientRectangle.Bottom - 4) - 4, 7, 4);
case PortraitStyle.DropDownAtBottomSide:
return new Rectangle((clientRectangle.Right - 4) - 7, (clientRectangle.Bottom - 4) - 4, 7, 4);
}
return Rectangle.Empty;
}
}
private Rectangle DropDownRectOuter
{
get
{
Rectangle dropDownRect = this.DropDownRect;
dropDownRect.Inflate(2, 2);
return dropDownRect;
}
}
private bool HoverDropDown
{
get
{
return this._hoverDropDown;
}
set
{
if (this._hoverDropDown != value)
{
this._hoverDropDown = value;
base.Invalidate(this.DropDownRectOuter);
}
}
}
public System.Drawing.Image Image
{
get
{
return this._image;
}
set
{
if (this._image != value)
{
this._image = value;
base.Invalidate();
}
}
}
private Rectangle ImageRect
{
get
{
int x;
int y;
Rectangle clientRectangle = this.ClientRectangle;
switch (this._style)
{
case PortraitStyle.DropDownAtRightSide:
x = clientRectangle.Left + this.Padding.get_Left();
y = ((clientRectangle.Top + clientRectangle.Bottom) - this.PortraitSize) / 2;
break;
case PortraitStyle.DropDownAtBottomSide:
x = ((clientRectangle.Left + clientRectangle.Right) - this.PortraitSize) / 2;
y = clientRectangle.Top + this.Padding.get_Top();
break;
default:
x = ((((clientRectangle.Left + this.Padding.get_Left()) + clientRectangle.Right) - this.Padding.get_Right()) - this.PortraitSize) / 2;
y = ((((clientRectangle.Top + this.Padding.get_Top()) + clientRectangle.Bottom) - this.Padding.get_Bottom()) - this.PortraitSize) / 2;
break;
}
return new Rectangle(x, y, this.PortraitSize, this.PortraitSize);
}
}
public System.Windows.Forms.Padding Padding
{
get
{
return this._padding;
}
set
{
this._padding = value;
base.DoAutoSize(true);
}
}
public System.Drawing.Image Portrait
{
get
{
return this._image;
}
set
{
if (this._image != value)
{
this._image = value;
base.Invalidate();
}
}
}
public Cursor PortraitCursor
{
get
{
return this._curPortrait;
}
set
{
this._curPortrait = value;
}
}
public int PortraitSize
{
get
{
return this._size;
}
set
{
if ((this._size != value) && (value > 0))
{
this._size = value;
base.DoAutoSize(true);
}
}
}
public override Size PreferredClientSize
{
get
{
int num = this._size + this.ShadowDepth;
return new Size(num + this.Padding.get_Horizontal(), num + this.Padding.get_Vertical());
}
}
public int ShadowDepth
{
get
{
return this._shadowDepth;
}
set
{
this._shadowDepth = value;
if (this._shadowDepth < 0)
{
this._shadowDepth = 0;
}
base.Margin = new System.Windows.Forms.Padding(this._shadowDepth);
base.DoAutoSize(true);
}
}
public PortraitStyle Style
{
get
{
return this._style;
}
set
{
if (this._style != value)
{
this._style = value;
switch (this._style)
{
case PortraitStyle.DropDownAtRightSide:
this.Padding = new System.Windows.Forms.Padding(4, 4, 13, 4);
return;
case PortraitStyle.DropDownAtBottomSide:
this.Padding = new System.Windows.Forms.Padding(4, 4, 4, 12);
return;
}
this.Padding = new System.Windows.Forms.Padding(4);
}
}
}
public enum PortraitStyle
{
Normal,
DropDownAtRightSide,
DropDownAtBottomSide
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -