Results 1 to 5 of 5

Thread: draw a line and save to memory for reuse

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    draw a line and save to memory for reuse

    $50 US/AU via PP for someone to make me a project that will draw a line on a picture box.

    After drawing the line, the line properties (length, direction) will need to be saved to memory so the user can then click on a new location and a new line identical will be drawn, this needs to continue until the user clicks a button to delete the line from the memory.

    pm me for skype name

    toe

  2. #2

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: draw a line and save to memory for reuse

    i have a taker, i will mark as resolved after deal is done

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: draw a line and save to memory for reuse

    $50 for that? That's a minute's work. All you need is a Point and a Size to represent the line. The Point is where it starts and the Size is the length in the X and Y directions. If you want to reproduce the line in another location you simply use a different Point with the same Size.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: draw a line and save to memory for reuse

    yer maybe, i spent 4 hours yesterday and counldnt work it out.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: draw a line and save to memory for reuse

    I'm guessing that this is not perfect but it took about 15 minutes:
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private lineTemplate As Line
    4.     Private isDrawing As Boolean = True
    5.     Private origin As Point
    6.     Private lines As New List(Of Line)
    7.  
    8.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    9.         Me.lineTemplate = Nothing
    10.     End Sub
    11.  
    12.     Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
    13.         If Me.lineTemplate Is Nothing Then
    14.             Me.isDrawing = True
    15.             Me.origin = e.Location
    16.         End If
    17.     End Sub
    18.  
    19.     Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
    20.         If Me.isDrawing Then
    21.             Me.isDrawing = False
    22.             Me.lineTemplate = New Line With {.Origin = Me.origin, .Offset = New Size(e.X - Me.origin.X, e.Y - Me.origin.Y)}
    23.             Me.lines.Add(Me.lineTemplate)
    24.             Me.PictureBox1.Refresh()
    25.         End If
    26.     End Sub
    27.  
    28.     Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
    29.         If Not Me.isDrawing Then
    30.             Me.lines.Add(New Line With {.Origin = e.Location, .Offset = Me.lineTemplate.Offset})
    31.             Me.PictureBox1.Refresh()
    32.         End If
    33.     End Sub
    34.  
    35.     Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
    36.         For Each line As Line In me.lines
    37.             e.Graphics.DrawLine(Pens.Black,
    38.                                 line.Origin.X,
    39.                                 line.Origin.Y,
    40.                                 line.Origin.X + line.Offset.Width,
    41.                                 line.Origin.Y + line.Offset.Height)
    42.         Next
    43.     End Sub
    44.  
    45. End Class
    46.  
    47.  
    48. Public Class Line
    49.     Public Property Origin As Point
    50.     Public Property Offset As Size
    51. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width