<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Windows Forms Documentation Updates : Container Controls and Layout</title><link>http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx</link><description>Tags: Container Controls and Layout</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>New White Paper: Creating Smart Application Layouts in Windows Forms 2.0</title><link>http://blogs.msdn.com/winformsue/archive/2006/07/19/671843.aspx</link><pubDate>Thu, 20 Jul 2006 00:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:671843</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/671843.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=671843</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=671843</wfw:comment><description>&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/layWF2.asp"&gt;My new Windows Forms white paper is now available on MSDN&lt;/a&gt;. It covers using ToolStrip as a navigation alternative to TabControl, and creating collapsible flyout menus a la the Visual Studio Toolbox. Compilable code samples are included. &lt;br&gt;&lt;br&gt;Enjoy!&lt;br&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=671843" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Snaplines: Using CTRL Key to Snap in Windows Forms</title><link>http://blogs.msdn.com/winformsue/archive/2006/06/22/643427.aspx</link><pubDate>Fri, 23 Jun 2006 01:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:643427</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/643427.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=643427</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=643427</wfw:comment><description>&lt;P&gt;I was just in a meeting and learned about a Windows Forms feature I previously knew nothing of. I love Snaplines in Windows Forms 2.0/Visual Studio 2005. What I didn't know, however, is that you can use the CTRL key and the arrow keys to snap to Snaplines.&lt;/P&gt;
&lt;P&gt;Try it! Place a Panel and a Button on a form next to one another, spaced reasonably well apart. Put another Button on the form, above and to the left of the other two controls. Now, select the second Button, press CTRL, and use the right arrow key to SNAP your Button's way across the page. &lt;/P&gt;
&lt;P&gt;There are a few other shortcuts as well, including ALT, which temporarily disables Snaplines. For the full 411 on this feature, check out &lt;A href="http://msdn2.microsoft.com/en-us/t5b5kc41.aspx"&gt;Walkthrough: Arranging Controls on Windows Forms Using Snaplines&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=643427" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Control.Location is a Pain - or, Why We Need an OffsetLocation() Method</title><link>http://blogs.msdn.com/winformsue/archive/2006/04/20/580039.aspx</link><pubDate>Thu, 20 Apr 2006 20:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:580039</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/580039.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=580039</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=580039</wfw:comment><description>&lt;P&gt;I'm polishing up some code for a Windows Forms white paper on application layouts in Windows Forms 2.0. The paper will cover advanced uses of the ToolStrip control for creating navigational layouts, among other things. One of the samples is a VS Toolbox-style flyout panel. The code to implement this wasn't too gnarly, except that in my first rev, I was new()ing up a whole lotta Point structs in slide-in and slide-out:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;currentControl.Location = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Point(currentControl.Location.X + 20, currentControl.Location.Y)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Jim Galasyn, one of my colleagues on the team, asked why I was doing this. To put it simply, I did it this naively because the Location property of Control is lame. Location is of type Point, which is a struct. Structs are passed by value, not by reference, meaning that returning the Location property directly would pass a copy of the type on the stack. On top of that, for some reason, the source code for Control.Location in Windows Forms just goes ahead and new()s up a new Struct every time you access the Location property anyway! (That's a&amp;nbsp;good reason not to call this property extraneously, and to almost &lt;STRONG&gt;never&lt;/STRONG&gt; call it in&amp;nbsp;large loops.) So direct calls on Location are for naught. &lt;/P&gt;
&lt;P&gt;I worked around this in my own application by caching a Point value, and operating on that using the Offset() method. This eliminated the constant creation of new Point structures on the stack, sped up my app, and make for somewhat cleaner code:&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;_CachedControlPoint.Offset(-20, 0)&lt;BR&gt;currentControl.Location = _CachedControlPoint&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;What's frustrating is that, after 2-1/2 years writing Windows Forms documentation, I &lt;STRONG&gt;still&lt;/STRONG&gt; get bitten by this. It's so natural to call a property or a method and expect that to reflect on the associated object that exceptions such as these throw me for a loop. Sure, we can document this. We &lt;EM&gt;have&lt;/EM&gt; documented it. But documentation can only do so much to defeat logic.&lt;/P&gt;
&lt;P&gt;It would be nice, at the very least, to have an OffsetLocation() method defined on Control that eliminated the need for self-caching of Point objects. I know my product team has bigger fish to fry, but...come on, folks, pretty please? As a favor for l'il ol' me? [insert eyelash-batting here]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=580039" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Form+and+Application+Classes/default.aspx">Form and Application Classes</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Using TableLayoutPanel to Create DHTML-Style Text Menu</title><link>http://blogs.msdn.com/winformsue/archive/2006/04/05/569367.aspx</link><pubDate>Thu, 06 Apr 2006 00:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:569367</guid><dc:creator>Jay A. Allen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/569367.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=569367</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=569367</wfw:comment><description>&lt;P&gt;I'm not a big fan of TableLayoutPanel. The control is very limited in what it can do given that the cells created by column/row interactions are not programmatically accessible (unlike in DHTML tables or even in the awesome DataGridView class). However, you can still pull off some cool tricks in spite of its limitations. Below is an example of how to create a DHTML-style link menu that expands and shrinks freely as the form is resized.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.msdn.com/photos/jay_a_allen/picture569360.aspx" target=_blank&gt;&lt;IMG src="https://blogs.msdn.com/photos/jay_a_allen/images/569360/575x198.aspx" border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The menu is nothing more than a TableLayoutPanel with one row and five columns. The TLP's &lt;STRONG&gt;Dock&lt;/STRONG&gt; property is set to Top. The columns are configured to each take up 20% apiece of the panel's available real estate - in other words, each occupies equal space. The link text is simply five LinkLabels, each set as follows:&lt;/P&gt;
&lt;P&gt;.&lt;STRONG&gt;Dock&lt;/STRONG&gt;=Fill&lt;BR&gt;.&lt;STRONG&gt;BackColor&lt;/STRONG&gt;=Transparent&lt;BR&gt;.&lt;STRONG&gt;TextAlign&lt;/STRONG&gt;=MiddleCenter&lt;/P&gt;
&lt;P&gt;The gradient background and bottom border only took a few lines of code to accomplish. Just define a Paint event handler for TableLayoutPanel and go to town:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LinearGradientBrush newBrush = new LinearGradientBrush(new Point(0, 0), new Point(tableLayoutPanel2.Width, tableLayoutPanel2.Height),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Color.White, Color.LightGray);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Graphics.FillRectangle(newBrush, new Rectangle(0, 0, tableLayoutPanel2.Width, tableLayoutPanel2.Height));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Draw a thin border on the bottom.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Black), 1),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new Point(0, tableLayoutPanel2.Height - 1),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new Point(tableLayoutPanel2.Width, tableLayoutPanel2.Height - 1));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE&lt;/STRONG&gt;: One problem with this implementation is that there is some nasty flicker on the TLP when you resize the form. The flicker manifests as a small flash of the form's background at the point where the table cells jut up against one another. I don't know how to fix this; setting Form.DoubleBuffered=True had no effect.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=569367" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item><item><title>Using ToolStrip as a TabControl Alternative in Windows Forms</title><link>http://blogs.msdn.com/winformsue/archive/2006/03/21/557054.aspx</link><pubDate>Tue, 21 Mar 2006 23:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:557054</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/557054.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=557054</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=557054</wfw:comment><description>&lt;P&gt;I've been going back and forth lately with Karl Erickson, another member of our team, and the guy who owns the TabControl docs. It appears that &lt;A href="/winformsue/archive/2006/03/14/551564.aspx"&gt;my gripes with TabControl&lt;/A&gt; weren't mine alone. He's been fielding reports of various weird bugs, such as the visual styles weirdness and the funky way &lt;STRONG&gt;TabControl&lt;/STRONG&gt; handles layout at run time. Basically, the darn thing isn't meant to have its tab layout order changed at run time; properties like Alignment are best set at design time, and then kept like that for the life of your app.&lt;/P&gt;
&lt;P&gt;So, yes: it's possible to hack up TabControl to make right-aligned and left-aligned tabs work.&lt;/P&gt;
&lt;P&gt;Or, you can use &lt;STRONG&gt;&lt;A href="http://lab.msdn.microsoft.com/search/Redirect.aspx?title=ToolStrip+Control+(Windows+Forms)+&amp;amp;url=http://msdn2.microsoft.com/en-us/library/5daaw6hf.aspx"&gt;ToolStrip&lt;/A&gt;&lt;/STRONG&gt; instead.&lt;/P&gt;
&lt;P&gt;&lt;A href="/photos/winformsue/picture557005.aspx"&gt;&lt;STRONG&gt;Picture 1&lt;/STRONG&gt;: ToolStrip Tab Imitator&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The idea is simple. Add a SplitContainer to your form. Make one panel the "nav" panel, and the other the content panel. (You could just Dock it Left, but using SplitContainer makes it easier to resize. And yes, I know that ToolStripContainer exists - I'm still trying to force it to do my bidding.) Add a ToolStrip to the nav panel and set it to Dock=Full. Add image and text for each of the buttons, and use the following settings on each button:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;.DisplayType&lt;/STRONG&gt;=TextAndImage&lt;BR&gt;&lt;STRONG&gt;.ImageAlign&lt;/STRONG&gt;=MiddleLeft&lt;BR&gt;&lt;STRONG&gt;.TextAlign&lt;/STRONG&gt;=MiddleRight&lt;BR&gt;&lt;STRONG&gt;.TextImageRelation&lt;/STRONG&gt;=Overlay&lt;/P&gt;
&lt;P&gt;For the panels themselves, you can develop separate UserControl classes, and switch between them whenever a user clicks a button. You can incorporate interfaces onto the UserControls to test if there is any data that needs to be persisted before switching tabs. E.g., if you're on the Pay Bills tab, and the user has unconfirmed bill payments, you might want to prompt to confirm or discard the transactions.&lt;/P&gt;
&lt;P&gt;Here's another screenshot of a rinky-dink app I've been using as a testbed. I haven't written any of the panels yet, so there's a big gaping hole in the middle there, but this shows how to do the same thing using larger, more stylized buttons on the right hand side. These use .TextImageRelation=ImageBeforeText to make them work. Also, the &lt;STRONG&gt;RenderStyle&lt;/STRONG&gt; of ToolStrip is set to System, and the &lt;STRONG&gt;BackColor&lt;/STRONG&gt; to White to blend in with the buttons. (Don't&amp;nbsp;attempt to use &lt;STRONG&gt;TransparencyKey&lt;/STRONG&gt; when using complex images.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll have to forgive the app's slight klunkiness; I've hacked it to bits recently. And yes, that&amp;nbsp;&lt;STRONG&gt;is&lt;/STRONG&gt; a ToolStrip control I'm using as the title bar!&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.msdn.com/photos/winformsue/picture557040.aspx"&gt;&lt;STRONG&gt;Picture 2&lt;/STRONG&gt;: Right-Aligned Buttons&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The benefits of this approach are numerous. Because you're using ToolStrip, you can use features like drop-down buttons, embedded ComboBoxes, fly-out menus, context menus, etc. ToolStrip is a great "kitchen sink" control that's been designed to do just about anything. It has a modern look and feel by default; you can&amp;nbsp;make it very slick without writing a lick of code.&amp;nbsp;If the&amp;nbsp;built-in renderers&amp;nbsp;don't meet your needs, however, never fear:&amp;nbsp;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms171698.aspx"&gt;ToolStrip can be stylized out the wazoo using a custom renderer&lt;/A&gt;. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=557054" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category><category domain="http://blogs.msdn.com/winformsue/archive/tags/ToolStrip+Control/default.aspx">ToolStrip Control</category></item><item><title>Windows Forms TabControl: Using Right-Aligned or Left-Aligned Tabs</title><link>http://blogs.msdn.com/winformsue/archive/2006/03/14/551564.aspx</link><pubDate>Wed, 15 Mar 2006 01:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:551564</guid><dc:creator>WinFormsUE</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/winformsue/comments/551564.aspx</comments><wfw:commentRss>http://blogs.msdn.com/winformsue/commentrss.aspx?PostID=551564</wfw:commentRss><wfw:comment>http://blogs.msdn.com/winformsue/rsscomments.aspx?PostID=551564</wfw:comment><description>&lt;P&gt;I wanted to do something today that I thought was simple: take a Windows Forms TabControl and &lt;A HREF="/photos/winformsue/picture551562.aspx"&gt;render the tabs horizontally on the right- or left-hand side of the form&lt;/A&gt;. The good news is, it&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; simple. You just have to know the secret sauce to pull it off.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;On TabControl, set the following properties:&lt;/LI&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;.Alignment&lt;/STRONG&gt;=Right&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;.SizeMode&lt;/STRONG&gt;=Fixed (Must be set to change &lt;STRONG&gt;ItemSize.Width&lt;/STRONG&gt;, below)&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;.DrawMode&lt;/STRONG&gt;=OwnerDrawFixed&lt;/LI&gt;&lt;/OL&gt;
&lt;LI&gt;Set the &lt;STRONG&gt;ItemSize&lt;/STRONG&gt; property to&amp;nbsp;the preferred width and height of your tabs. Since we're owner-drawing, we need the tabs to be a fixed width and height so we have a well-defined area in which to draw the tab labels. &lt;BR&gt;&lt;BR&gt;Here's one of the tricky bits, though: Width and height do not flip even though you are now right-aligned. In other words, you have to change the &lt;STRONG&gt;Width&lt;/STRONG&gt; property to change the height (y axis) of the tabs, and change the &lt;STRONG&gt;Height&lt;/STRONG&gt; property to change the width (x axis) of the tabs.&lt;/LI&gt;
&lt;LI&gt;Handle &lt;STRONG&gt;DrawItem()&lt;/STRONG&gt; and define code to render the text the way you want it. Here's a sampling:&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As _&lt;BR&gt;System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim g As Graphics = e.Graphics&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _TextBrush As Brush&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Get the item from the collection.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _TabPage As TabPage = TabControl1.TabPages(e.Index)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Get the real bounds for the tab rectangle.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _TabBounds As Rectangle = TabControl1.GetTabRect(e.Index)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If (e.State = DrawItemState.Selected) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Draw a different background color, and don't paint a focus rectangle.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _TextBrush = New SolidBrush(Color.Red)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.FillRectangle(Brushes.Gray, e.Bounds)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _TextBrush = New System.Drawing.SolidBrush(e.ForeColor)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.DrawBackground()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Use our own font. Because we CAN.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _TabFont As New Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Draw string. Center the text.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim _StringFlags As New StringFormat()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _StringFlags.Alignment = StringAlignment.Center&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _StringFlags.LineAlignment = StringAlignment.Center&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, New StringFormat(_StringFlags))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=551564" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/winformsue/archive/tags/Container+Controls+and+Layout/default.aspx">Container Controls and Layout</category></item></channel></rss>