|
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
{
public Rectangle Rect;
public void DrawObject(Graphics g)
{
}
}
ArrayList paintedObjects = new ArrayList();
protected override void OnPaint(PaintEventArgs e)
{
foreach (PaintObject obj in paintedObjects)
{
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.
|
|
|
|
|
hmmmm, i guess this will not work in my case.
Imagine the following example:
I have a gauge on the screen (in fact 4 of them), with an arrow in the middle.
To reduce CPU load, i divided the gauge into 4 parts (quarters).
Befor Invalidation, I check the arror position and recalc the invalidation rectangle,
means: the quarter to be redrawn, the reminder (three) quarters of the gauge is beeing left, since there would be no change.
The gauge depends on the Form size (height, width).
Everything I have is now:
- the gauge's size (complete)
- the gauges' invalidation region (rectangle) to be redrawn
I must be dump like hell, but I cannot figure out, how your idea would work in my case :´-(
|
|
|
|
|
OK, that makes more sense now. Similar to how I thought it was originally, but not quite. The way you describe it, I don't see how it would work directly - plus invalidating a quarter of each gauge will end up creating a clip rectangle that covers most of the form (since each invalidated region gets added together to create a single rectangle).
However, you could probably still make it work with a bit more work on your part. Instead of drawing them all in the form's paint event, create a user control that encapsulates a single gauge. This will probably be a bit better anyway, as it could better handle some requirements changes (ie - what happens when the user decides that one of the gauges isn't important and wants it removed, or wants to add more, or even wants to adjust it dymanically).
The same concept applies to user controls as it does to forms - the paint event gets the same arguments and can be used in the same way. And once you have it narrowed down to a single gauge, then you're back to where we were, and you can begin to look at the clip region again to minimize drawing.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
hi,
i have to display date in the format as follows, mm.dd.yyyy( e.g. 12.31.2006)
How i will be able to do it in asp.net web application using c#?
yog
hui gfgh kgdgrt njjn hjgkn
|
|
|
|
|
yogita charhate wrote: i have to display date in the format as follows, mm.dd.yyyy( e.g. 12.31.2006)
How i will be able to do it in asp.net web application using c#?
This can be done in any C# application (ASP.NET is just a framework for designing web applications)
DateTime myDateTime = DateTime.Now;
string displayDate = myDateTime.ToString("MM.dd.yyyy");
|
|
|
|
|
Thank you very much Colin, I've successfully completed the functionality.
have a nice day!!!!!!!!!
yog
hui gfgh kgdgrt njjn hjgkn
|
|
|
|
|
i want to write the Nonrectangular form in c#.net 2005 .
in c# 2003 set FormBorderStyle to None and set BackgroundImage to file that shown as background then set TransparencyKey property to backcolor of BackgroundImage but this doesn't work in c# 2005 .
i don't want to use GDI+ and Region property of form .
please help me.thanks.
|
|
|
|
|
you can overwrite the OnPaint method:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
Point[] points = new Point[6];
points[0] = new Point(0, 0);
points[1] = new Point(this.Width, 0);
points[2] = new Point((this.Width/2)+1, this.Height/2);
points[3] = new Point(this.Width, this.Height);
points[4] = new Point(0,this.Height);
points[5] = new Point((this.Width / 2) - 1, this.Height / 2);
shape.AddPolygon(points);
this.Region = new System.Drawing.Region(shape);
}
... and you will have a glasshour shaped form...
|
|
|
|
|
In form i have different object (like picturebox),i want to acces these object from another class for example class1
|
|
|
|
|
This is essentially the same question you asked before[^] and the results will be the same because the object you are trying to access is not instantiated because you are not fully instantiating the form the object comes from.
So far you have not told us the overall goal of your application is, of even this part of the application. I think that there is a better way to do what you are trying to do because from the description you have supplied so far I cannot invisage that the application is designed very well.
|
|
|
|
|
Accessing an object properties or methods from another form is unallowed in a direct way. This is because when the compiler creates those objects, they are declared as private so u can not access it from outside the scope where it is created.
u can pass over this in one solution, this is by definning some public function in that form tha do the actions u need in the properties of those objects. And u should pass a reference of the first form to the second form through the constructor of the second form.
hope it helps.
best regards
Jamil Abou Khalil
|
|
|
|
|
signimage wrote: In form i have different object (like picturebox),i want to acces these object from another class for example class1
The default access/visibility level of the form's objects is private . To use your form's objects in another class, you have to change its access level from private to public (or what is more appropriate) through its Modifiers property.
________________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
you should declare object public in partial class and formName.objectName acces object .
|
|
|
|
|
hi
i want to use TableAdapter in VC# 2005,how to use ??
does anybody know or have an article for this topic ?
thanks
|
|
|
|
|
The table adapter is used to get data from database and put it inside a table with the help of the data set. tell us what u specifically need from this object and i may provide u with some help.
best regards
jamil abou khalil
|
|
|
|
|
Hi,
How can I convert char[] to byte[] without loss of data?
Regards,
Hemant.
|
|
|
|
|
How can I convert char[] to byte[] without loss of data?
typecast it
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
char[] c = new char[2] { 'a', 'b' };
byte[] b = System.Text.Encoding.ASCII.GetBytes(c);
|
|
|
|
|
That depends on how you want to convert it.
The char data type is a 16 bit unicode character. Unless you have restricted the characters to use only ASCII characters, each character can not be converted to a byte.
If you want to convert the string to it's encoded format, you can use the GetBytes method of the encoding you want to use. Example:
byte[] data = Encoding.UTF8.GetBytes(theChars);
---
b { font-weight: normal; }
|
|
|
|
|
Hi all,
Is any body provide me information about IpAddress control in C#. i couldn't find any thing
|
|
|
|
|
IPAddress Class[^]
If you're looking for an UI control that lets you specify an IP address there isn't one in the .NET Framework class library AFAIK. But there should be some custom controls for it out in the internet. I think there even was an article here on CP presenting such a control.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
In my project two forms(form1 and form2)
when from form1 i try to Access any object of from2 then it give me error that object reference not set to an instance of object,
me using following way
in form1 i create the obg of from2 as
from2 f=new fomr2();
Bitmap b=(Bitmap)f.pictureBox1.Image;
if(b.GetPixel(100,100)==-1)
{//code}
it give the abovemention error in if statement when i try to accec the pixels of that object.
What should i do?????????
|
|
|
|
|
Just by instantiating the form does not necessarily mean that the picture box will have anything in it. Thefore the error is correct.
Where does the picture box get its image? Once you have the answer to that then you know what else you need to instantiate in order to get your code to work.
|
|
|
|
|
PictureBox take its image from file and i m sure that pictureBox has its image,this is not empty pictureBox but still it give thte above mentioned error
|
|
|
|
|
signimage wrote: PictureBox take its image from file and i m sure that pictureBox has its image,this is not empty pictureBox but still it give thte above mentioned error
Obviously, it is an empty picture box at the time you are running your code otherwise you would not be getting the error.
Since you don't seem to be doing anything else with the form (at least from the code you provided) then I would suggest that you probably don't need the form anyway. Perhaps you just need to instantiate a Bitmap with the relevant file and use that.
|
|
|
|