2 Replies - 8946 Views - Last Post: 05 July 2010 - 11:28 PM Rate Topic: -----

#1 Eagles05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 01-November 09

Drawing a Straight Line

Posted 03 November 2009 - 09:35 PM

Ok. I know this is a basic question :rolleyes:
But it seems I completely forgot how to do this.

I know how to do a diagonal line.

 grph.DrawLine(pen2, 0, 0, 100, 100); 


I really don't understand the concepts of the x and y coordinates, so can someone please show me how to draw a straight line. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Drawing a Straight Line

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 942
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Drawing a Straight Line

Posted 03 November 2009 - 09:46 PM

Think of a sheet of graph paper. The X coordinate starts on the left side of the paper and as you increase X it moves farther to the right. The Y coordinate is a little backward from the X and Y axises in math. Y starts at the top of the page and as Y increases it moves down the page.

To draw a straight horizontal line you would keep the Y coordinate the same for both points in the line. That means that X changes and Y doesn't

grph.DrawLine(pen2, 0, 100, 100, 100);



That would draw a line across the screen 100 pixels down the screen.

To draw a straight vertical line you would keep the X coordinate the same for point points in the line. That means that Y changes but X doesn't/

grph.DrawLine(pen2, 100, 0, 100, 100);



That would draw a vertical line 100 pixels in from the left edge of the screen.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Nagendra*


Reputation:

Re: Drawing a Straight Line

Posted 05 July 2010 - 11:28 PM

View PostSixOfEleven, on 03 November 2009 - 08:46 PM, said:

Think of a sheet of graph paper. The X coordinate starts on the left side of the paper and as you increase X it moves farther to the right. The Y coordinate is a little backward from the X and Y axises in math. Y starts at the top of the page and as Y increases it moves down the page.

To draw a straight horizontal line you would keep the Y coordinate the same for both points in the line. That means that X changes and Y doesn't

grph.DrawLine(pen2, 0, 100, 100, 100);



That would draw a line across the screen 100 pixels down the screen.

To draw a straight vertical line you would keep the X coordinate the same for point points in the line. That means that Y changes but X doesn't/

grph.DrawLine(pen2, 100, 0, 100, 100);



That would draw a vertical line 100 pixels in from the left edge of the screen.



Thanks Alot this information Help me to understand X P Coordinate
there Provided information is very useful
I have made crossing Vertical and Horizontal Lines
code is Given below

Bitmap img = new Bitmap(100, 100);
System.Drawing.Graphics g = Graphics.FromImage(img);
Pen drawingPen = new Pen(Color.Black, 3);

//Vertical Line
//g.DrawLine(pen2, x1, y1, x2, y2);
g.DrawLine(drawingPen, 50, 20, 50, 80);

//Horizontal Line
g.DrawLine(drawingPen, 10, 0,30, 0);

//Horizontal Line
g.DrawLine(drawingPen, 5, 50, 60, 50);


pictureBox1.BackColor = Color.White;
pictureBox1.Image = img;
Was This Post Helpful? 0

Page 1 of 1