📄 picbox.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace CardGame
{
/// <summary>
/// PicBox 的摘要说明。
/// </summary>
public class PicBox:UserControl
{
private Image image=null;
public PicBox():base()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
SetStyle(ControlStyles.Opaque, false);
SetStyle(ControlStyles.Selectable, false);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
public Image Image
{
get
{
return image;
}
set
{
if(image==value)return;
image=value;
base.Invalidate(false);
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
if(image!=null)
{
if(!image.Size.Equals(base.Size))
{
base.Size=image.Size;
}
g.DrawImageUnscaled(image,0,0);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -