用户自定义控件透明文本框Word文件下载.docx
《用户自定义控件透明文本框Word文件下载.docx》由会员分享,可在线阅读,更多相关《用户自定义控件透明文本框Word文件下载.docx(13页珍藏版)》请在冰豆网上搜索。
///(C)2003BobBradley/ZBobb@
/summary>
///
publicclassAlphaBlendTextBox:
System.Windows.Forms.TextBox
{
#regionprivatevariables
privateuPictureBoxmyPictureBox;
privateboolmyUpToDate=false;
privateboolmyCaretUpToDate=false;
privateBitmapmyBitmap;
privateBitmapmyAlphaBitmap;
privateintmyFontHeight=10;
privateSystem.Windows.Forms.TimermyTimer1;
privateboolmyCaretState=true;
privateboolmyPaintedFirstTime=false;
privateColormyBackColor=Color.White;
privateintmyBackAlpha=10;
///Requireddesignervariable.
privateSystem.ComponentModel.Containercomponents=null;
#endregion//endprivatevariables
#regionpublicmethodsandoverrides
publicAlphaBlendTextBox()
//ThiscallisrequiredbytheWindows.FormsFormDesigner.
InitializeComponent();
//TODO:
AddanyinitializationaftertheInitializeComponentcall
this.BackColor=myBackColor;
this.SetStyle(ControlStyles.UserPaint,false);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
myPictureBox=newuPictureBox();
this.Controls.Add(myPictureBox);
myPictureBox.Dock=DockStyle.Fill;
}
protectedoverridevoidOnResize(EventArgse)
base.OnResize(e);
this.myBitmap=newBitmap(this.ClientRectangle.Width,this.ClientRectangle.Height);
//(this.Width,this.Height);
this.myAlphaBitmap=newBitmap(this.ClientRectangle.Width,this.ClientRectangle.Height);
myUpToDate=false;
this.Invalidate();
//SomeoftheseshouldbemovedtotheWndProclater
protectedoverridevoidOnKeyDown(KeyEventArgse)
base.OnKeyDown(e);
protectedoverridevoidOnKeyUp(KeyEventArgse)
base.OnKeyUp(e);
protectedoverridevoidOnKeyPress(KeyPressEventArgse)
base.OnKeyPress(e);
protectedoverridevoidOnMouseUp(MouseEventArgse)
base.OnMouseUp(e);
protectedoverridevoidOnGiveFeedback(GiveFeedbackEventArgsgfbevent)
base.OnGiveFeedback(gfbevent);
protectedoverridevoidOnMouseLeave(EventArgse)
//foundthiscodetofindthecurrentcursorlocation
//at
PointptCursor=Cursor.Position;
Formf=this.FindForm();
ptCursor=f.PointToClient(ptCursor);
if(!
this.Bounds.Contains(ptCursor))
base.OnMouseLeave(e);
protectedoverridevoidOnChangeUICues(UICuesEventArgse)
base.OnChangeUICues(e);
//--
protectedoverridevoidOnGotFocus(EventArgse)
base.OnGotFocus(e);
myCaretUpToDate=false;
myTimer1=newSystem.Windows.Forms.Timer(ponents);
myTimer1.Interval=(int)win32.GetCaretBlinkTime();
//
usuallyaround500;
myTimer1.Tick+=newEventHandler(myTimer1_Tick);
myTimer1.Enabled=true;
protectedoverridevoidOnLostFocus(EventArgse)
base.OnLostFocus(e);
myTimer1.Dispose();
//--
protectedoverridevoidOnFontChanged(EventArgse)
if(this.myPaintedFirstTime)
base.OnFontChanged(e);
this.SetStyle(ControlStyles.UserPaint,true);
myFontHeight=GetFontHeight();
protectedoverridevoidOnTextChanged(EventArgse)
base.OnTextChanged(e);
protectedoverridevoidWndProc(refMessagem)
base.WndProc(refm);
//needtorewriteasabigswitch
if(m.Msg==win32.WM_PAINT)
myPaintedFirstTime=true;
myUpToDate||!
myCaretUpToDate)
GetBitmaps();
myUpToDate=true;
myCaretUpToDate=true;
if(myPictureBox.Image!
=null)myPictureBox.Image.Dispose();
myPictureBox.Image=(Image)myAlphaBitmap.Clone();
elseif(m.Msg==win32.WM_HSCROLL||m.Msg==win32.WM_VSCROLL)
elseif(m.Msg==win32.WM_LBUTTONDOWN
||m.Msg==win32.WM_RBUTTONDOWN
||m.Msg==win32.WM_LBUTTONDBLCLK
||m.Msg==win32.WM_MOUSELEAVE
///****
)
elseif(m.Msg==win32.WM_MOUSEMOVE)
if(m.WParam.ToInt32()!
=0)
//shiftkeyorotherbuttons
//System.Diagnostics.Debug.WriteLine("
Pro:
"
+m.Msg.ToString("
X"
));
///Cleanupanyresourcesbeingused.
protectedoverridevoidDispose(booldisposing)
if(disposing)
//this.BackColor=Color.Pink;
if(components!
=null)
components.Dispose();
base.Dispose(disposing);
#endregion
//endpublicmethodandoverrides
#regionpublicpropertyoverrides
publicnewBorderStyleBorderStyle
get{returnbase.BorderStyle;
set
base.BorderStyle=value;
this.myBitmap=null;
this.myAlphaBitmap=null;
publicnewColorBackColor
get
returnColor.FromArgb(base.BackColor.R,base.BackColor.G,base.BackColor.B);
myBackColor=value;
base.BackColor=value;
publicoverrideboolMultiline
get{returnbase.Multiline;
base.Multiline=value;
//endpublicpropertyoverrides
#regionprivatefunctionsandclasses
privateintGetFontHeight()
Graphicsg=this.CreateGraphics();
SizeFsf_font=g.MeasureString("
this.Font);
g.Dispose();
return(int)sf_font.Height;
privatevoidGetBitmaps()
if(myBitmap==null
||myAlphaBitmap==null
||myBitmap.Width!
=Width
||myBitmap.Height!
=Height
||myAlphaBitmap.Width!
||myAlphaBitmap.Height!
=Height)
myBitmap=null;
myAlphaBitmap=null;
if(myBitmap==null)
myBitmap=newBitmap(this.ClientRectangle.Width,this.ClientRectangle.Height);
//(Width,Height);