4 Replies - 1958 Views - Last Post: 06 October 2012 - 08:12 AM Rate Topic: -----

#1 dcarp757  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
      lineCanvas.Children.Add(newLine)
   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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,773
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 dcarp757  Icon User is offline

  • New D.I.C Head

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

Re: point to point line draw problem?

Posted 03 October 2012 - 06:03 PM

View Postmaj3091, 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?
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,773
  • 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

Good luck solving your issue.

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

Was This Post Helpful? 1
  • +
  • -

#5 WiFi COMPUTER SYSTEM  Icon User is offline

  • New D.I.C Head

Reputation: -8
  • View blog
  • 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

Private Sub Form_Load()
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


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1