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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

e1vCommented:
What happens if you add ControlStyles.Opaque ? (But I don't really have a clue)
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.
RoninTheCommented:
override Form's OnPaintBackGround event and suppress base call.

protected override void OnPaintBackground(PaintEventArgs pevent)
{
      // base.OnPaintBackground (pevent);                //comment it out
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

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.
RoninTheCommented:
I just tried this with a very basic winApp, and it works. may be you're doing something else too.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.