Prevent drawing form background

I have Form-derived class which is used as MDI child. I want to prevent form to redraw it's background. To do this I added the following code:

        private void FormImage_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.DoubleBuffer |
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint,
                true);
            this.UpdateStyles();
        }

Now I expect to see transparent form which does't redraw it's background. But form still redraws background according to it's BackColor property. What else should I do?
LVL 48
AlexFMAsked:
Who is Participating?
 
RoninTheCommented:
override Form's OnPaintBackGround event and suppress base call.

protected override void OnPaintBackground(PaintEventArgs pevent)
{
      // base.OnPaintBackground (pevent);                //comment it out
}
0
 
e1vCommented:
What happens if you add ControlStyles.Opaque ? (But I don't really have a clue)
0
 
AlexFMAuthor Commented:
Even with Opaque style form redraws itself.
From my VC++ experience, if window doesn't draw anything in WM_ERASEBKGND handler, it remains transparent and shows all garbage which is under it. I expect to see the same in C#, because I want to draw image in Paint handler and don't want flickering.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AlexFMAuthor Commented:
Tried this, form still draws background.
From MSDN: If you do not want the default Windows behavior, you must set the event's Handled property to true.

I didn't find any Handled property.
0
 
RoninTheCommented:
I just tried this with a very basic winApp, and it works. may be you're doing something else too.
0
 
AlexFMAuthor Commented:
OK, it didn't work with UserPaint and AllPaintingInWmPaint styles. I still don't know what is better - using styles or overriding OnPaintBackground, because there is no actual drawing code yet. But I will keep this solution for future use, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.