Results 1 to 5 of 5

Thread: Pen color selection

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Pen color selection

    Hey everyone!!

    Just a quick question.
    I've drawn about 3 lines on form using pen.
    line1 pen1
    line2 pen2
    line3 pen3

    On the form i've put a menustrip to enable users to select different colors for each line. How do i code this in vb.net 2005.

    Thank you

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Pen color selection

    Do want like a color Dialog, or random colors ¿
    VB.NET MVP 2008 - Present

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: Pen color selection

    Like a color dialog HanneSThEGreaT

  4. #4
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Pen color selection

    OK, Then you can do something like :

    Code:
     Private cColor As Color 'Selected Color To Draw With
          'Create A New ColorDialog Object
            Dim CColorD As New ColorDialog
    
            'Settings For CColorD
            'Open Full Dialog Box
            CColorD.FullOpen = True
    
            'Do Not Display Help Button On TitleBar
            CColorD.ShowHelp = False
    
            'Display All Available Colors
            CColorD.AnyColor = True
    
            'If OK Is Selected On The Color DialogBox
            If (CColorD.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
                'Change The Selection Color To The User Specified Color.
                cColor = CColorD.Color
            Else
                'Cancel Was Clicked, return To default
                cColor = System.Drawing.Color.Black
            End If
    I've declared the cColor variable as a modular variable, you can of course make it Public / or local (Dim)

    Then draw the line, here's an example :
    Code:
     Dim pLinePen As New Pen(cColor, 1) 'you can use whatever width, I've used 1
    e.Graphics.DrawLine(pLinePen, sStartX, sStartY, sEndX, sEndY)
    I hope it helps!
    VB.NET MVP 2008 - Present

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: Pen color selection

    Thanks HanneSThEGreaT, i'll try this just now, it looks quite logical and i don't see why it wouldn't work.

    Once again, Thanks Man!!

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