Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE: How to change TextBox selected text colors?

197 views
Skip to first unread message

Ying-Shen Yu[MSFT]

unread,
Jul 29, 2004, 5:15:47 AM7/29/04
to
Hi Dave,

The Selection Color setting is retrieved from system settings, all windows
controls are conform to this setting, there is no easy way to override
this settings.

One exception might be helpful to your scenario is the RichEdit 1.0
control, it uses the inverse color of the background color as its selection
color. So when you set the Background color to black and text color to
white, the selection color will be white in bandground and black in text.
However Unfortunately, there is no corresponding Winform controls for
RichEdit 1.0 control. so you may need to write a wrapper class for it to
use it in your winform application.
Here is an snippet in C++ for how to change set White on Black with
RichEdit 1.0.
<code>
LRESULT CALLBACK WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
lParam)
{
HWND hEdit = NULL;
HDC hDC = NULL;
switch (message)
{
case WM_INITDIALOG:
//Need Load the RichEdit 1.0 DLL
LoadLibrary ( "RICHED32.DLL" );
//Create a RichEdit 1.0 control
hEdit = CreateWindow( _T("RICHEDIT"), _T("TEST RICHTEXT"), WS_BORDER |
WS_CHILD, 10, 10, 200, 100, hDlg,NULL, hInst, NULL );
ShowWindow (hEdit, SW_SHOW );

//Set Background color
SendMessage ( hEdit, EM_SETBKGNDCOLOR, 0, RGB ( 0, 0, 0 ) );

//Set TextColor ( Forecolor )
CHARFORMAT char_format;
ZeroMemory ( &char_format, sizeof ( CHARFORMAT ) );
char_format.cbSize = sizeof ( CHARFORMAT );
char_format.dwMask = CFM_COLOR;
char_format.crTextColor = RGB( 255,255,255);
SendMessage ( hEdit, EM_SETCHARFORMAT,SCF_ALL, (DWORD) &char_format );

return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
</code>

Hope it helps.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

0 new messages