Snappy Rendering of Controls

  • Thread starter Thread starter Phil Jones
  • Start date Start date
P

Phil Jones

I have a situation where I'm hosting a number of complex controls within a
form, but only showing one at a time. When the user clicks on a navigation
button one or other of the controls is displayed.

My problem is that, as the control is revealed (it's Visible property is set
to True), it flashes quickly as parts of it are rendered (that is, I can see
squares of white flashing until their BG colors a drawn etc).

What's the correct appropach to take when revealaing a control to avoid this
kind of thing? What I'd like is for it to just snap up in one go. Is there
anything I can do???

Thank you!

===
Phil
(Auckland | Aotearoa)
 
Phil,

did you try to use SuspendLayout/PerformLayout calls for form to bracket
Visible setting?

HTH
Alex
 
* "AlexS said:
did you try to use SuspendLayout/PerformLayout calls for form to bracket
Visible setting?

This will only prevent the controls from resizing.
 
I find this works best. This is VB, but easily translated to C#:

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)

End Sub

That should work if your control is inherited a System.Windows.Form.Control.
 
Ah sweet - I'll give that a crack. No problem on the VB - I prefer it that
way ;)

Much appreciated.
===
Phil


"The New iSoftware Company"
 
I've just tried that and it doesn't seem to make a difference (at least not
one I can notice).

The problem is like, I have a control that contains [PictureBox] controls,
layered over background colors, when the control is revealed (via Visible =
True) the picture boxes will flash white (the default background color)
quickly before the image is revealed.

Does that code usually sort this kind of issue? I've applied it to each
control and the form that it's contained within. Should I be putting it
anywhere else?

Many thanks!

===
Phil
(Auckland | Aotearoa)
 
Do you need the Picturebox controls? You'd get better results by painting
directly onto the control.
Maybe you should consider creating a Component which has Draw and HitTest
Methods so that you can place that on your Control in place of the
PictureBox.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Phil Jones said:
I've just tried that and it doesn't seem to make a difference (at least not
one I can notice).

The problem is like, I have a control that contains [PictureBox] controls,
layered over background colors, when the control is revealed (via Visible =
True) the picture boxes will flash white (the default background color)
quickly before the image is revealed.

Does that code usually sort this kind of issue? I've applied it to each
control and the form that it's contained within. Should I be putting it
anywhere else?

Many thanks!

===
Phil
(Auckland | Aotearoa)
 
Hi Phil,

You may try deriving from the PictureBox class and set those styles in the
constructor of the derived class, then use this derived class in your
control instead.
Does it help to your problem?
If it does not help, could you make a simple project and send me to
demonstrate this issue?

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Ahh - I think you're pointing me in the direction I want to go. There's no
real reason for the picture box, other than it renders PNG's with complex
alpha filters (for layering). If I can achieve the same results - only
without flashing, then I'm well interested in overriding the Draw method.

I don't know anything about this - so I'll have to go and study (any
suggestions on a good place to start?). Also, if I have to controls (A and
B) I'm interested in a way to draw parts of A onto a portion of B - so I can
overlay controls a little. Is that possible within the custom Draw world?

Many thanks - this is getting really intesesting!!!

===
Phil
(Auckland | Aotearoa)






"Mick Doherty"
Do you need the Picturebox controls? You'd get better results by painting
directly onto the control.
Maybe you should consider creating a Component which has Draw and HitTest
Methods so that you can place that on your Control in place of the
PictureBox.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Phil Jones said:
I've just tried that and it doesn't seem to make a difference (at least not
one I can notice).

The problem is like, I have a control that contains [PictureBox] controls,
layered over background colors, when the control is revealed (via
Visible
=
True) the picture boxes will flash white (the default background color)
quickly before the image is revealed.

Does that code usually sort this kind of issue? I've applied it to each
control and the form that it's contained within. Should I be putting it
anywhere else?

Many thanks!

===
Phil
(Auckland | Aotearoa)
 
I've just gone through and applied the suggested code (see below) to every
single control involved in the app - and the problem has disappeared
(without implementing your suggestion of inheriting from [PictureBox]).

So YEA HA!!!!!

But - I have a question. I don't really understand what setting these flags
do. Is this going to impact upon performance (or generally be bad) in other
ways if I do set these flags on all controls. Should I be a little
judicios?

Thanks everyone.
---
Phil
(Auckland | Aotearoa)



====
Code to reduce flicker:
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
 
Hi Phil,

Great!
My suggestion was to apply these code into every controls on your Form ,
not only the custom container control. PictureBox is just a sample since
you mentioned in your reply.

These flags are indicate this control supports user paint,

it should no do painting when gets WM_ERASEBKGND, when repainting,

it should repaint the whole control into a memory graphic object instead of
draw on the screen directly ( double-buffing)

and redraw the window when its size changed (normally, the window does not
need redraw if its size is become smaller).

these flags are only effective to the control you call SetStyle on , it
will not affect the child controls in it.

And it should not have a big impact on performance for the first three
flags, as the last flags it does cause more repainting however some owner
draw control relies on this behavior, you may try commenting it and see if
your form repaints correctly.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top