Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good day!

Guys, i have this problem with my user control.
I have here a user control that has a method and oveerides like these:

C#
protected void InvalidateEx()
        {
            if(Parent == null)
                return ;
            Rectangle rc = new Rectangle(this.Location, this.Size);
            Parent.Invalidate(rc, true);
        }


protected override void OnPaintBackground(PaintEventArgs e){ }

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
        InvalidateEx();
        return cp;
    }
}


My problem is that whenever I run my program, the initial display is transparent but whenever a certain event(e.g. Form_Move event with a specific codes encoded in this event) will happen, the usercontrol will appear with a transparent background. What should I do then? I've tried doing the same code lines with respect to the events that allow the usercontrol to appear in the formload but it still didnt work. Please help.
If you need my whole user control program / my form code, please comment it here. Thanks! :)
Posted

1 solution

You overrode the OnPaintBackground method and didn't provide any code in it to either paint the background or call the base class OnPaintBackground, so guess what's not going to happen, ever...
 
Share this answer
 
Comments
Fealrone Alajas 14-May-12 22:55pm    
in the tutorial that I had,
http://www.bobpowell.net/transcontrols.htm

it said that I should not provide any code in the OnPaintBackground.
O.o
Fealrone Alajas 14-May-12 22:56pm    
or maybe my understanding is far from what the tutorial is implying... O.o
Dave Kreskowiak 15-May-12 7:34am    
I have no idea what you really want, but I think the tutorial your following is how to make a control with a transparent background, and then your complaining that the control has a transparent background. If you've got questions about how the code works, you'll have to ask the guy who wrote it.

I can't see the site as it's not responding.
Fealrone Alajas 15-May-12 10:13am    
My target is to make my user control transparent without affecting the objects (in my usercontrol, I have a drawn icons, drawn circles and drawns rectangles). During run time, my user control and so are my objects in the user control were transparent which does not satisfy to my expectations that is to retain the visibility for my objects in my usercontrol. Then if a certain events like Form_Move or whatsoever events that will occur, all my objects in the user control will be visible again but my user control is still transparent. What I mean by transparent is its background. I hope you got my point in here.. Sorry, twas kinda long.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900