I want to convert an object Color, to Int, to put him in crTextColor member, so I used the method myColor.ToArgb(), but the color changes, and displays a different color.
Why is this happening?
this is the code:
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
// check if the text contains CFE_AUTOCOLOR effect
SendMessage(new HandleRef(this, Handle), EM_GETCHARFORMAT, SCF_SELECTION, ref fmt);
if ((fmt.dwEffects & CFE_AUTOCOLOR) == CFE_AUTOCOLOR)
{
fmt.dwEffects -= CFE_AUTOCOLOR;
}
fmt.dwMask = CFM_COLOR;
Color c = Color.Red;
fmt.crTextColor = c.ToArgb();
SendMessage(new HandleRef(this, Handle), EM_SETCHARFORMAT, SCF_SELECTION, ref fmt);
This works fine. Are you doing something different?
EDIT: (After seeing your edit)
OK. So you got me there, I don’t really know this stuff. But:
If you go to MSDN’s page on
CHARFORMAT2here http://msdn.microsoft.com/en-us/library/windows/desktop/bb787883%28v=vs.85%29.aspx and search in it forcrTextColoryou’ll find (as the fifth case) the explanation to it. It says its type is: COLORREF . If you’ll click on that link – it says that it isRGB. Clicking on theRGBlink there goes to here http://msdn.microsoft.com/en-us/library/windows/desktop/dd162937%28v=vs.85%29.aspx which says:On the other hand – if you go here http://msdn.microsoft.com/en-us/library/system.drawing.color.toargb.aspx you see (in “remarks”) that
Color.ToArgbisARGB:So perhaps that’s the problem. But, again, I don’t really know this stuff! I just did some searching.