56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
![]() |
using System;
|
|||
|
using CPF.Drawing;
|
|||
|
using CPF.ReoGrid.Rendering;
|
|||
|
|
|||
|
namespace CPF.ReoGrid.CellTypes
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class ImageButtonCell : ButtonCell
|
|||
|
{
|
|||
|
public Image Image { get; set; }
|
|||
|
|
|||
|
public ImageButtonCell() : this(null)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public ImageButtonCell(Image image)
|
|||
|
{
|
|||
|
this.Image = image;
|
|||
|
}
|
|||
|
|
|||
|
public override void OnPaint(CellDrawingContext dc)
|
|||
|
{
|
|||
|
base.OnPaint(dc);
|
|||
|
bool flag = this.Image != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
float val = Math.Min((this.Bounds.Width - 4f) / (float)this.Image.Width, 1f);
|
|||
|
float val2 = Math.Min((this.Bounds.Height - 4f) / (float)this.Image.Height, 1f);
|
|||
|
float num = Math.Min(val, val2);
|
|||
|
float num2 = (float)this.Image.Height / (float)this.Image.Width;
|
|||
|
float num3 = (float)this.Image.Width * num;
|
|||
|
float num4 = 0f;
|
|||
|
float num5 = 0f;
|
|||
|
float num6 = num2 * num3;
|
|||
|
Rect rect = new Rect(ref num4, ref num5, ref num3, ref num6);
|
|||
|
rect.X = (this.Bounds.Width - rect.Width) / 2f;
|
|||
|
rect.Y = (this.Bounds.Height - rect.Height) / 2f;
|
|||
|
bool isPressed = base.IsPressed;
|
|||
|
if (isPressed)
|
|||
|
{
|
|||
|
num4 = rect.X;
|
|||
|
rect.X = num4 + 1f;
|
|||
|
num4 = rect.Y;
|
|||
|
rect.Y = num4 + 1f;
|
|||
|
}
|
|||
|
dc.Graphics.DrawImage(this.Image, rect);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override ICellBody Clone()
|
|||
|
{
|
|||
|
return new ImageButtonCell(this.Image);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|