# point to point line draw problem?

Page 1 of 1

## 4 Replies - 2424 Views - Last Post: 06 October 2012 - 08:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294074&amp;s=6dcee78c84d74b986704cff87a8f7f04&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 dcarp757

Reputation: 0
• Posts: 9
• Joined: 02-September 12

# point to point line draw problem?

Posted 03 October 2012 - 05:11 AM

The assignment is to create a WPF then have the user click in two places and draw a straight connecting line. Also output the distance of the line in WPF. Im very close, but nothing happens when I click on canvas. Any help is appreciated.

```Class LineLengthWindow

Dim position1 As Point
Dim position2 As Point

Private Sub paintLine(ByVal lineColor As Brush, ByVal position As Point)

Dim newLine As Line = New Line()
newLine.Stroke = Brushes.Black
newLine.X1 = position1.X
newLine.X2 = position2.X
newLine.Y1 = position1.Y
newLine.Y2 = position2.Y
End Sub

Private Function Length() As Double
Dim xDistance As Integer = position1.X - position2.X
Dim yDistance As Integer = position1.Y - position2.Y

Return Math.Sqrt((xDistance ^ 2) + (yDistance ^ 2))
End Function ' end Length function

Private Sub lineCanvas_MouseLeftButtonDown(ByVal sender As Object, ByVal e _
As System.Windows.Input.MouseButtonEventArgs) Handles lineCanvas.MouseLeftButtonDown

' clear Label text content
lengthOutputLabel.Content = ""

' get x and y coordinates of mouse click
Dim mousePosition As Point = e.GetPosition(lineCanvas)
paintLine(Brushes.Black, mousePosition)

End Sub

Private Sub lineCanvas_MouseLeftButtonUp(ByVal sender As Object, ByVal e _
As System.Windows.Input.MouseButtonEventArgs) Handles lineCanvas.MouseLeftButtonUp

' get endpoints
Dim mousePosition As Point = e.GetPosition(lineCanvas)
paintLine(Brushes.Black, mousePosition)

' distance between two points
Dim dblDistance As Double = Length()

' draw line connecting the two points

' display distance in Label
lengthOutputLabel.Content = String.Format("{0:F}", dblDistance)

End Sub

End Class

```

```<Window x:Class="LineLengthWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Line Length" Height="300" Width="300">
<Grid>
<StackPanel Name="outputStackPanel" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<Label Height="Auto" Name="lengthLabel" Width="Auto">Length =</Label>
<Label Height="Auto" Name="lengthOutputLabel" Width="Auto"></Label>
</StackPanel>
<Canvas Name="lineCanvas" Margin="0" HorizontalAlignment="Right" Width="Auto" Background="White" />
</Grid>
</Window>

```

Is This A Good Question/Topic? 0

## Replies To: point to point line draw problem?

### #2 maj3091

• D.I.C Lover

Reputation: 309
• Posts: 1,847
• Joined: 26-March 09

## Re: point to point line draw problem?

Posted 03 October 2012 - 06:22 AM

You might be better contacting a mod to move this to the correct forum as it's not VB6 related and you'll get a better response in the correct forum.

### #3 dcarp757

Reputation: 0
• Posts: 9
• Joined: 02-September 12

## Re: point to point line draw problem?

Posted 03 October 2012 - 06:03 PM

maj3091, on 03 October 2012 - 06:22 AM, said:

You might be better contacting a mod to move this to the correct forum as it's not VB6 related and you'll get a better response in the correct forum.

I'm obviously a beginner. This is VB course work out of a VB book (Deitel VB 2008 3rd Ed). What forum do you suggest?

### #4 maj3091

• D.I.C Lover

Reputation: 309
• Posts: 1,847
• Joined: 26-March 09

## Re: point to point line draw problem?

Posted 04 October 2012 - 12:17 AM

I appreciate you're a beginner, hence my suggestion to contact a mod to move your post to the correct forum, so you can get more specific help.

This is the VB6 forum, so you would be better in the VB.Net forum

VB6 was late 1990's, anything VB 2003,2008, etc, is VB.NET

This post has been edited by maj3091: 04 October 2012 - 12:18 AM

### #5 WiFi COMPUTER SYSTEM

Reputation: -8
• Posts: 13
• Joined: 05-October 12

## Re: point to point line draw problem?

Posted 06 October 2012 - 08:12 AM

Quote

This Code Help To point to point Drawing

```Dim a As Boolean

Private Sub Form_DblClick()
Cls
End Sub

ScaleMode = vbpixel
a = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CurrentX = X
CurrentY = Y
a = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = "X :" & Str(X)
Text2.Text = "Y :" & Str(Y)
If a Then Line -(X, Y)
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = False
End Sub
```

Quote

This Program Helps To Create Point to Point Line Try !T

```Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Line -(X, Y)

End Sub

```