Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys. I am using a UserControl to load a .tif file on it. After that I am using the GDI API to draw lines and rectangles on top of the Image loaded into the UserControl. So far that is working fine. But the thing is, when ever I draw a new Rectangle/Line on on the UserControl, the UserControl is Invalidated and is repainted. The Rectangles/Lines should be redrawn and that is the case. But the Image need not be redrawn again. For one thing, the Image doesn't change once it is loaded. Second, the size of the image is well above 100MB so repainting it every time I call Invalidate() is making my application slow.

I know there is a way to make OnPaint() to paint only the specific part of the UserControl but the thing is, the TIF image and the other shapes are drawn on the same area. i.e the image is drawn first and on top of it the shapes. It is like there is a layering. What I am trying to do is to force Invalidate() to repaint only the shapes on the upper layer without going all the way to down to the image. As far as I know GDI doesn't have a 'Z' coordinate like that in OpenGL. Which means, I won't be able to tell my application not to repaint the image.
So, if you know a workaround to this problem, I would greatly appreciate it.

Thanks in advance
Posted
Updated 4-Dec-10 22:22pm
v2

Please see also the SetStyles method of a Control class to set the ControlStyles[^].

By using these styles, you can control various things like background painting (See the Opaque enum member).

Cheers
Uwe
 
Share this answer
 
You could override the OnPaintBackground() function to control what/when it does its painting. Here[^] is a link to the MSDN, there is a note to inheritors about not calling the base.
 
Share this answer
 
v2
Well, there are already 2 layers on every Control: the one painted by OnPaint and the one painted by OnPaintBackground. So, you can simply load your Image as the Control's BackgroundImage and draw all the other stuff in OnPaint.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900