[C#] - 用户自定义控件(含源代码)-透明文本框=
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
[C#] - 用户自定义控件(含源代码)-透明文本框透明文本框
由于在只能下载*.dll的文件,没有代码,所以特意发出源代码。
using System;
using System.Collections;
using ponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace ZBobb
{
///
/// AlphaBlendTextBox: A .Net textbox that can be translucent to the background.
/// (C) 2003 Bob Bradley / ZBobb@
///
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;
///
/// Required designer variable.
///
private ponentModel.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(erPaint, 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)
{
base.OnKeyUp(e);
myUpToDate = false;
this.Invalidate();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
myUpToDate = false;
this.Invalidate();
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
this.Invalidate();
}
protected override void OnGiveFeedback(GiveFeedbackEventArgs gfbevent)
{
base.OnGiveFeedback(gfbevent);
myUpToDate = false;
this.Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
//found this code to find the current cursor location
//at /FAQ/WinForms/FAQ_c50c.asp#q597q
Point ptCursor = Cursor.Position;
Form f = this.FindForm();
ptCursor = f.PointToClient(ptCursor);
if (!this.Bounds.Contains(ptCursor))