Click here to Skip to main content
16,005,141 members
Home / Discussions / C#
   

C#

 
QuestionHigh CPU load caused by this.Invalidate(myRegion); [modified] Pin
Mike Novy8-Nov-06 1:33
Mike Novy8-Nov-06 1:33 
AnswerRe: High CPU load caused by this.Invalidate(myRegion); Pin
vineas8-Nov-06 4:27
vineas8-Nov-06 4:27 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
Mike Novy8-Nov-06 5:48
Mike Novy8-Nov-06 5:48 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
vineas8-Nov-06 6:49
vineas8-Nov-06 6:49 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); [modified] Pin
Mike Novy8-Nov-06 7:44
Mike Novy8-Nov-06 7:44 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
vineas8-Nov-06 8:06
vineas8-Nov-06 8:06 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
Mike Novy8-Nov-06 8:46
Mike Novy8-Nov-06 8:46 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
vineas8-Nov-06 9:20
vineas8-Nov-06 9:20 
This isn't quite what you were indicating initially - from you initial post you indicated that you had a form with several objects in them (graphs, and I don't remember what else). Since each object only takes up a small portion of the form, invalidating small portions of the form (and therefore a subset of all drawn objects) is possible. If this isn't the case, then this isn't really the correct method for doing so (it could be done, but gets much more complicated).

When you call this.Invalidate(myRegion), internally it will convert the region into a rectangle, and then flags the windows sub-system that the form needs to be painted. When the paint event is raised, this rectangle is passed in as the PaintEventArgs.ClipRectangle and is setup as a clipping region in the PaintEventArgs.Graphics object.


Here's what I'm trying to advocate as the next step (very simplified code, should be enough to get the gist of it):
class PaintObject // place holder object - this would be whatever object you use to paint with
{
	public Rectangle Rect; // this is be the rectangle that fully contains the drawn object.
	public void DrawObject(Graphics g)
	{
		// TODO: draw the object to the Graphics object
	}
}

ArrayList paintedObjects = new ArrayList();
protected override void OnPaint(PaintEventArgs e)
{
	foreach (PaintObject obj in paintedObjects)
	{
		// only paint those items that are in the clipping region.
		if (e.ClipRectangle.IntersectsWith(obj.Rect) || e.ClipRectangle.Contains(obj.Rect))
			obj.DrawObject(e.Graphics);
	}
	base.OnPaint(e);
}


Note that anything that is either fully contained in the clipping region or touches the clipping region in any way is redrawn using this method. Also note that none of your other code changes - correctly calling this.Invalidate(myRegion) is the key to this entire process, as it is the source of the clipping rectangle and what tells the form that it needs to paint.

-----
In the land of the blind, the one eyed man is king.

GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
Mike Novy8-Nov-06 9:52
Mike Novy8-Nov-06 9:52 
GeneralRe: High CPU load caused by this.Invalidate(myRegion); Pin
vineas8-Nov-06 10:46
vineas8-Nov-06 10:46 
Questionhow to get a date format mm.dd.yyyy( e.g. 12.31.2006) Pin
yogita charhate8-Nov-06 0:36
yogita charhate8-Nov-06 0:36 
AnswerRe: how to get a date format mm.dd.yyyy( e.g. 12.31.2006) Pin
Colin Angus Mackay8-Nov-06 0:44
Colin Angus Mackay8-Nov-06 0:44 
GeneralRe: how to get a date format mm.dd.yyyy( e.g. 12.31.2006) Pin
yogita charhate8-Nov-06 1:27
yogita charhate8-Nov-06 1:27 
QuestionHow Create Nonrectangular form in c#.net 2005 Pin
mohammadSoft8-Nov-06 0:30
mohammadSoft8-Nov-06 0:30 
AnswerRe: How Create Nonrectangular form in c#.net 2005 Pin
c_onica8-Nov-06 2:14
c_onica8-Nov-06 2:14 
QuestionHow to access from objects from other class Pin
signimage8-Nov-06 0:26
signimage8-Nov-06 0:26 
AnswerRe: How to access from objects from other class Pin
Colin Angus Mackay8-Nov-06 0:42
Colin Angus Mackay8-Nov-06 0:42 
AnswerRe: How to access from objects from other class Pin
quiteSmart8-Nov-06 0:56
quiteSmart8-Nov-06 0:56 
AnswerRe: How to access from objects from other class Pin
Mairaaj Khan8-Nov-06 1:07
professionalMairaaj Khan8-Nov-06 1:07 
AnswerRe: How to access from objects from other class Pin
mohammadSoft8-Nov-06 1:38
mohammadSoft8-Nov-06 1:38 
Questionhow to use TableAdapter in VC# 2005 ? Pin
hdv2128-Nov-06 0:26
hdv2128-Nov-06 0:26 
AnswerRe: how to use TableAdapter in VC# 2005 ? Pin
quiteSmart8-Nov-06 1:02
quiteSmart8-Nov-06 1:02 
Questionhow to convert char[] to byte[] without loss of data Pin
Hemant kulkarni7-Nov-06 23:52
Hemant kulkarni7-Nov-06 23:52 
AnswerRe: how to convert char[] to byte[] without loss of data Pin
ThatsAlok8-Nov-06 0:01
ThatsAlok8-Nov-06 0:01 
AnswerRe: how to convert char[] to byte[] without loss of data Pin
stancrm8-Nov-06 0:35
stancrm8-Nov-06 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.