Click here to Skip to main content
15,886,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys!
I'm a chinese guy, so sorry for my poor english, some question confused me for long time.blow is some code segment and the result image link.

1.
private void Form1_Paint(object sender, PaintEventArgs e)
{   

/*
I wanna draw a border around the form's client area, but the bottom and right border both are not show
*/


    Pen p = new Pen(Color.Blue, 1);
    e.Graphics.DrawRectangle(p, ClientRectangle);
<a href="http://hi.csdn.net/attachment/201106/8/896324_1307507275OFj1.png">http://hi.csdn.net/attachment/201106/8/896324_1307507275OFj1.png</a>}

2.
private void Form1_Paint(object sender, PaintEventArgs e)
{   
    Pen p = new Pen(Color.Blue, 5);
    e.Graphics.DrawRectangle(p, ClientRectangle);

/*
border size are not 5pixel, bottom and right border size are small then 
left and top border.
*/
<a href="http://hi.csdn.net/attachment/201106/8/896324_1307507323bfEw.png">http://hi.csdn.net/attachment/201106/8/896324_1307507323bfEw.png</a>
}

I wanna to know why produce those result, they are not expceted.

last question is about real rectangle RectangleF, how do GDI+ draw image in a RectangleF(11. 3, 11. 5, 22.7, 33.9).
and device unit is one pixel
Posted
Updated 3-Jul-11 16:46pm
v3

Simple enough. Your using the instance of the System.Drawing.Graphics class obtained from the event arguments of the System.Windows.Control.Paint event. The coordinate system in this case in defined by current client area of the control and the coordinate system origin is placed in the top left corner of this area with positive directions going right and down.

This coordinate system can be transformed by assigning the property System.Drawing.Graphics.Transform, see http://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform.aspx[^].

For detailed explanation and examples of transform matrices and coordinate systems see http://msdn.microsoft.com/en-us/library/aa1hw2kk.aspx[^].

A client coordinate can be converted to a screen coordinate system and back using methods System.Windows.Forms.Control.PointToScreen and System.Windows.Forms.Control.PointToClient, see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].

I don't understand how anything could be messed-up here, as it is easy to see even from experiments. I also don't quite understand the title of the questions. All coordinate systems are "real enough".

—SA
 
Share this answer
 
Simple enough. Your using the instance of the System.Drawing.Graphics class obtained from the event arguments of the System.Windows.Control.Paint event. The coordinate system in this case in defined by current client area of the control and the coordinate system origin is placed in the top left corner of this area with positive directions going right and down

yes, precede code is very simple, so i known it too, do you have see the result image.
 
Share this answer
 
Comments
Christian Graus 8-Jun-11 1:38am    
The word 'answer' means a solution to the question. So, push 'answer' to give an answer. The word 'comment' means to add something, like a question, to an answer. Hence, what you posted here, is a comment, and should have been done using the 'comment' button.
feihan 8-Jun-11 3:01am    
thanks, this is my first question, before this i just find some techniquearticle that i need, have a good day to you.
thanks codeproject's man!

i got it, becasue in gdi+ the graphics mode is GM_ADVANCE ,it's mean when you draw rectangle that are bottom-right inclusive, so if a rectangle dinfine in (0, 0, 100, 100), then gdi+ draw the rectangle border on rectangle(0, 0, 101, 101).

so the on_paint routine in .net form based application, if you write like this(
e.Graphics.DrawRectangle(Pens.Red, ClientRectangle);) the right he bottom side both are not be draw to the red color. because when using ClientRectangle(euqal GetClientRect retrieved) as the draw rectangle that has be explaned as Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width+1, ClientRectangle.Height+1) that is exceed the clip region.

please forgive me using incorrect grammar or world, i will try it alway.
 
Share this answer
 
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Blue, 5);
e.Graphics.DrawRectangle(p, new Rectangle(ClientRectangle.X ,ClientRectangle.Y , ClientRectangle.Width - pen.Width , ClientRectangle.Height - pen.Width);
}
 
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