您现在的位置:IT之家 >> 学院>> 程序开发教程>> c#教程 >> 正文内容
同级栏目:
ASP.NET教程ASP教程PHP教程JSP教程Perl教程PowerBuilder教程XML教程Visual C++教程c#教程Visual Basic教程JAVA教程C++ Builder教程C++教程Delphi教程shell教程NoahWeb教程移动开发教程
>内容阅读:

用户自定义控件-透明文本框(WinForm)

作者: 来源: 时间:2010年03月13日 【字体:

用户自定义控件-透明文本框(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)
{


共6页 您在第1页 首页 上一页 1 2 3 4 5 6 下一页 尾页 跳转到页 本页共有2894个字符