You may know all of this already, so please skip over it if it sounds familiar:
In Windows Forms programming, the coordinate system works like this. Let's saw you have a form that is 500 pixels wide by 300 pixels tall. The top left corner of the form's client area* will be (0,0), the origin. The bottom right corner is (500, 300).
* What's the client area? That's the part of the form
that you can usually draw on...it doesn't include the borders, the
titlebar, and min/max/close buttons.
That means that X increases from left to right, and Y increases from TOP to BOTTOM. This is different than you may used to.
In order to draw a line near the bottom of your form, the Y coordinate will tend to be larger. However, if it is too large, it will go off the edge of your form and won't be drawn. You can use the form's ClientRectangle.Height property to see how far down you can draw.
If you want to draw a line near the bottom of your form, try:
Point p5 = new Point(8, this.ClientRectangle.Height - 20);Point p6 = new Point(this.ClientRectangle.Width - 8, this.ClientRectangle.Height - 20);e.Graphics.DrawLine(Pens.CadetBlue, p5, p6);This will draw a line that is always 8 pixels from the left and right edges, and 20 pixels above the bottom edge.
Some other notes:
- Remember to call Dispose() on your MyBrush and MyPen.
- Or, you can use Brushes.Red and Pens.CadetBlue, and you won't have to call Dispose().
Here's a trick that may help: Add this code to the Forms OnMouseMove event handler:
private void Form1_MouseMove(object sender, MouseEventArgs e){ this.Text = e.Location.ToString();}This will show the mouse's current coordinates in the titlebar of the form, in client coordinates.
Hope this helps,
-- Tim Scott
http://geekswithblogs.net/tscott
>>> Please remember to mark answers <<<