-
Subclassing UserControls
I've got a VScrollBar on a user control, how would I stop VB from changing the background colour of it to white?
I achieved it on a form by stopping the WM_CTLCOLORSCROLLBAR from being sent to the form, but when I subclass the usercontrol nothing happens.
Cheers for any help, adehh!
-
What, the background color of the scrollbar?
-
1 Attachment(s)
Indeed, running Win2k all the backgrounds on scrollbars are grey, yet in VB scrollbar controls are made white by VB for some reason.
Look at the attached project. In design view the scrollbar should have a white background but in runtime it should look normal, that's from the subclassing.
-adehh
-
Aha, the VScrollBar was contained in a PictureBox so I subclassed that instead and it works a treat.
-adehh
-
So you can change the color of the scrollbar?
-
WM_CTLCOLORSCROLLBAR Notification
--------------------------------------------------------------------------------
The WM_CTLCOLORSCROLLBAR message is sent to the parent window of a scroll bar control when the control is about to be drawn. By responding to this message, the parent window can use the display context handle to set the background color of the scroll bar control.
A window receives this message through its WindowProc function.
Syntax
WM_CTLCOLORSCROLLBAR
WPARAM wParam
LPARAM lParam;
Parameters
wParam
Handle to the device context for the scroll bar control.
lParam
Handle to the scroll bar.
Return Value
If an application processes this message, it must return the handle to a brush. The system uses the brush to paint the background of the scroll bar control.
Remarks
By default, the DefWindowProc function selects the default system colors for the scroll bar control.
The system does not automatically destroy the returned brush. It is the application's responsibility to destroy the brush when it is no longer needed.
The WM_CTLCOLORSCROLLBAR message is never sent between threads; it is only sent within the same thread.
If a dialog box procedure handles this message, it should cast the desired return value to a BOOL and return the value directly. If the dialog box procedure returns FALSE, then default message handling is performed. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.
The WM_CTLCOLORSCROLLBAR message is used only by child scrollbar controls. Scrollbars attached to a window (WS_SCROLL and WS_VSCROLL) do not generate this message. To customize the appearance of scrollbars attached to a window, use the flat scroll bar functions.
Notification Requirements
Minimum DLL Version None
Header Declared in Winuser.h, include Windows.h
Minimum operating systems Windows 95, Windows NT 3.1
See Also
Scroll Bars, DefWindowProc, RealizePalette, SelectPalette, WM_CTLCOLORBTN, WM_CTLCOLORDLG, WM_CTLCOLOREDIT, WM_CTLCOLORLISTBOX, WM_CTLCOLORSTATIC[COLOR=red][B]
-
adzzzzz. You said you subclassed the scrollbar in the picture box instead. Could you post that example please?
Cheers
-
1 Attachment(s)
It's part of a big project so I'll slap together a small example.
-adehh
-
If when you click it, its supposed to be a different color.
Then it doesnt work for me. I clicked the actual bar, the background (large change) and arrow. Does nothing extra special.
Thanks anyway:p
-
1 Attachment(s)
It's not meant to do anythin special, just make the scrollbar look like a normal windows one.
Look at attached pic, top one is with the hook and bottom one is without, small change I know but this one used to annoy me. :)
-adehh
-
You did all that subclassing for that!
My advice, if you wear glasses, then dont when you look at the scrollbars:lol:
-
Heh, that's nothin. It's all part of a usercontrol I made because the text in textboxes isn't flush with the bottom. :p
Little things annoy me. :D
-adehh
-
Yeah, same here. Everything has to be perfect. But thats beyond a joke!