how can I use the line contorl like VB?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how can I use the line contorl like VB? or draw a line on the Form
thank you!
 
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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top