c# - Owner-Drawn ToolStripDropDownButton -


i'm writing custom behavior toolstripdropdown control. i'd modify toolstripdropdownbutton display colored shape.

i see can handle paint event , draw whatever like. however, there way have button paint default background before paint shape? hard background right, future versions of .net , windows.

in plain ol' windows, invoke default proc handler before or after paint code. i'm not seeing way accomplish in .net. or perhaps there's way tell button paint background?

when handle paint event (as opposed overriding onpaint method in derived class) base class (default proc handler) getting called. gets drawn normal, , you're drawing on top of that in paint event. can see here:

     lime rectangle drawn on part of drop-down button, showing default contents underneath

the trick making sure leave enough of control's clipping rectangle exposed show part want. e.cliprectangle property retrieves entire button's client area, if just
fill color swatch, you're going cover drop-down arrow , default background, too. above demonstration created using following ugly sample code:

private void toolstripdropdownbutton1_paint(object sender, painteventargs e) {     e.graphics.fillrectangle(brushes.chartreuse,                              e.cliprectangle.x + 3, e.cliprectangle.y + 3,                              e.cliprectangle.width - 12,                              e.cliprectangle.height - 12); } 

other that, don't think there's way customize gets drawn base class. owner-drawing (at least in winforms) tends all-or-nothing affair. complete control,
comes @ price of having implement yourself.


of course, in case haven't noticed, toolstrip control already doesn't native windows control. , worse, always going same now,
in future versions of windows overhaul ui. (the menustrip plagued by
same phenomenon, , difference visible in windows vista/7 standard api menus have changed dramatically). reason both controls drawn entirely in c# code written in winforms implementations. personally, think looks ridiculously cheesy, , wouldn't use in 1 of applications on bet.

you can assign custom renderer uses uxtheme api draw buttons, much closer approximating of native menus , toolbars. pretty thorough sample available here. i've written similar winforms development i've done requiring additional features of toolstrip class (such embedding combo boxes) not offered the
old-school mainmenu , toolbar controls wrap windows api equivalents. choosing things way, have more control on parts of base class renderer wish call, you've written code explicitly yourself. highly recommended if you're
type cares @ ui, native feel, or user experience.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -