📄 collapseexpandbutton.cs
字号:
namespace Imps.Client.Pc.BizControls.Conversation
{
using Imps.Client.Pc.BizControls;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class CollapseExpandButton : BControl
{
protected System.Drawing.Image hoverImage;
protected System.Drawing.Image image;
protected Rectangle imageRectangle;
protected bool isExpanded;
protected bool isMouseHover;
public event EventHandler CollapseExpand;
public CollapseExpandButton()
{
base.SetStyle(0x20802, true);
base.Size = new Size(12, 13);
this.BackColor = Color.Transparent;
}
private Rectangle CalculateImageRectangle()
{
if (this.Image == null)
{
return Rectangle.Empty;
}
return new Rectangle((base.Width - this.Image.Width) / 2, (base.Height - this.Image.Height) / 2, this.Image.Width, this.Image.Height);
}
public void ChangeStatus()
{
if (this.image != null)
{
this.image.RotateFlip(RotateFlipType.RotateNoneFlipX);
this.hoverImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
this.isExpanded = !this.isExpanded;
if (this.CollapseExpand != null)
{
this.CollapseExpand(this, new EventArgs());
}
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (MouseButtons.Left == e.Button)
{
this.ChangeStatus();
base.Invalidate();
}
}
protected override void OnMouseEnter(EventArgs e)
{
this.isMouseHover = true;
base.Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
this.isMouseHover = false;
base.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.image != null)
{
Graphics graphics = e.Graphics;
this.imageRectangle = this.CalculateImageRectangle();
if (this.isMouseHover)
{
graphics.DrawImage(this.hoverImage, this.imageRectangle);
}
else
{
graphics.DrawImage(this.image, this.imageRectangle);
}
}
}
public System.Drawing.Image HoverImage
{
get
{
if (this.hoverImage == null)
{
this.hoverImage = this.image;
}
return this.hoverImage;
}
set
{
this.hoverImage = value;
}
}
public System.Drawing.Image Image
{
get
{
return this.image;
}
set
{
this.image = value;
}
}
public bool IsExpanded
{
get
{
return this.isExpanded;
}
set
{
this.isExpanded = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -