.NET

Reply
Active Contributor
38 Posts
0 Kudos
Registered: ‎09-08-2006
Post 1 of 13

RBG value from color dialog

258 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
38 Posts
0 Kudos
Registered: ‎08-31-2006
Post 2 of 13

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
35 Posts
1 Kudo
Registered: ‎01-15-2003
Post 3 of 13

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
188 Posts
0 Kudos
Registered: ‎09-18-2005
Post 4 of 13

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
125 Posts
0 Kudos
Registered: ‎08-02-2005
Post 5 of 13

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
212 Posts
6 Kudos
Registered: ‎10-03-2003
Post 6 of 13

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
38 Posts
0 Kudos
Registered: ‎09-08-2006
Post 7 of 13

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
38 Posts
0 Kudos
Registered: ‎09-08-2006
Post 8 of 13

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
125 Posts
0 Kudos
Registered: ‎08-02-2005
Post 9 of 13

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
38 Posts
0 Kudos
Registered: ‎09-08-2006
Post 10 of 13

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..
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!