Draw Lines then click on one

phillip

Active member
Joined
Aug 28, 2003
Messages
37
Hi

I want to be able to draw some lines (Any angle) then perform an operation based on which one ive click.
I can draw the lines using GDI but how would i know if ive clicked on one?

Phill
 
What have you tried? You are keeping track of where the lines are, right? If your lines are a single pixel wide, do you have to click exactly on the line? Or close enough to it? Do you know the distance formula?
 
If you take a close look at some c# code, you will see that it can generally be converted to VB pretty easily. Knowing a little C++ (or C#) will help alot.
[VB]
//C#
public class Line
{
public Point StartPoint;
public Point EndPoint;
public int PenWidth;

public void DrawLine(Graphics g,Color c)
{
Pen p=new Pen(c,PenWidth);
g.DrawLine(p,StartPoint,EndPoint);
p.Dispose();
}

}

VB
Public Class Line
Public StartPoint As Point
Public EndPoint As Point
Public PenWidth As Integer

Public Sub DrawLine(ByVal g As Graphics, ByVal c As Color)
Dim p As New Pen(c, PenWidth)
g.DrawLine(p, StartPoint, EndPoint)
p.Dispose()
End Sub
End Class
[/VB]
[VB]
//C#
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
foreach(Line l in Lines)
l.DrawLine(e.Graphics,Color.Black);
}

VB
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
For Each l As Line In Lines
l.DrawLine(e.Graphics, Color.Black)
Next
End Sub
[/VB]

Im not going to translate everything, not to be difficult, but because I dont have time and that isnt what these forums are for. Maybe someone else feels like being nicer.
 
Back
Top