用户自定义控件-透明文本框(WinForm)代码,希望对大家学习有所帮助哈,下面看代码了
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace ZBobb
{
/// <summary>
/// AlphaBlendTextBox: A .Net textbox that can be translucent to the background.
/// (C) 2003 Bob Bradley / ZBobb@hotmail.com
/// </summary>
///
public class AlphaBlendTextBox : System.Windows.Forms.TextBox
{
#region private variables
private uPictureBox myPictureBox;
private bool myUpToDate = false;
private bool myCaretUpToDate = false;
private Bitmap myBitmap;
private Bitmap myAlphaBitmap;
private int myFontHeight = 10;
private System.Windows.Forms.Timer myTimer1;
private bool myCaretState = true;
private bool myPaintedFirstTime = false;
private Color myBackColor = Color.White;
private int myBackAlpha = 10;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
#endregion // end private variables
#region public methods and overrides
public AlphaBlendTextBox()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
this.BackColor = myBackColor;
this.SetStyle(ControlStyles.UserPaint, false);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
myPictureBox = new uPictureBox();
this.Controls.Add(myPictureBox);
myPictureBox.Dock = DockStyle.Fill;
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.myBitmap = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);//(this.Width,this.Height);
this.myAlphaBitmap = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);//(this.Width,this.Height);
myUpToDate = false;
this.Invalidate();
}
//Some of these should be moved to the WndProc later
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
myUpToDate = false;
this.Invalidate();
}
protected override void OnKeyUp(KeyEventArgs e)
{
Copyright © IT之家(Www.IT55.Com) Powered By 易网科技 备案号:豫ICP备07012916号
本站QQ群:6614136 / 4218001 友情链接QQ:987950121