The problem is:TextboxAndRichTextBoxBackcolorAttributeNot acceptableColor. Transparent. So I giveTextboxAndRichTextBoxControl to find the corresponding solution
This is not a perfect solution. It may be hard for beginners to understand it. If youProgramDesign and C # are good, so this articleArticleIt must be a piece of cake for you.
RichTextBox Class Transparentcontrol: Control
{
Public Transparentcontrol ()
{
Base . Setstyle (controlstyles. userpaint, True );
Base . Setstyle (controlstyles. doublebuffer, True );
Base . Setstyle (controlstyles. supportstransparentbackcolor, True );
}
}
ClassTransparentrichtextbox: RichTextBox
{
PublicTransparentrichtextbox ()
{
Base. Scrollbars=Richtextboxscrollbars. None;
}
Override Protected Createparams
{
Get
{
Createparams CP = Base . Createparams;
CP. exstyle | = 0x20 ;
Return CP;
}
}
Override Protected VoidOnpaintbackground (painteventargs E)
{
}
}
Textbox
Public Class Transparenttextbox: textbox
{
Picturebox = New Picturebox ();
Public Transparenttextbox ()
{
Picturebox. Dock = Dockstyle. Fill;
This . Controls. Add (picturebox );
}
Protected Override Void Wndproc ( Ref Message m)
{
Base . Wndproc ( Ref M );
Switch (M. msg)
{
Case Win32.wm _ paint:
Bitmap bmpcaptured =
New Bitmap ( This . Clientrectangle. Width, This . Clientrectangle. Height );
Bitmap BMP result =
New Bitmap ( This . Clientrectangle. Width, This . Clientrectangle. Height );
Rectangle R =
New Rectangle ( 0 , 0 , This . Clientrectangle. Width,
This . Clientrectangle. Height );
Capturewindow ( This , Ref Bmpcaptured );
This . Setstyle (controlstyles. supportstransparentbackcolor, True );
This . Backcolor = Color. transparent;
Imageattributes imgattrib= NewImageattributes ();
Colormap [] colormap= NewColormap [1];
Colormap [0]= NewColormap ();
Colormap [0]. Oldcolor=Color. White;
Colormap [0]. Newcolor=Color. transparent;
Imgattrib. setremaptable (colormap );
Graphics g=Graphics. fromimage (BMP result );
G. drawimage (bmpcaptured, R,0,0,This. Clientrectangle. Width,
This. Clientrectangle. Height, graphicsunit. pixel, imgattrib );
G. Dispose ();
Picturebox. Image=(Image) BMP result. Clone ();
Break;
CaseWin32.wm _ hscroll:
CaseWin32.wm _ vscroll:
This. Invalidate ();//Repaint
//If you use scrolling then add these two case statements
Break;
}
}
Private Static Void Capturewindow (Control, Ref Bitmap bitmap)
{
Graphics g = Graphics. fromimage (Bitmap );
Int I = ( Int ) (Win32.prf _ Client | Win32.prf _ erasebkgnd );
Intptr iptr = New Intptr ( 14 );
Intptr HDC = G. gethdc ();
Win32.sendmessage (control. Handle, win32.wm _ print, HDC, iptr );
G. releasehdc (HDC );
G. Dispose ();
}