Windows Develop Bookmark and Share   
 index > Windows Forms General > Problem with the autoscroll and painting.
 

Problem with the autoscroll and painting.

Hi,
I wrote a small application which uses a panel with autoscroll, on which I draw a image. The image can be painted at diferent zoom values, and when I zoom in, a specified point from the image must be in the center of the panel ( that is, I zoom the image and the center of the picture will be always found in the center of the panel). To achieve this, when the zoom value is changed, I also modify the AutoScrollMinSize and AutoScrollPosition properties, to match the scrolls to the new image size and position.

The problem is that when I set the AutoScrollPosition property, the image found on the panel is automaticaly scrolled by the framework, to accomodate the new change of position of the scrolls. And this causes flicker on the image.

How can I stop the automatic scrolling of the image found on the panel ?
ZyZyX  Thursday, October 18, 2007 9:54 AM
then it may be simple enough - make bool field, let say

private bool DisablePaint = false;

and before you start changing scroller values set it to TRUE, after values changed set it to FALSE.

In OnPaint() method simply check:

if(DisablePaint)
return;
Sergey Galich  Monday, October 22, 2007 12:53 PM
If you want to get rid of flicker - set property DoubleBuffered = true.

Sergey Galich  Thursday, October 18, 2007 10:15 AM
It's not about double buffering here ( with double buffer activated is even worse ).

The problem is that the framework is scrolling automaticaly the contents of the panel when I change the values of the scroll bars, and right after I change the values of scrolls, I repaint the panel. So the panel is painted once by the framework with the old picture at different zoom and at the new position, and I am repainting once again with the new image at the new zoom.

So I want to disable the repainting made by the framework, when I change the values of the scrolls.
ZyZyX  Thursday, October 18, 2007 10:58 AM
then it may be simple enough - make bool field, let say

private bool DisablePaint = false;

and before you start changing scroller values set it to TRUE, after values changed set it to FALSE.

In OnPaint() method simply check:

if(DisablePaint)
return;
Sergey Galich  Monday, October 22, 2007 12:53 PM

Set the ScrollPosition back to Point(0,0) before painting the image then set the scrollbars' position to the center after painting.

JRQ  Monday, October 22, 2007 4:43 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom SDK Development on .Net (Best Practices)
• Convert VB Script to .DLL(URGENT)
• I want to set two textboxes and a hole or circle(at middle of button) on top of the button(whether it may be user defined or der
• vb.net msacces records + record
• Painting Multiple child controls
• ADO.net and MS Access Errors
• how to programmatically set column field(s) to read-only?
• Open EXE ie.Application as soon as Computer Starts
• Sequence Of Events
• Using EM_GETLINE