Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic CustomDraw Bug? Draw handler gets fired continuously. (Read 3625 times)
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
CustomDraw Bug? Draw handler gets fired continuously.
Oct 23rd, 2012 at 1:09pm
Print Post  
Hi there,

I was wondering why some strange things happened in my application. I found out that the Draw event handler gets fired continuously when I'm using this code:

Code (C++)
Select All
            calendar1.CustomDraw |= CustomDrawElements.ResourceViewItem;
            calendar1.Draw += delegate(object sender, DrawEventArgs e)
                                  {
                                      //propertyGrid1.SelectedObject = e;

                                      if (e.Element == CustomDrawElements.ResourceViewItem)
                                      {
                                          counter++;
                                          ClientApplication.INSTANCE.AppFrame.StatusBar.Status = counter.ToString();

                                          int distance = e.GetDistance(sender as Calendar, e.Item.StartTime.AddHours(3));
                                          if (distance >= 0)
                                          {
                                              e.Graphics.DrawLine(Pens.Aquamarine, e.Bounds.Left + distance, e.Bounds.Top,
                                                                  e.Bounds.Left + distance, e.Bounds.Bottom);
                                          }
                                      }

                                  };
 



The counter variable is static to monitor the calls. In 10 seconds the counter was at about 500  Shocked

Any help on this?

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: CustomDraw Bug? Draw handler gets fired continuously.
Reply #1 - Oct 23rd, 2012 at 3:22pm
Print Post  
Hi,

I presume that the items are getting repainted as a result of the mouse being moved within the control. You can turn this off by disabling the extended item styles (Calendar.ItemSettings.UseExtendedStyles = Disabled). I will see if we can improve this by repainting the items only when they actually change state during mouse moves.

If the event is raised even when the mouse is not moved, there must be some code that causes the control to repaint. In this case, I will appreciate it if you can send me a small application, which reproduces this issue.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: CustomDraw Bug? Draw handler gets fired continuously.
Reply #2 - Oct 24th, 2012 at 7:34am
Print Post  
Hi Meppy,

I made a small test application and everything worked fine. After a little search I found out, that the double buffering feature in my application caused the continuous firing of the paint event (but only after an item was created in the ResourceView).

Code (C++)
Select All
        protected override CreateParams CreateParams
        {
            //NOTE: this is taken from: http://www.angryhacker.com/blog/archive/2010/07/21/how-to-get-rid-of-flicker-on-windows-forms-applications.aspx

            get
            {
                if (ClientApplication.INSTANCE.EnableDoubleBuffer)
                {
                    // Activate double buffering at the form level.  All child controls will be double buffered as well.
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
                    return cp;
                }

                return base.CreateParams;
            }
        } 



For now I disabled the double buffer feature. Maybe you can test it and find the reason why the ResourceView does not work with this.

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: CustomDraw Bug? Draw handler gets fired continuously.
Reply #3 - Oct 24th, 2012 at 8:08am
Print Post  
Hi again,

Are you sure that the double-buffering flag alone causes the Draw event to be raised continuously? Turning this flag on in my application seems to have no effect on the event.

In any case, we have made some improvements to how items are repainted during mouse moves. Repaints should now only occur when an item actually changes its state. Trial version of the new assemblies can be downloaded from here.

You can also try setting Calendar.EnableOptimization to true. This will cause items to be cached and they will be repainted only when their appearance or size changes.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: CustomDraw Bug? Draw handler gets fired continuously.
Reply #4 - Oct 26th, 2012 at 8:12am
Print Post  
Hi Meppy,

hm. It seems to be a combination of the double buffering feature and anything else in my application but I have not found it yet. I've tried the EnableOptimization flag but then my custom drawing produce weird results.

So far I disabled the double buffering which works fine for me. Maybe after my holidays I'll go back on it and try to find out what in combination with double buffering makes the event go wild.

I also have to try the new assemblies and test the redrawing in combination with my custom drawings on the items.

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint