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

Color Selection Dialog

7 REPLIES 7
Reply
Message 1 of 8
flongsworth
426 Views, 7 Replies

Color Selection Dialog

This is probably very simple but can anyone show me how choose a color from the dialog.

Dim ColorRes As Autodesk.AutoCAD.Colors.Color
Autodesk.AutoCAD.ApplicationServices.Dialogs.ChooseColorDialog(ColorRes, True, CurColor, Dialogs.ColorTabs.ACITab)

this gives me the following warning:

Warning 1 Variable 'ColorRes' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: flongsworth

For instance:

Dim ColorRes As New Autodesk.AutoCAD.Colors.Color

or

Dim ColorRes As Autodesk.AutoCAD.Colors.Color =
Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Black)

or

Dim ColorRes As Autodesk.AutoCAD.Colors.Color =
Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.None,
1)

or

Dim c As Autodesk.AutoCAD.Colors.Color =
Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 255)




escreveu na mensagem news:5083997@discussion.autodesk.com...
This is probably very simple but can anyone show me how choose a color from
the dialog.

Dim ColorRes As Autodesk.AutoCAD.Colors.Color
Autodesk.AutoCAD.ApplicationServices.Dialogs.ChooseColorDialog(ColorRes,
True, CurColor, Dialogs.ColorTabs.ACITab)

this gives me the following warning:

Warning 1 Variable 'ColorRes' is passed by reference before it has been
assigned a value. A null reference exception could result at runtime.
Message 3 of 8
flongsworth
in reply to: flongsworth

I know you can declare the color in those ways, but I want to give the user the ability to use the color selection dialog to choose the color.
Message 4 of 8
cgay
in reply to: flongsworth

Hey flongsworth ,

I am pretty sure tp was giving you the solution to the error you posted. The warning you are getting is a compiler warning. I would also like to add one other possible fix:
Dim ColorRes As Autodesk.AutoCAD.Colors.Color = Nothing

Good Luck,
C
Message 5 of 8
flongsworth
in reply to: flongsworth

Thanks , and I apologize for not paying attention to tp's post. The samples you both provided work fine.
Message 6 of 8
wesbird
in reply to: flongsworth

Hi flongsworth:
I am looking for the code to show AutoCAD true color dialog and pick color from there for a while. When I read your message, I thought that what I am looking for. Is this correct?
Where did you find the ChooseColorDialog? I can not find it everywhere, include the help file.
I tried to compile the code:
[code]
[CommandMethod("AsdkCmd1")]
static public void AsdkCmd1() // This method can have any name
{
// Put your command code here
Autodesk.AutoCAD.Colors.Color ColorRes = new Autodesk.AutoCAD.Colors.Color();
Autodesk.AutoCAD.ApplicationServices.Dialogs.ChooseColorDialog(ColorRes, True, CurColor, Dialogs.ColorTabs.ACITab);
}
[/code]

which does not comiple with this error message:
...\ChooseColorDialogCS\Class.cs(52): The type or namespace name 'Dialogs' does not exist in the class or namespace 'Autodesk.AutoCAD.ApplicationServices' (are you missing an assembly reference?)


Is there something I missing?

Thank you
Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 7 of 8
Anonymous
in reply to: flongsworth

Have you looked at :
Autodesk.AutoCAD.Windows.ColorDialog Class



wrote in message news:5085599@discussion.autodesk.com...
Hi flongsworth:
I am looking for the code to show AutoCAD true color dialog and pick color from there for a while.
When I read your message, I thought that what I am looking for. Is this correct?
Where did you find the ChooseColorDialog? I can not find it everywhere, include the help file.
I tried to compile the code:
[code]
[CommandMethod("AsdkCmd1")]
static public void AsdkCmd1() // This method can have any name
{
// Put your command code here
Autodesk.AutoCAD.Colors.Color ColorRes = new Autodesk.AutoCAD.Colors.Color();
Autodesk.AutoCAD.ApplicationServices.Dialogs.ChooseColorDialog(ColorRes, True, CurColor,
Dialogs.ColorTabs.ACITab);
}
[/code]

which does not comiple with this error message:
...\ChooseColorDialogCS\Class.cs(52): The type or namespace name 'Dialogs' does not exist in the
class or namespace 'Autodesk.AutoCAD.ApplicationServices' (are you missing an assembly reference?)


Is there something I missing?

Thank you
Wes
Message 8 of 8
RonnieWilkins
in reply to: flongsworth

No error catching but show how to use the color dialog...

Imports AcCm = Autodesk.AutoCAD.Colors
Imports AcWi = Autodesk.AutoCAD.Windows
Public Class ColorSelector
Public Function GetColor() As AcCm.Color
Dim CD As New AcWi.ColorDialog
Dim C As AcCm.Color = AcCm.Color.FromColorIndex(AcCm.ColorMethod.ByAci, 1) 'Set color to RED
CD.Color = C
CD.SetDialogTabs(AcWi.ColorDialog.ColorTabs.ACITab Xor AcWi.ColorDialog.ColorTabs.TrueColorTab) 'Do not show color books
If CD.ShowDialog <> DialogResult.OK Then
Return Nothing
End If

Return CD.Color
End Function

Public Function GetColor(ByVal DefaultColor As AcCm.Color) As AcCm.Color
Dim CD As New AcWi.ColorDialog
CD.Color = DefaultColor
CD.SetDialogTabs(AcWi.ColorDialog.ColorTabs.ACITab Xor AcWi.ColorDialog.ColorTabs.TrueColorTab) 'Do not show color books
If CD.ShowDialog <> DialogResult.OK Then
'User cancelled return default color
Return DefaultColor
End If

Return CD.Color
End Function
End Class


P.S. I have a widescreen monitor so I apologize in advance for scrolling. I'm not a big fan of continuation lines. Message was edited by: rwilkins
Ronnie Wilkins, Jr.

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