Results 1 to 3 of 3

Thread: Color to hex

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    57

    Question Color to hex

    I'm not finding the correct syntax. This is what I have...

    Code:
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            If Pathstr <> "" Then
                Dim bitmap As New Bitmap(Pathstr)
                Dim LocalMousePosition As Point
                LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)
                bgc = bitmap.GetPixel(LocalMousePosition.X, LocalMousePosition.Y)
                Label12.BackColor = bgc
            Else
                MsgBox("Please Drop an image before choosing color")
            End If
            ColorDialog1.Color = bgc
            ColorDialog1.FullOpen = True
            If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
                Label12.BackColor = ColorDialog1.Color
            End If
            Dim intColor2Dec As Integer
            intColor2Dec = Convert.ToInt32(bgc)
            TextBox1.Text = Microsoft.VisualBasic.Conversion.Hex(intColor2Dec)
        End Sub
    The Bold is where I am failing to convert to hex. What can I do to get this right?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Color to hex

    Well, bgc is a color, which has a .ToARGB method, which returns an integer, that can be converted to a string with .ToString("X"), so it seems like all you'd need is:

    TextBox1.Text = bgc.ToARGB.ToString("X")

    I haven't tried it, though.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    57

    Re: Color to hex

    That was it. Thanks

Tags for this Thread

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