<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>BitsAbound (really really abound!) - Code</title>
    <link>http://blog.bitsabound.com/</link>
    <description>Software products with distinction</description>
    <language>en-us</language>
    <copyright>Sajid</copyright>
    <lastBuildDate>Tue, 19 May 2009 00:37:22 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>info@bitsabound.com</managingEditor>
    <webMaster>info@bitsabound.com</webMaster>
    <item>
      <trackback:ping>http://blog.bitsabound.com/Trackback.aspx?guid=feb859ce-aec4-40f6-a55f-0b518d9dc95f</trackback:ping>
      <pingback:server>http://blog.bitsabound.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.bitsabound.com/PermaLink,guid,feb859ce-aec4-40f6-a55f-0b518d9dc95f.aspx</pingback:target>
      <dc:creator>Sajid Khan</dc:creator>
      <wfw:comment>http://blog.bitsabound.com/CommentView,guid,feb859ce-aec4-40f6-a55f-0b518d9dc95f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.bitsabound.com/SyndicationService.asmx/GetEntryCommentsRss?guid=feb859ce-aec4-40f6-a55f-0b518d9dc95f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Since Windows default Tab Control is quite
primitive, every once in a while you'll need the ability to be able to close the individual
tab pages in the control.<br /><br />
SnapConfig has this ability and I thought I would share some aspects of how this is
done.<br /><br />
One of the problematic issues in drawing buttons yourself is to take care of themes
in windows but still be able to support non themed desktops.<br /><br />
following is the code that does that<br /><br />
    <pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> DrawTabCloseButton(System.Windows.Forms.DrawItemEventArgs
e, Rectangle rect, VisualStyleElement style, ButtonState state) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (VisualStyleRenderer.IsSupported)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (VisualStyleRenderer.IsElementDefined(style))
{ VisualStyleRenderer renderer <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> VisualStyleRenderer(style);
renderer.DrawBackground(e.Graphics, rect); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span>;
} } ControlPaint.DrawCaptionButton(e.Graphics, rect, CaptionButton.Close, state);
}</span></pre><br /><br /><br />
The rect parameter is where you want to draw the button,<br /><br />
The VisualStyleElement can be VisualStyleElement.Window.CloseButton.Hot or VisualStyleElement.Window.CloseButton.Pressed
or any of the others supported if you are handling that logic.<br /><br />
ButtonState can be ButtonState.Pushed or any other.<br /><br />
This section only handles the actual drawing, there are other things which are done
on the fly by SnapConfig that is maintaing the state of button on each tab, for example
if you press and hold the mouse and move away from a close button it will become normal
but if you come back while holding it will again press down, which is standard windows
behaviour.<br /><br />
to get onDrawItem you need to set<br /><br />
DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;<br /><br /><br /><p></p><img width="0" height="0" src="http://blog.bitsabound.com/aggbug.ashx?id=feb859ce-aec4-40f6-a55f-0b518d9dc95f" /></body>
      <title>Drawing Caption buttons on Tab Pages</title>
      <guid isPermaLink="false">http://blog.bitsabound.com/PermaLink,guid,feb859ce-aec4-40f6-a55f-0b518d9dc95f.aspx</guid>
      <link>http://blog.bitsabound.com/2009/05/19/DrawingCaptionButtonsOnTabPages.aspx</link>
      <pubDate>Tue, 19 May 2009 00:37:22 GMT</pubDate>
      <description>Since Windows default Tab Control is quite primitive, every once in a while you'll need the ability to be able to close the individual tab pages in the control.&lt;br&gt;
&lt;br&gt;
SnapConfig has this ability and I thought I would share some aspects of how this is
done.&lt;br&gt;
&lt;br&gt;
One of the problematic issues in drawing buttons yourself is to take care of themes
in windows but still be able to support non themed desktops.&lt;br&gt;
&lt;br&gt;
following is the code that does that&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; DrawTabCloseButton(System.Windows.Forms.DrawItemEventArgs
e, Rectangle rect, VisualStyleElement style, ButtonState state) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (VisualStyleRenderer.IsSupported)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (VisualStyleRenderer.IsElementDefined(style))
{ VisualStyleRenderer renderer &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; VisualStyleRenderer(style);
renderer.DrawBackground(e.Graphics, rect); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt;;
} } ControlPaint.DrawCaptionButton(e.Graphics, rect, CaptionButton.Close, state);
}&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
The rect parameter is where you want to draw the button,&lt;br&gt;
&lt;br&gt;
The VisualStyleElement can be VisualStyleElement.Window.CloseButton.Hot or VisualStyleElement.Window.CloseButton.Pressed
or any of the others supported if you are handling that logic.&lt;br&gt;
&lt;br&gt;
ButtonState can be ButtonState.Pushed or any other.&lt;br&gt;
&lt;br&gt;
This section only handles the actual drawing, there are other things which are done
on the fly by SnapConfig that is maintaing the state of button on each tab, for example
if you press and hold the mouse and move away from a close button it will become normal
but if you come back while holding it will again press down, which is standard windows
behaviour.&lt;br&gt;
&lt;br&gt;
to get onDrawItem you need to set&lt;br&gt;
&lt;br&gt;
DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.bitsabound.com/aggbug.ashx?id=feb859ce-aec4-40f6-a55f-0b518d9dc95f" /&gt;</description>
      <comments>http://blog.bitsabound.com/CommentView,guid,feb859ce-aec4-40f6-a55f-0b518d9dc95f.aspx</comments>
      <category>Code</category>
    </item>
  </channel>
</rss>