How to add color picker in mfc?
Solution 1
Use CColorDialog class in mfc is used to pick the color from mfc
// Get the selected color from the CColorDialog.
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
COLORREF color = dlg.GetColor();
}
This sample will popup dialog to select the color and after selecting the color and click ok button then color variable will contain the selected color.
Use this color in your application.
EDIT
You can customize your combo box or list box to add the color pick tool.
Refer this link : CodeProjectSample
Solution 2
Since you don't seem to have the MFC Feature Pack, check the Ultimate Toolbox at http://www.codeproject.com/KB/MFC/UltimateToolbox.aspx. Its Graphical User Interface classes have a Color Picker.
Solution 3
CMFCColorDialog
is what you seem to be looking for. To make it act like a drop-down, you'll need to position it below the down-arrow button (e.g., using MoveWindow
).
karthik
.NET Developer having experience in MVC, Web Development, WCF Services.
Updated on June 13, 2022Comments
-
karthik almost 2 years
i want be able to select any color i want, just like the attached pic.
yes i want to learn this c++ or mfc . I find it more powerfull . Could u explain to me exactly how to add it to my project. I also want the color iteslf and it code appers in picture box and textbox.
Thanks
-
karthik almost 13 years@user : This will popup the dialog but i want like the above attachment.
-
karthik almost 13 yearshow to include CMFCColorDialog in to my application.when i use this , it will show the error as CMFCColorDialog undeclared identifier.
-
Jerry Coffin almost 13 yearsYou need either VS 2008 with the Feature Pack or SP1, or else VS 2010 to use it. Assuming you have that,
#include <afxcolordialog.h>
. -
karthik almost 13 yearsI am not having that version.Is any other possible way to achieve this?
-
Jerry Coffin almost 13 yearsWith older versions/compilers, it's easiest to use a CColorDialog instead (or you can call ChooseColor directly). At least in theory, you should be able to create the drop-down color picker directly via its COM interface, but I've never tried it, so I can't really say much about how to do it.
-
karthik almost 13 years@karthik: For that you have to customize the combobox and write in the way you like.