.NET

Reply
Active Contributor
Littlerubarbwk
Posts: 38
Registered: ‎09-08-2006
Message 1 of 13 (250 Views)

RBG value from color dialog

250 Views, 12 Replies
09-27-2006 12:23 PM
Can someone point me in the right direction for pulling the RGB value from the color dialog and pass them on to a windows form background color?
Active Contributor
ahmed.felix
Posts: 38
Registered: ‎08-31-2006
Message 2 of 13 (250 Views)

Re: RBG value from color dialog

09-29-2006 10:37 AM in reply to: Littlerubarbwk
I'm not sure if I get your question right but maybe it's this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dlgColor As New ColorDialog
dlgColor.ShowDialog()
Me.BackColor = dlgColor.Color
End Sub

This passes the color value to the form that loads at startup. If you need it in another form just instantiate it: formX=new Form and set the color to it.
Active Contributor
Littlerubarb
Posts: 31
Registered: ‎01-15-2003
Message 3 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 07:03 AM in reply to: Littlerubarbwk
Not exactly, Here's what I'm trying to do.
I have a color swatch on a user form that needs to change color when the user picks a color from the AutoCAD color dialog. The problem I've ran into is that AutoCAD uses it own color system ACI and I need to convert this to RGB for the color swatch. I could do it by creating a spread sheet with all 256 ACI Color number and RGB reference but I was hoping their is a easier way.
Distinguished Contributor
saluki
Posts: 188
Registered: ‎09-18-2005
Message 4 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 07:43 AM in reply to: Littlerubarbwk
This may help you out . . .

http://discussion.autodesk.com/thread.jspa?messageID=414913
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 5 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 07:46 AM in reply to: Littlerubarbwk
There is a type defined, Autodesk.AutoCAD.Colors.
This type has some shared methods, like 'FromColorIndex(colorMethod,colorIndex)' where color method is the enum type ColorMethod which defines among others 'ByAci', and colorIndex is of numerical type Short.
This method returns a Autodesk.AutoCAD.Color object.
The Autodesk.AutoCAD.Color type defines Red,Blue,Green as byte.
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 6 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 07:46 AM in reply to: Littlerubarbwk
You need to pull the RGB values from the color.

MsgBox(dlgColor.Color.ColorValue.R.ToString & ", " & dlgColor.Color.ColorValue.G.ToString & ", " & dlgColor.Color.ColorValue.B.ToString)
Active Contributor
Littlerubarbwk
Posts: 38
Registered: ‎09-08-2006
Message 7 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 09:04 AM in reply to: Littlerubarbwk
Here's what I've tried, this returns The ACI...

I've tried all these solutions to no return...Thanks for The table one less thing if I'm forced to use it

Now if I set Autodesk.AutoCAD.Colors.Color.FromRGB it return random colors..

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CD As New Autodesk.AutoCAD.Windows.ColorDialog()
Dim C As Autodesk.AutoCAD.Colors.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1) 'Set color to RED
Dim PENN As Object
CD.Color = C
CD.SetDialogTabs(Autodesk.AutoCAD.Windows.ColorDialog.ColorTabs.ACITab Xor Autodesk.AutoCAD.Windows.ColorDialog.ColorTabs.ColorBookTab)
If CD.ShowDialog <> Windows.Forms.DialogResult.OK Then
End If
PENN = CD.Color.ToString
TextBox2.Text = PENN

End Sub
Active Contributor
Littlerubarbwk
Posts: 38
Registered: ‎09-08-2006
Message 8 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 09:09 AM in reply to: Littlerubarbwk
Just to Clarify

When I approached this I though ha just set r to string ... and so on..
Boy was i wrong it keeps on returning random colors and numbers.. Give it a try
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 9 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 10:35 AM in reply to: Littlerubarbwk
This works.....

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CD As New Autodesk.AutoCAD.Windows.ColorDialog
CD.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1)
CD.SetDialogTabs(Autodesk.AutoCAD.Windows.ColorDialog.ColorTabs.ACITab)
Dim dr As DialogResult = CD.ShowDialog
If dr = DialogResult.OK Then
MsgBox(CD.Color.ColorValue.ToString, MsgBoxStyle.OkOnly, "ColorInfo")
End If
End Sub

note on : CD.Color.ColorValue
ColorValue is a system.drawing.color type and can be used directly in coltrols and such
Active Contributor
Littlerubarbwk
Posts: 38
Registered: ‎09-08-2006
Message 10 of 13 (250 Views)

Re: RBG value from color dialog

10-03-2006 12:12 PM in reply to: Littlerubarbwk
Thanks, that what I was missing...
I'll repost the code in a minute..
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.