C# 高仿腾讯QQ (TextBox控件美化).doc_第1页
C# 高仿腾讯QQ (TextBox控件美化).doc_第2页
C# 高仿腾讯QQ (TextBox控件美化).doc_第3页
C# 高仿腾讯QQ (TextBox控件美化).doc_第4页
C# 高仿腾讯QQ (TextBox控件美化).doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C# 高仿腾讯QQ (TextBox控件美化)(附源码)这篇来说一下QQ皮肤TextBox控件的美化: (1)已修正 每次窗口最小化以后再还原会发现窗口底部往下移了几十个像素(但还不十分完善,在设计模式时有BUG,请高手支招) 效果图如下: 说明: (1)新增一个自定义控件(ALTextBox.cs),在上面放一个TextBox控件,把控件的边框属性设为无 (BorderStyle=BorderStyle.None); (2)准备一张带有5个状态的按钮图片如 分别对应5种状态,通过重写OnPaint方法把相应的状态图画进去(其实有几种状态用不到,大家自己去修正吧) /枚举按钮的状态 public enum State Normal = 1,/按钮默认时MouseOver = 2,/鼠标移上按钮时MouseDown = 3,/鼠标按下按钮时Disable = 4,/当不启用按钮时(也就是按钮属性Enabled=Ture时)Default = 5/控件得到Tab焦点时 ALTextBox.cs类源码代码 using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using AlSkin.AlClass;namespace AlSkin.AlControl.AlTextBox public partial class AlTextBox : UserControl #region 声明 private Bitmap _TextBoxBackImg = ImageObject.GetResBitmap(AlSkin.AlSkinImg.AlTextBoxImg.Textbox.png); private State state = State.Normal; private bool _Isico = false; private Bitmap _Ico; private Padding _IcoPadding=new Padding(3,3,0,0); /枚鼠标状态 private enum State Normal = 1, MouseOver = 2, MouseDown = 3, Disable = 4, Default = 5 #endregion #region 构造 public AlTextBox() InitializeComponent(); 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.SetStyle(ControlStyles.Selectable, true); this.BackColor = Color.Transparent; #endregion #region 属性 Category(阿龙自定义属性), Description(与控件关联的文本) public string text get return BaseText.Text; set BaseText.Text = value; Category(阿龙自定义属性), Description(输入最大字符数) public int MaxLength get return BaseText.MaxLength; set BaseText.MaxLength = value; Category(阿龙自定义属性), Description(与控件关联的文本) public new string Text get return BaseText.Text; set BaseText.Text = value; Category(阿龙自定义属性), Description(将控件设为密码显示) public bool IsPass get return BaseText.UseSystemPasswordChar; set BaseText.UseSystemPasswordChar = value; Category(阿龙自定义属性), Description(密码显示字符) public char PassChar get return BaseText.PasswordChar; set BaseText.PasswordChar = value; Category(阿龙自定义属性), Description(将控件设为多行文本显示) public bool Multiline get return BaseText.Multiline; set BaseText.Multiline = value; if (value) BaseText.Height = this.Height - 6; else base.Height = 22; BaseText.Height = 16; this.Invalidate(); Category(阿龙自定义属性), Description(将控件设为多行文本显示) public Font font get return BaseText.Font; set BaseText.Font = value; Category(阿龙自定义属性), Description(将控件设为只读) public bool ReadOnly get return BaseText.ReadOnly; set BaseText.ReadOnly = value; Category(阿龙自定义属性), Description(多行文本的编辑行) public String lines get return BaseText.Lines; set BaseText.Lines = value; Category(阿龙自定义属性), Description(是否显示图标) public bool Isico get return _Isico; set _Isico = value; if (value) if (_Ico != null) BaseText.Location = new Point(_IcoPadding.Left + _Ico.Width, 3); BaseText.Width = BaseText.Width - _IcoPadding.Left - _Ico.Width; else BaseText.Location = new Point(25, 3); BaseText.Width = BaseText.Width - 25; this.Invalidate(); Category(阿龙自定义属性), Description(图标文件) public Bitmap Ico get return _Ico; set _Ico = value; Category(阿龙自定义属性), Description(图标文件Padding) public Padding IcoPadding get return _IcoPadding; set _IcoPadding = value; this.Invalidate(); #endregion #region 委托 public event EventHandler IcoOnclick; #endregion #region 方法 protected override void OnPaint(PaintEventArgs e) Rectangle rc = this.ClientRectangle; Graphics g = e.Graphics; ImageDrawRect.DrawRect(g, _TextBoxBackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), (int)state, 5); if (_Isico) if (_Ico != null) g.DrawImage(_Ico,new Point(_IcoPadding.Left,_IcoPadding.Top); base.OnPaint(e); private void AlTextBox_Resize(object sender, EventArgs e) if (this.Height 22) Multiline = true; else this.Height = 22; Multiline = false; private void NotifyIcoOnclick() if (IcoOnclick != null) IcoOnclick(this, EventArgs.Empty); public void AppendText(string ss) BaseText.AppendText(ss); private void BaseText_MouseEnter(object sender, EventArgs e) state = State.MouseOver; this.Invalidate(); private void BaseText_MouseLeave(object sender, EventArgs e) state = State.Normal; this.Invalidate(); private void AlTextBox_MouseUp(object sender, MouseEventArgs e) if (_Ico != null) if (new Rectangle(_IcoPadding.Left, _IcoPadding.Top, _Ico.Width, _Ico.Height).Contains(e.X,e.Y) NotifyIcoOnclick(); private void AlTextBox_Mou

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论