Results 1 to 4 of 4

Thread: Create custom line in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    1

    Create custom line in vb.net

    Is there a way to create custom lines in vb.net?
    I cannot find a way to do so and it would be really helpful if any of you could help me.
    Thank you.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Create custom line in vb.net

    Where do you want to draw the line? On your form? If so, you just use the form’s paint event. The eventargs has a graphics object. You use the graphics object drawline method...

  3. #3
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Create custom line in vb.net

    yes you can, as said by .paul. , you draw in the pain event : here is an example with the form1 paint event from https://www.worldbestlearningcenter....wing-lines.htm

    it works with all paint event of controls (picturebox, button, etc)

    Code:
    Private  Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint      
                                   
        'Create point objects      
        Dim pt As New Point(50, 50)      
        Dim pt1 As New Point(300, 50)      
        Dim pt2 As New Point(200, 70)      
        Dim pt3 As New Point(50, 170)      
        Dim pt4 As New Point(300, 170)      
        Dim pt5 As New Point(200, 70)      
    
        'Array of points      
        Dim pArra() As Point = {pt2, pt3, pt4, pt5}      
    
        'Draw a line      
        e.Graphics.DrawLine(Pens.Orange, pt, pt1)      
    
        'Draw multiple lines      
        e.Graphics.DrawLines(Pens.Blue, pArra)      
                 
    End Sub
    Last edited by Delaney; Nov 27th, 2020 at 04:41 AM.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Create custom line in vb.net

    Also, if you want to be interacting with the line, look into the GraphicsPath object. You can draw lines with that, and be better able to deal with mouse events.
    My usual boring signature: Nothing

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