.NET

Reply
Contributor
flongsworth
Posts: 17
Registered: ‎01-27-2005
Message 1 of 8 (188 Views)

Color Selection Dialog

188 Views, 7 Replies
02-11-2006 02:26 PM
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.
*tp
Message 2 of 8 (188 Views)

Re: Color Selection Dialog

02-12-2006 03:22 PM 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.
Contributor
flongsworth
Posts: 17
Registered: ‎01-27-2005
Message 3 of 8 (188 Views)

Re: Color Selection Dialog

02-12-2006 04:17 PM 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.
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 4 of 8 (188 Views)

Re: Color Selection Dialog

02-12-2006 09:01 PM 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
Contributor
flongsworth
Posts: 17
Registered: ‎01-27-2005
Message 5 of 8 (188 Views)

Re: Color Selection Dialog

02-13-2006 06:11 AM in reply to: flongsworth
Thanks , and I apologize for not paying attention to tp's post. The samples you both provided work fine.
Distinguished Contributor
wesbird
Posts: 349
Registered: ‎12-05-2003
Message 6 of 8 (188 Views)

Re: Color Selection Dialog

02-14-2006 06:48 AM 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
*Kerry Brown
Message 7 of 8 (188 Views)

Re: Color Selection Dialog

02-14-2006 07:30 AM 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
Distinguished Contributor
RonnieWilkins
Posts: 453
Registered: ‎04-07-2003
Message 8 of 8 (188 Views)

Re: Color Selection Dialog

02-14-2006 08:25 AM 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.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community