Results 1 to 13 of 13

Thread: Subclassing UserControls

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    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!

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    What, the background color of the scrollbar?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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
    Attached Files Attached Files

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Aha, the VScrollBar was contained in a PictureBox so I subclassed that instead and it works a treat.

    -adehh

  5. #5
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    So you can change the color of the scrollbar?

  6. #6
    Addicted Member Abilio's Avatar
    Join Date
    May 2003
    Location
    Aveiro - Portugal
    Posts
    222
    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]

  7. #7
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    adzzzzz. You said you subclassed the scrollbar in the picture box instead. Could you post that example please?

    Cheers

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    It's part of a big project so I'll slap together a small example.

    -adehh
    Attached Files Attached Files

  9. #9
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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
    Attached Images Attached Images  

  11. #11
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    You did all that subclassing for that!

    My advice, if you wear glasses, then dont when you look at the scrollbars

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Heh, that's nothin. It's all part of a usercontrol I made because the text in textboxes isn't flush with the bottom.

    Little things annoy me.

    -adehh

  13. #13
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Yeah, same here. Everything has to be perfect. But thats beyond a joke!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width