BackgroundImage in ToolBar

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

I'm trying to make a simple background for a toolbar similar to the one in
Microsoft Money. Only problem is, I can't get the BackgroundImage to show
up. I set it up in VB.NET using the example for Control.BackgroundImage but
it appears normally. Has the functionality been removed for the Toolbar
control?

Thanks,
Stephen Graybeal
(e-mail address removed)
 
Hi Stephen,

ToolBar.BackGroundImage can not add a background image to the Toolbar,
that's why this property was hidden in the AutoIntelligence.
To draw a background image on the toolbar is not easy, you need do custom
draw to the toolbar, the general steps are:
1. Define a derived class from the ToolBar class, and override the WndProc
method to handle the native win32 messages.
2. In the Wndproc, if the incoming message is WM_NOTIFY, then we retrieve
the structure NMTBCUSTOMDRAW and get the painting stage. To draw the
background of the toolbar , you may handle the painting stage CDDS_PREPAINT.
3. In CDDS_PREPAINT stage, draw the background image using the Graphics
class or GDI APIs, then set the Message.Result to CDRF_DODEFAULT to let
windows continue drawing the rest parts.

The code needs some inertop, you need define the structure NMTBCUSTOMDRAW
in managed code and use Marshal.PtrToStructure to get the value from the
Message.lParam. You may read the .NET Interoperability guide to get more
information on it.

<Platform Invoke Tutorial (C#)>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vcwlkplatforminvoketutorial.asp

For further information on toolbar custom draw, you may refer to :
<NM_CUSTOMDRAW (toolbar) Notification>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/commctls/toolbar/notifications/nm_customdraw_toolbar.asp

<Customizing a Control's Appearance Using Custom Draw >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/commctls/custdraw/custdraw.asp

Due to the complexity of this issue, if a commercial control is an option,
maybe it would be easier to try some 3rd party toolbar controls.

If you have further questions on this issue, pelase feel free to reply to
this thread.
Thanks!

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.
 
Back
Top