.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RBG value from color dialog

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
1093 Views, 12 Replies

RBG value from color dialog

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?
12 REPLIES 12
Message 2 of 13
ahmed.felix
in reply to: Anonymous

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.
Message 3 of 13
Littlerubarb
in reply to: Anonymous

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.
Message 4 of 13
saluki
in reply to: Anonymous

This may help you out . . .

http://discussion.autodesk.com/thread.jspa?messageID=414913
Message 5 of 13
cgay
in reply to: Anonymous

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.
Message 6 of 13
Mikko
in reply to: Anonymous

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)
Message 7 of 13
Anonymous
in reply to: Anonymous

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
Message 8 of 13
Anonymous
in reply to: Anonymous

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
Message 9 of 13
cgay
in reply to: Anonymous

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
Message 10 of 13
Anonymous
in reply to: Anonymous

Thanks, that what I was missing...
I'll repost the code in a minute..
Message 11 of 13
Anonymous
in reply to: Anonymous

I got it to work this is the code I ended up using for now..

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
Dim r As Integer
Dim g As Integer
Dim b As Integer
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
r = CD.Color.ColorValue.R.ToString
g = CD.Color.ColorValue.G.ToString
b = CD.Color.ColorValue.B.ToString
PictureBox1.BackColor = System.Drawing.Color.FromArgb(r, g, b)
TextBox2.Text = PENN


I tried combiing the RGB value and couldn't get it to work do you see anything that's missing

Dim swatch As String

swatch = CD.Color.ColorValue.R.ToString + "," + CD.Color.ColorValue.G.ToString + "," + CD.Color.ColorValue.B.ToString

PictureBox1.BackColor = System.Drawing.Color.FromArgb(swatch) Message was edited by: Littlerubarbwk
Message 12 of 13
cgay
in reply to: Anonymous

You can use CD.Color.ColorValue directly as a system.color
like so:

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.ColorMetho d.ByAci, 1) 'Set Color to Red
CD.SetDialogTabs(Autodesk.AutoCAD.Windows.ColorDialog.ColorTabs.ACITab)
Dim dr As DialogResult = CD.ShowDialog 'Show the Dialog
If dr = DialogResult.OK Then 'If user clicked OK then
PictureBox1.BackColor = CD.Color.ColorValue 'Set the backcolor to the color selected
End If
End Sub
Message 13 of 13
Anonymous
in reply to: Anonymous

Thanks it works

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost