Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have been trying all day long to draw the toolbar background red but to no avail. The OnPaint event is not ever called when I inherit from ToolBar.

 

But when I inherit from UserControl or Button the OnPaint event is fired, but that is pretty useless to me because it is not anything like a toolbar.

 

And, the ToolBar in VS does not have a DrawMode option for it. So I cannot Owner Draw. I don't think so anyway. It seems like I would have to create my own toolbar control from scratch. What do you think?

C#
  • *Gurus*
Posted

The answer is probably. The Toolbar in the .NET framework is not a complete control in itself, it only wraps the win32 common controls toolbar. This won't always be the case, but that's how it is at the moment. That means that you almost certainly won't be able to owner draw it in any elegant way.

 

The only way you'd be able to owner draw it is to override its WndProc method and listen for the WM_PAINT message. You might be able to do some more stuff specific to the toolbar by sending it messages and creating win32 brush objects for it when it asks for them.

 

Creating your own toolbar from scratch will probably be about as much work, and give you far more control (obviously). I've written my own, which works well. It does more than the win32 one does. You might want to read the article I wrote on writing collection-driven controls like this, it goes in to the best way to design them. The sample project that comes with it could be converted to a functioning toolbar quite easily.

 

Read it here

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Divil, I found a small mistake in your page:

 

but in this case we want to hide then. (them)

 

That is under the Adding the designer section.

 

Here is another one:

 

Adding Buttons

 

The first thing we want the user to be able to do is to buttons.

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...