Change color of datagrid's scrollbars?

J

James Radke

Hello,

How can I change the background color of a datagrid's scrollbars (and the
associated arrows)?

Thanks!

Jim
 
Y

Ying-Shen Yu[MSFT]

Hi James,

Does this issue same as your another issue in the windowsforms.controls
group titiled "How can I change the color of a datagrid scrollbar" ?
If they are same issue, I'll follow up with you in this thread.

There is no managed way to change the the background color of the scrollbar.
however we may handle the win32 message WM_CTLCOLORSCROLLBAR to change the
background color. Here is a list of steps to do this:
1. define a derived class from DataGrid
2. override WndProc and handle the WM_CTLCOLORSCROLLBAR messge.
like below:
<code>
protected override void WndProc(ref Message m)
{
const int WM_CTLCOLORSCROLLBAR = 0x0137;
const int BLACK_BRUSH = 4;
if (m.Msg == WM_CTLCOLORSCROLLBAR && m.LParam == this.VertScrollBar.Handle)
{
m.Result = GetStockObject(BLACK_BRUSH);
return;
}
base.WndProc (ref m);
}
</code>
according to the doc of this message, you need return a HBRUSH handle , you
may create your brush object by pinvoke GDI APIs, however you need delete
them when they are no longer needed.

For arrows, I haven't found a way to customize the color, I'll go on
research it for a while and post an update for this thread.
Thanks!




Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner 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, "online" should be removed before
sending.
 
Y

Ying-Shen Yu[MSFT]

Hi James

Have you changed the background of the scrollbar successfully?
If you have any problems on this issue, please feel free to reply in this
thread.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner 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, "online" should be removed before
sending.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top