|
-
May 16th, 2004, 11:47 AM
#1
Thread Starter
Fanatic Member
How to get color value from colordialog
I am very new in Vb.NET ..
I need to save color value to a table, How to get the value of color?
Dim MyDialog As New ColorDialog
' Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = False
' Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = True
' Sets the initial color select to the current text color,
MyDialog.Color = LblPreviewColor.ForeColor
' Update the text box color if the user clicks OK
If (MyDialog.ShowDialog() = DialogResult.OK) Then
LblPreviewColor.ForeColor = MyDialog.Color
' How to get the color value??
End If
I need advice .. thanks
Winanjaya
-
May 16th, 2004, 06:16 PM
#2
Lively Member
Hi
This works for me, just modify it to your needs.
Code:
'Open the color dialog control
With ColorDialog
'Get the current color from the picturebox
.Color = Me.picCropColor.BackColor
If .ShowDialog = DialogResult.OK Then
Try
'Place the color in the picbox
Me.picCropColor.BackColor = ColorDialog.Color
Dim colour As Integer = ColorTranslator.ToWin32(ColorDialog.Color)
Me.lblColor.Text = colour.ToString
Catch
Dim Msgbox As MessageBox
Msgbox.Show("Error! " & vbCrLf & "An error has occured while trying to set the color to the controls", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
'Now exit
End
End Try
End If
End With
-
May 17th, 2004, 05:00 AM
#3
Thread Starter
Fanatic Member
Thanks.
Dim colour As Integer = ColorTranslator.ToWin32(ColorDialog.Color)
this will return a long type variable and then I save it to a table..
but when I recall it from table, how to implement it to "lblColor.ForeColor"
I need advice .. many thanks in advance
Regards
Winanjaya
-
May 17th, 2004, 05:41 AM
#4
Lively Member
Hi
To retrieve the colour and set a label or column in a listview you do:
Code:
'Retrieve the color from the stored integer value
Dim colour As ColorTranslator
osItem.BackColor = colour.FromWin32(CInt(drv("GrainColour").ToString))
This is for a listview but you would replace osItem.BackColor with Label1.BackColor or whatever. I've stored the integer value in the field drv("GrainColour")
You'll have to change that to your setup.
Last edited by Wallabie; May 17th, 2004 at 05:45 AM.
-
May 17th, 2004, 07:35 AM
#5
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|