Solved

Borderless form flickers to much after resizing.

Posted on 2011-09-24
7
453 Views
Last Modified: 2013-12-17
Dear Experts,

I have made a borderless form with a borderline painted.
And the user is able to resize the form.
But when the form gets resized it flickers to much!

What can I do about this?

Who knows the answer and is willing to help me?

Greetings,

Peter Kiers
private void StickyNotes_Paint(object sender, PaintEventArgs e)
         {
            using (Pen pen = new Pen(Brushes.Silver, 2))
            {
                e.Graphics.DrawRectangle(pen, this.ClientRectangle);
            }
         }

      Private void StickyNotes_Resize(object sender, EventArgs e)
{
this.Invalidate();
}

Open in new window

0
Comment
Question by:peterkiers
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
I thought it might surface as a problem.

There is a ResizeEnd event - you could put the invalidate in there (instead of OnResize) but check it first - it looks odd.

If it is not suitable you would need to store the original rectangle coordinates you draw then erase them (draw in pen with sam colour as the background) before drawing the new rectangle in the OnPaint event.


(Maybe you should consider just having a border on the form instead of borderless - stops you inventing the wheel again)
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
ResizeEnd had no effect.

"If it is not suitable you would need to store the original rectangle coordinates you draw then erase them (draw in pen with sam colour as the background) before drawing the new rectangle in the OnPaint event."

Can you PLEASE tell me how?
P.

0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Oh ye,forgot to mention

I have just a form that i have give a certain color
and a borderline painted.

P.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
Comment Utility
You are recreating and disposing of the Pen on each pass into Paint.

Define the Pen as a form level variable.

Then, I haven't work in those things for a long time and I do not have time to check, so I could be wrong, but I do not think you have to Invalidate the form. It is done automatically while you are resizing. If you do it, it gets done twice.

And finally, a personal remark. I do not thing that it is a good idea to have a resizable form with such a thin border. Any user of Windows is used to the look of a resizable form. It has a tick border that is in more than one color, either some kind of a gradient in the newer versions of Windows, or thin black lines with grey inside in the order ones.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
Comment Utility
Have you tried enabling double buffering?...
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
Double buffering saves a copy of the bitmap. It is thus useful when there is something on the form. As I understand, the form is empty right now.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Try Invalidate(false); instead of just Invalidate();  Maybe that will help (it shouldn't force child controls to redraw).
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now