Board index » cppbuilder » Getting RGB variables from a ColorDialog

Getting RGB variables from a ColorDialog

my event calls this code

MainForm->ColorDialog1->Execute();
int Red = GetRValue(ColorToRGB(Color));
int Green = GetGValue(ColorToRGB(Color));
int Blue = GetBValue(ColorToRGB(Color));
MainForm->Edit1->Text = Red; // temp edit boxes to see values generated
MainForm->Edit2->Text = Green;
MainForm->Edit5->Text = Blue;

The ColorDialog pops up like i expect, I can select a color, which is
supposed to be stored in Color as a TColor value.
I want to extract the RGB values from Color to assign them to other
variables within my program. What is wrong with my code? It seems to be
ignoring the color set by the colordialog and using the standard grey of the
form.
Is GetBValue(ColorToRGB(Color)) refering to the color of the form, or the
color seleted by the colordialog box?

 

Re:Getting RGB variables from a ColorDialog


You need to point to the ColorDialog1 Color.
<MainForm->ColorDialog1->Color> not <Color>.

 MainForm->ColorDialog1->Execute();
 int Red = GetRValue(ColorToRGB(MainForm->ColorDialog1->Color));    
 int Green = GetGValue(ColorToRGB(MainForm->ColorDialog1->Color));  
int Blue = GetBValue(ColorToRGB(MainForm->ColorDialog1->Color));    
 MainForm->Edit1->Text = Red; // temp edit boxes to see values generated
 MainForm->Edit2->Text = Green;
 MainForm->Edit5->Text = Blue;

See Ya

Quote
> my event calls this code

> MainForm->ColorDialog1->Execute();
> int Red = GetRValue(ColorToRGB(Color));
> int Green = GetGValue(ColorToRGB(Color));
> int Blue = GetBValue(ColorToRGB(Color));
> MainForm->Edit1->Text = Red; // temp edit boxes to see values generated
> MainForm->Edit2->Text = Green;
> MainForm->Edit5->Text = Blue;

> The ColorDialog pops up like i expect, I can select a color, which is
> supposed to be stored in Color as a TColor value.
> I want to extract the RGB values from Color to assign them to other
> variables within my program. What is wrong with my code? It seems to be
> ignoring the color set by the colordialog and using the standard grey of the
> form.
> Is GetBValue(ColorToRGB(Color)) refering to the color of the form, or the
> color seleted by the colordialog box?

Re:Getting RGB variables from a ColorDialog


I have fixed it myself please ignore this.

the code should be

MainForm->ColorDialog1->Execute();
Color = MainForm->ColorDialog1->Color;  // you have to assign the color from
the dialog to Color
int Red = GetRValue((ColorToRGB(Color)));
int Green = GetGValue((ColorToRGB(Color)));
int Blue = GetBValue((ColorToRGB(Color)));

just in case anyone else was having the same problem.

Re:Getting RGB variables from a ColorDialog


Well, sharks. I did not know that! I was doing it the hard way, breaking up
the RGB value using bit operations.
Thanks.

--
Andrei
REMOVE_sezna2...@yahoo.com

Other Threads