how can I use the line contorl like VB?

  • Thread starter Thread starter Guest
  • Start date Start date
Hi flybird,

You can use the Graphics object to draw lines or any shape for that matter.

Eg. the following code in the form paint event draws a black line that
is 90 pix wide:

private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black, 1), 10, 10, 100, 10);
}

HTH,
APG
 
flybird said:
how can I use the line contorl like VB? or draw a line on the Form?
thank you!

You're referring to the VB 6 Line Control, right?

In .NET, you'll need to investigate the System.Drawing namespace and the
Graphics class, which includes the public method DrawLine. Here is a basic
example from the help:

[C#]
public void DrawLineFloat(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create coordinates of points that define line.
float x1 = 100.0F;
float y1 = 100.0F;
float x2 = 500.0F;
float y2 = 100.0F;
// Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
 
Back
Top