picbox.cs
来自「C#纸牌游戏,做的还是比较精致的.值得学习.」· CS 代码 · 共 53 行
CS
53 行
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 + =
减小字号Ctrl + -
显示快捷键?