C# 高仿腾讯QQ (CheckBox控件美化)

接上一篇《C# 高仿腾讯QQ (TextBox控件美化)

这篇来说一下QQ皮肤CheckBox控件的美化:

看过上几篇的,这个理解应该很简单,没有太多时间,就不多说了,直接贴源

 

代码
 
   
// 作者:阿龙(Along)
// QQ号:646494711
// QQ群:57218890
// 网站: http://www.8timer.com
// 博客: http://www.cnblogs.com/Along729/
// 声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using AlSkin.AlClass;
using System.ComponentModel;

namespace AlSkin.AlControl.AlCheckBox
{
[ToolboxBitmap(
typeof (System.Windows.Forms.CheckBox))]
public class AlCheckBox : CheckBox
{
#region 声明
private State state = State.Normal;
private Bitmap _BackImg = ImageObject.GetResBitmap( " AlSkin.AlSkinImg.AlCheckBoxImg.Checkbox.png " );
// 枚鼠标状态
private enum State
{
Normal
= 1 ,
MouseOver
= 2 ,
MouseDown
= 3 ,
Disable
= 4
}
#endregion

#region 构造函数
public AlCheckBox()
{
this .SetStyle(ControlStyles.UserPaint, true ); // 设置控件自行绘制
this .SetStyle(ControlStyles.DoubleBuffer, true );
this .SetStyle(ControlStyles.AllPaintingInWmPaint, true );
this .SetStyle(ControlStyles.SupportsTransparentBackColor, true ); // 背景透明
this .SetStyle(ControlStyles.StandardDoubleClick, false );
this .BackColor = System.Drawing.Color.Transparent; // 背景设为透明

}
#endregion

#region 属性
[CategoryAttribute(
" 阿龙自定义属性 " ), Description( " CheckBox图片 " )]
public Bitmap BackImg
{
get { return this ._BackImg; }
set
{
_BackImg
= value;
this .Invalidate();
}
}
#endregion

#region 方法
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base .OnPaint(e);
base .OnPaintBackground(e);
if (_BackImg == null )
{
base .OnPaint(e);
return ;
}

int i = ( int )state;
if ( ! this .Enabled) i = 4 ;
if ( this .CheckState == CheckState.Checked) i += 4 ;
if ( this .CheckState == CheckState.Indeterminate) i += 8 ;

Rectangle rc
= this .ClientRectangle;
Rectangle r1
= rc;
Rectangle textRect;
Graphics g
= e.Graphics;

if ( this .CheckAlign == ContentAlignment.MiddleLeft) // 对齐状态
{
r1
= new Rectangle( 0 , (rc.Height - 15 ) / 2 , 16 , 15 );
textRect
= new Rectangle( 16 , 0 , rc.Width - 16 , rc.Height);
}
else
{
r1
= new Rectangle(r1.Right - 16 , (rc.Height - 16 ) / 2 , 16 , 15 );
textRect
= new Rectangle( 0 , 0 , rc.Width - 16 , rc.Height);
}
ImageDrawRect.DrawRect(g, _BackImg, r1, Rectangle.FromLTRB(
0 , 0 , 0 , 0 ), i, 12 );
Color textColor
= Enabled ? ForeColor : SystemColors.GrayText;
TextRenderer.DrawText(e.Graphics,
this .Text, this .Font, textRect, textColor);
}
protected override void OnMouseEnter(EventArgs e)
{
state
= State.MouseOver;
this .Invalidate();
base .OnMouseEnter(e);
}

protected override void OnMouseLeave(EventArgs e)
{
state
= State.Normal;
this .Invalidate();
base .OnMouseLeave(e);
}

protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) != MouseButtons.Left) return ;
state
= State.MouseOver;
this .Invalidate();
base .OnMouseDown(e);
}

protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
state
= State.MouseOver;
this .Invalidate();
base .OnMouseUp(e);
}
#endregion
}
}

 

由于我的空间经常出问题,以后所有的源文件都放在57218890群共享里面,大家自己去下

还有,RadioButton 美化差不多,大家自己去试试

 

 

转载于:https://www.cnblogs.com/Along729/archive/2010/12/20/AlCheckBox.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值