» home » forums

c# transparent usercontrol background? tags:  .net, c#, help desk

misterhaan
radar
subject:  c# transparent usercontrol background?
posted:  10:30:09 am, oct 10, 2008

i’ve been working on openaces (my card game platform) recently, and haven't been able to make a usercontrol for a playing card the way i want.  since the card has rounded corners and some space around it so i can make it glow or something if it's selected, i need the background to be transparent so i can stack it on top of other cards.

the most obvious way to do that is to set the BackColor property of the usercontrol to Transparent in the designer, and while that sort of seems to work, how it actually ends up working is not actually transparent but instead sets the background color to the background color of whatever is hosting the control.

so i did a search and ended up at an msdn article how to give your control a transparent background, which said to add some code in the constructor:

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Transparent;

. . . which ended up acting not at all different than setting the backcolor property in the designer.  so for now i’m pretty much stuck.

i am seeing this problem in my card pile control, which as you might expect is a control that represents a pile of cards (like you might see in a solitaire game).  i see a stripe of background color between each card and the card below that it’s mostly covering up.  i may be able to work around this by moving the code that draws the card images out to a separate class and having the card pile simply draw card images on itself rather than actually containing card controls, but i don’t like that as much and i’m not sure if doing that will cause other problems for me.

at least my shuffle algorithm works!

edited by misterhaan, 1:02:58 pm, oct 30, 2008

please note that the above post is likely made up in its entirety.

anonymous
subject:  re: c# transparent usercontrol background?
posted:  3:31:06 pm, feb 07, 2009

dear misterhaan, a faced the same problem, if u  reach the solution  please till me, my mail sherif__samy@hotmail.com

anonymous
subject:  re: c# transparent usercontrol background?
posted:  9:29:12 am, may 05, 2009

put this code.

        protected override CreateParams CreateParams
        {
            get
            {
                const int WS_EX_TRANSPARENT = 0x20;
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= WS_EX_TRANSPARENT;
                return cp;
            }
        }


from jarbas ugarte

edited by misterhaan, 5:07:02 pm, may 29, 2009

misterhaan
radar
subject:  re: c# transparent usercontrol background?
posted:  7:40:52 am, oct 10, 2009

i finally got around to trying the CreateParams thing — it seems to make the entire control transparent instead of just the background.  so put two cards on top of each other and the one on the bottom actually shows through the one on top (looks like it’s stacked backward from how it’s actually stacked).  if you click the part of the bottom one that’s showing through the top one though, the top one gets the click event.

so maybe closer, but still not there.

please note that the above post is likely made up in its entirety.

add a reply

posting asanonymous (log in or register)

nearby pages

users online

13 guests

user list

statistics

hits today1051
registered users184
forum posts419
comments157

powered by

  • dreamhost
  • linux
  • apache
  • php
  • mysql