Note that there are some explanatory texts on larger screens.

plurals
  1. POPartial transparency with C# .NET 3.5 WinForms?
    text
    copied!<p>I'm making a .NET 3.5 app with a form that draws a partially transparent black background. I'm overriding OnPaintBackground to accomplish this:</p> <pre><code>protected override void OnPaintBackground( PaintEventArgs e ) { using ( Brush brush = new SolidBrush( Color.FromArgb( 155, Color.Black ) ) ) { e.Graphics.FillRectangle( brush, e.ClipRectangle ); } } </code></pre> <p>It works, but occasionally the form draws over itself without clearing the screen, making the transparency darker than it should be. I've tried playing with <code>Graphics.Flush()</code> and <code>Graphics.Clear()</code>, but it either doesn't help or completely removes transparency. Any suggestions?</p> <p><strong>Edit:</strong> Here's what it looks like, after starting the app on the left, and after the form redraws itself a few times (in response to tabbing from one control to another) on the right:</p> <p><a href="http://www.quicksnapper.com/files/5085/17725729384A10347269148_m.png" rel="nofollow noreferrer">Transparency Issue http://www.quicksnapper.com/files/5085/17725729384A10347269148_m.png</a></p> <p><strong>Edit 2:</strong> I was trying a few things out this morning and noticed that when the desktop behind the transparent portions change, it's not actually being redrawn. For example, if I open Task Manager and put it behind the window, you don't see it refreshing itself. This makes sense with what I've been seeing with the transparency levels. Is there a function to make Windows redraw the area behind your window?</p> <p><strong>Edit 3:</strong> I've tried changing a few properties on the form, but they all result in the form drawing non-transparent black:</p> <pre><code>this.AllowTransparency = true; this.DoubleBuffered = true; this.Opacity = .99; </code></pre> <p>I'm going to try creating a separate window for the transparent portion as overslacked mentioned, but any other ideas are still welcome.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload