Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

phillip Restall
  • Leaders
Posted
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?
[sIGPIC]e[/sIGPIC]
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...