phillip Posted September 15, 2005 Posted September 15, 2005 Hi I want to be able to draw some lines (Any angle) then perform an operation based on which one i've click. I can draw the lines using GDI but how would i know if ive clicked on one? Phill Quote phillip Restall
Leaders snarfblam Posted September 15, 2005 Leaders Posted September 15, 2005 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? Quote [sIGPIC]e[/sIGPIC]
phillip Posted September 15, 2005 Author Posted September 15, 2005 I found this which looks like what i need but im using Vb :o http://www.bobpowell.net/hittestlines.htm Phill Quote phillip Restall
Leaders snarfblam Posted September 15, 2005 Leaders Posted September 15, 2005 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. //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 //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 I'm not going to translate everything, not to be difficult, but because I don't have time and that isn't what these forums are for. Maybe someone else feels like being nicer. Quote [sIGPIC]e[/sIGPIC]
phillip Posted September 15, 2005 Author Posted September 15, 2005 I'm not after a free ride, I'll try to do it myself. Thanks for your help :) Phill Quote phillip Restall
PROKA Posted September 26, 2005 Posted September 26, 2005 Next time use this translator and lose no time at all :) Quote Development & Research Department @ Elven Soft
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.