資源簡介
C#復(fù)選框重繪 ,重寫的Checkbox,支持選框大小調(diào)整、選框圖像替換等,適合學(xué)習(xí)使用

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing;
using?System.ComponentModel;
using?System.Drawing.Drawing2D;
namespace?WControls
{
????[ToolboxBitmap(typeof(CheckBox))]
????public?class?WCheckBox?:?CheckBox
????{
????????public?WCheckBox()?:?base()
????????{
????????????Setstyle(Controlstyles.UserPaint?|
??????????????Controlstyles.AllPaintingInWmPaint?|
??????????????Controlstyles.OptimizedDoubleBuffer?|
??????????????Controlstyles.ResizeRedraw?|
??????????????Controlstyles.SupportsTransparentBackColor?true);
????????????this.BackColor?=?Color.Transparent;
????????????baseImage?=?ResourceReader.GetBitmapResource(“checkbox“);//狀態(tài)圖像
????????????this.AutoSize?=?false;
????????}
????????#region?public
????????[Category(“Custom“)?Description(“選框狀態(tài)的背景圖像該圖像包含5個狀態(tài)正常、劃過、選中、未選不可用,選中不可用,圖像總寬度應(yīng)不小于baseImageSplitWidth*5“)?Browsable(true)]
????????public?Bitmap?baseImage
????????{
????????????get?{?return?baseImage;?}
????????????set
????????????{
????????????????if?(value?!=?baseImage)
????????????????{
????????????????????baseImage?=?value;
????????????????????base.Invalidate();
????????????????}
????????????}
????????}
????????[Category(“Custom“)?Description(“背景圖像分割的寬度即每個狀態(tài)圖像的寬度“)?Browsable(true)?DefaultValue(88)]
????????public?int?baseImageSplitWidth
????????{
????????????get?{?return?baseImageSplitWidth;?}
????????????set
????????????{
????????????????if?(value?!=?baseImageSplitWidth)
????????????????{
????????????????????baseImageSplitWidth?=?value;
????????????????????this.Invalidate();
????????????????}
????????????}
????????}
????????[Category(“Custom“)?Description(“選框的大小“)?Browsable(true)?DefaultValue(typeof(Size)?“20“)]
????????public?int?BoxWidth
????????{
????????????get?{?return?this.boxSize.Width;?}
????????????set
????????????{
????????????????if?(boxSize.Width?!=?value)
????????????????{
????????????????????boxSize?=?new?Size(value?value);
????????????????????this.Invalidate();
????????????????}
????????????}
????????}
????????public?override?bool?AutoSize
????????{
????????????get?{?return?base.AutoSize;?}
????????????set
????????????{
????????????????base.AutoSize?=?false;
????????????}
????????}
????????///?
????????///?選框的繪制方式
????????///?
????????public?enum?DrawMode
????????{
????????????///?
????????????///?繪制
????????????///?
????????????Draw
????????????///?
????????????///?使用圖像繪制
????????????///?
????????????Image
????????}
????????[Category(“Custom“)?Description(“checkbox的繪制方式“)?Browsable(true)?DefaultValue(typeof(DrawMode)?“Image“)]
????????public?DrawMode?BoxDrawMode
????????{
????????????get
????????????{
????????????????return?this.drawMode;
????????????}
????????????set
????????????{
????????????????if?(this.drawMode?!=?value)
????????????????{
??????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????21796??2018-10-08?15:49??checkbox\WCheckBox.cs
?????文件????????5871??2018-06-28?11:04??checkbox\狀態(tài).png
?????目錄???????????0??2018-10-08?15:50??checkbox\
評論
共有 條評論