The RichTextBox Control is transparent to the background.

Source: Internet
Author: User

Http://www.codeproject.com/cs/miscctrl/TransparentTextBox.asp
How to make the RichTextBox Control transparent: After transparency, you can set the background image on the back, but it is usually shaking.
There are also other ways to set transparency and use the timer to refresh, as shown below:
Http://www.codeproject.com/cs/miscctrl/AlphaBlendedTextControls.asp

RichTextBox
<span class="cs-keyword">class</span> TransparentControl : Control{   <span class="cs-keyword">public</span> TransparentControl()   {      <span class="cs-keyword">base</span>.SetStyle( ControlStyles.UserPaint, <span class="cs-keyword">true</span> );      <span class="cs-keyword">base</span>.SetStyle( ControlStyles.DoubleBuffer, <span class="cs-keyword">true</span> );      <span class="cs-keyword">base</span>.SetStyle( ControlStyles.SupportsTransparentBackColor, <span class="cs-keyword">true</span> );   }} <span class="cs-keyword">class</span> TransparentRichTextBox : RichTextBox{   <span class="cs-keyword">public</span> TransparentRichTextBox()   {      <span class="cs-keyword">base</span>.ScrollBars = RichTextBoxScrollBars.None;   }    <span class="cs-keyword">override</span> <span class="cs-keyword">protected</span> CreateParams CreateParams   {      <span class="cs-keyword">get</span>      {         CreateParams cp = <span class="cs-keyword">base</span>.CreateParams;         cp.ExStyle |= <span class="cs-literal">0x20</span>;         <span class="cs-keyword">return</span> cp;      }   }    <span class="cs-keyword">override</span> <span class="cs-keyword">protected</span> <span class="cs-keyword">void</span> OnPaintBackground( PaintEventArgs e )   {   }}
Textbox collapse
public class TransparentTextBox : TextBox{   PictureBox 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 bmpResult =               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 = new ImageAttributes();            ColorMap[] colorMap = new ColorMap[ 1 ];            colorMap[ 0 ] = new ColorMap();            colorMap[ 0 ].OldColor = Color.White;            colorMap[ 0 ].NewColor = Color.Transparent;            imgAttrib.SetRemapTable( colorMap );             Graphics g = Graphics.FromImage( bmpResult );            g.DrawImage( bmpCaptured, r, 0 , 0, this.ClientRectangle.Width,                 this.ClientRectangle.Height, GraphicsUnit.Pixel, imgAttrib );            g.Dispose();            pictureBox.Image = ( Image )bmpResult.Clone();          break;         case Win32.WM_HSCROLL:         case Win32.WM_VSCROLL:            this.Invalidate(); // repaint           // if you use scrolling then add these two case statements         break;   }}private static void CaptureWindow( Control 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();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.