• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

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?
0
AlexFM
Asked:
AlexFM
  • 3
  • 2
1 Solution
 
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
 
RoninTheCommented:
override Form's OnPaintBackGround event and suppress base call.

protected override void OnPaintBackground(PaintEventArgs pevent)
{
      // base.OnPaintBackground (pevent);                //comment it out
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now