Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Semitransparent panel

Started by Montynis Jul 3, 2007 at 4:09 PM 2 replies 900+ views
Original Post
Montynis
Montynis
Hello, I am trying to create semitransparent panel (for example, which is 50% opaque). So I wrote the following code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing; 

namespace Visata
{
   public class TransparentPanel :Panel
   {
      public TransparentPanel()
      { 

      } 

      protected override CreateParams CreateParams
      {
         get
         {
            CreateParams cp = base.CreateParams;
            cp.Exstyle |= 0x20; 
            return cp;
         }
      }

      protected override void OnPaintBackground(PaintEventArgs e)
      {
      } 

   }

}
After this I tried to add TransparentPanel to my form. I noticed that this panel is absolutely invisible. Where is the problem? How to create a panel, which is, for example, blue and semitransparent (opacity is 50%)?. Thanks in advance.
Nypyren
Nypyren
Well, in your code it looks like you're totally skipping drawing the control's background, so it seems that it would be invisible due to that.

try:
BackColor = Color.FromArgb(127, BackColor);

remove the OnPaintBackground override function, and see if that works.
Montynis
Montynis
Quote:
Original post by Nypyren
Well, in your code it looks like you're totally skipping drawing the control's background, so it seems that it would be invisible due to that.

try:
BackColor = Color.FromArgb(127, BackColor);

remove the OnPaintBackground override function, and see if that works.


Thanks for answer. I have tried this suggestion. The panel becomes visible, but not semitransparent. Maybe there are some other solutions?
Nypyren
Nypyren
Try adding this to the previous changes I suggested:

Setstyle(Controlstyles.UserPaint, true);Setstyle(Controlstyles.SupportsTransparentBackColor, true);


Note: for some reason the [ code ] block is trying to spell check my code. the "style" portion of those symbols are uppercase.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.