Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# GDI+
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 4-Dec-10 21:56pm
Bezawit460
Edited 4-Dec-10 23:22pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 5 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100