1

We ported win-form application legacy code developed in c# .net framework 1.1 to c# .net 3.5.

There is functionality for drawing dot plot and apply different shapes(polygon,square etc.) on dots in plot. You can change size of applied shape by dragging using mouse what happening is when dragging shape some part get invisible till we drop to new point and also draws very slow speed.

you can call it as flickering .

this functionality works fine in windows xp, in windows 7 works fine with basic and classic theme

it flickers only when aero theme is applied in windows 7

i have tried http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c and Flickering in a Windows Forms app

none of them helped.

after time stamping execution time i found that

 for (int i=0; i < arraypnts.Length - 1; i++) {
           g.DrawLine(Pens.Black, arraypnts[i], arraypnts[i+1]);
         }

         // draw the last line
         g.DrawLine(Pens.Black, arraypnts[0], arraypnts[arraypnts.Length-1]);

takes hell lot of time when aero theme applied compared to basic theme applied

Community
  • 1
  • 1
sansat
  • 11
  • 3

4 Answers4

0

I had a similar problem long time ago and after a while finally found the solution by redrawing components only when setting the Object visibility to false first.

Object.Visible = false

//redraw your components

Object.Visible = true

I dont know if this is possible in your case but worth a try!

Haris
  • 915
  • 1
  • 11
  • 28
  • Thank you,can you explain more ! – sansat Aug 29 '12 at 12:15
  • Whats the name of the component you are trying to redraw? In the code above Object stands for the component you are trying to redraw. Set it first to Visibel.false and then perform your redrawing and finally set Object to visible again. – Haris Aug 29 '12 at 12:30
  • not its not solving problem flicking still there ! what i done object.Visible = false; this.object.Invalidate(); object.Visible = true; invalidate causes redraw – sansat Aug 29 '12 at 13:17
  • Have you tried SuspendLayout() and ResumeLayout() method? [MSDN link]http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx – Haris Aug 29 '12 at 13:27
  • what i found from debugging is Graphics.DrawLine() function taking lot of time when aero theme and very less when basic theme can any body guide how to improve – sansat Aug 29 '12 at 13:55
  • Haris, those won't do anything for owner-drawn controls. Drawing itself doesn't send any Layout events. – Joey Aug 30 '12 at 06:21
0

I think you need to use double buffer for you form object.

this.DoubleBuffered = true;
0

Well I found a workaround for the flickering problem. Just disable the desktop composition — you can do it either at application level or OS level.

For application level, go to exe file -> right click -> compatibility-> check disable desktop composition.

Foror OS level (and better visual appearance), start->right click computer -> properties -> Advance system settings -> Advance tab -> performance settings -> visual effects->custom-> uncheck Enable desktop composition.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
sansat
  • 11
  • 3
0

“works fine with Aero off” …sounds like a recourse issue to me…. Are you drawing in a paint event? If not where are you obtaining your graphics object from? You can programmatically disable desktop composition, I need it for some projects I do… but nothing related to drawing…

[DllImport("dwmapi.dll")]
private static extern int DwmIsCompositionEnabled(ref bool enabled);

const uint DWM_EC_DISABLECOMPOSITION = 0;
const uint DWM_EC_ENABLECOMPOSITION = 1;
[DllImport("dwmapi.dll", EntryPoint = "DwmEnableComposition")]
private static extern uint DwmEnableComposition(uint compositionAction);

usage:

 DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
devHead
  • 794
  • 1
  • 15
  • 38
  • just be sure to test if its Vista or Win7...XP will throw exception (API doesnt exist) – devHead Aug 30 '12 at 13:32
  • thank you, It works fine but some problems like notification coming and screen goes black for a second ,while window switches theme – sansat Aug 31 '12 at 11:54