I never tried this feature (sound like a good idea, so I up-voted the question, which happens very rarely), but I'm pretty sure it won't be too hard. Most likely, you will be able to render the image of such button in the overridden method
OnPaint
in the control class derived from
TabControl
or in the
Paint
event handler. You will need to introduce states for this button and render it differently depending on the current state. To reflect the state change in rendering, you will need to call the method
Invalidatew
; you can use it with
Rectanlge
or
Region
parameter, to invalidate only the part of the control, where the button is rendered. To handle the click, you will need to handle the events
MouseDown
and
MouseUp
of the control, or, better, override the virtual methods
OnMouseDown
and
OnMouseUp
.
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[
^].
That was the light-weight approach, where you don't create a separate control for a button but implement button-like behavior for the part of the rendered surface of the tab control itself.
The alternative approach (which will always work) is to use some available button control or develop one as a separate control and use it on top of your tab control in a composite control using available tab control and your button control as childen, which you can develop as a
UserControl
. If you don't need to use the Designer for such control (I highly recommend to avoid using the Designer when it is possible and practical enough), you can derive your composite control directly from the class
ContainerControl
and insert two children in your manually written code — in many cases, this is easier and gives your better code quality. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.containercontrol.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.aspx[
^].
[EDIT]
Please see this CodeProject article:
A TabControl with tab page closing capability[
^].
(Thanks to Maciej Los who pointed out this article.)
Good luck,
—SA