<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dotnet thoughts &#187; Tab Control</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/tab-control/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Implementing Close button in Tab Pages</title>
		<link>http://www.dotnetthoughts.net/2009/11/08/implementing-close-button-in-tab-pages/</link>
		<comments>http://www.dotnetthoughts.net/2009/11/08/implementing-close-button-in-tab-pages/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 22:15:23 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Tab Control]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=619</guid>
		<description><![CDATA[Long back, when I worked on Windows Application, my client asked me to change the UI, instead of using MDI, he want to use SDI. And for multiple Windows, suggested Tab Control, like the new Web Browsers. Fortunately he dropped &#8230; <a href="http://www.dotnetthoughts.net/2009/11/08/implementing-close-button-in-tab-pages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Long back, when I worked on Windows Application, my client asked me to change the UI, instead of using MDI, he want to use SDI. And for multiple Windows, suggested Tab Control, like the new Web Browsers. Fortunately he dropped the idea of SDI later and I continue to use MDI. But few days ago I got a question from a dotnet forum, how can we create close button for the Tab Pages in Tab Control. While searching I got lot of implementations, later I implemented it in my own way. In the implementations I found, they are inheriting from Tab Control, in this implementation, I implemented in such way that it can be applied for an existing Tab Control. </p>
<ol>
<li>Set the DrawMode property of the Tab Control to OwnerDrawFixed. This property is decides whether system or developer painting the captions.</li>
<li>Add the code in the DrawItem event of the Tab Control &#8211; This event will be invoked for painting each Tab Page.</li>
<pre class="brush: csharp; title: ; notranslate">
//This code will render a &quot;x&quot; mark at the end of the Tab caption.
e.Graphics.DrawString(&quot;x&quot;, e.Font, Brushes.Black, e.Bounds.Right - 15, e.Bounds.Top + 4);
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
e.DrawFocusRectangle();
</pre>
<li>Now for close button action, we need to add the following code to the MouseDown event of the Tab Control.</li>
<pre class="brush: csharp; title: ; notranslate">
//Looping through the controls.
for (int i = 0; i &lt; this.tabControl1.TabPages.Count; i++)
{
    Rectangle r = tabControl1.GetTabRect(i);
   //Getting the position of the &quot;x&quot; mark.
    Rectangle closeButton = new Rectangle(r.Right - 15, r.Top + 4, 9, 7);
    if (closeButton.Contains(e.Location))
    {
        if (MessageBox.Show(&quot;Would you like to Close this Tab?&quot;, &quot;Confirm&quot;, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
        {
            this.tabControl1.TabPages.RemoveAt(i);
            break;
        }
    }
}
</pre>
</ol>
<p>Here is the screenshot, of the implementation, running on my machine.<br />
<div id="attachment_621" class="wp-caption alignnone" style="width: 562px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/11/tabDemo.PNG" alt="Close Button in Tab Pages" title="Close Button in Tab Pages" width="552" height="300" class="size-full wp-image-621" /><p class="wp-caption-text">Close Button in Tab Pages</p></div></p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/08/09/creating-wizard-using-windows-forms/" title="Permanent link to Creating Wizard using Windows Forms">Creating Wizard using Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/11/02/wpf-interoperability-with-windows-forms/" title="Permanent link to WPF interoperability with Windows Forms">WPF interoperability with Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/" title="Permanent link to Color Picker Dropdown using C#">Color Picker Dropdown using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/03/update-multiple-elements-at-once-using-linq/" title="Permanent link to Update multiple elements at once using LINQ">Update multiple elements at once using LINQ</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/" title="Permanent link to Drive combo box in C#">Drive combo box in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/11/08/implementing-close-button-in-tab-pages/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

