# Drawing a Straight Line

Page 1 of 1

## 2 Replies - 17508 Views - Last Post: 05 July 2010 - 11:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=136458&amp;s=a084c6a1634b2bb5ceb1814fc1dde75b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Eagles05

• New D.I.C Head

Reputation: 0
• 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
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

• Planeswalker

Reputation: 1055
• Posts: 6,643
• 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

Reputation:

## Re: Drawing a Straight Line

Posted 05 July 2010 - 11:28 PM

SixOfEleven, 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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }