Remove a pad around a Tab control in WinForms

Possible duplicate:
How to remove border indentation in container controls in WinForms?

I developed the Winforms application in Visual studio 2008. In the main form, I have tab management . Now I am trying to use the background image in a tab. The problem I am facing is that the tab control has a thick border around it. Also, the tab control does not cover the entire form, leaving an upper border between the form and the bookmark. (I have tab alignment below bottom). So the border around the tab control and the space bar at the top make my page look ugly. I tried to give the same image as the background to be formed, but the tab control panel plays in spoilsport.

Any ideas to make my design better would be appreciated.

Screen shot

+4
source share
1 answer

I agree with most of the comments made here. The standard TabControl is very poorly drawn on the Microsoft Part ... even in Windows Vista / 7 it does not look great! You better write your own implementation, inheriting TabControl, and then attracting the extra material that you want.

You can use this as a template for your new control. You just need to add some cool design / drawing work to the OnPaint and OnPaintBackground methods.

namespace CustomControls { #region USING using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; #endregion public class CustomTabControl : TabControl { #region VARIABLES private int hotTrackTab = -1; #endregion #region INSTANCE CONSTRUCTORS public CustomTabControl() : base() { this.InitializeComponent(); } #endregion #region INSTANCE METHODS private void InitializeComponent() { this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.DrawMode = TabDrawMode.OwnerDrawFixed; } private int GetTabUnderCursor() { Point cursor = this.PointToClient(Cursor.Position); for (int index = 0; index < this.TabPages.Count; index++) { if (this.GetTabRect(index).Contains(cursor)) { return index; } } return -1; } private void UpdateHotTrack() { int hot = GetTabUnderCursor(); if (hot != this.hotTrackTab) { if (this.hotTrackTab != -1) { this.Invalidate(this.GetTabRect(this.hotTrackTab)); } this.hotTrackTab = hot; if (this.hotTrackTab != -1) { this.Invalidate(this.GetTabRect(this.hotTrackTab)); } this.Update(); } } #endregion #region OVERRIDE METHODS protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.UpdateHotTrack(); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); this.UpdateHotTrack(); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); this.UpdateHotTrack(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); switch (this.Alignment) { case TabAlignment.Bottom: case TabAlignment.Left: case TabAlignment.Right: case TabAlignment.Top: default: throw new NotImplementedException(); } } protected override void OnPaintBackground(PaintEventArgs pevent) { base.OnPaintBackground(pevent); } #endregion } } 

Keep in mind that the code above draws an absolutely empty TabControl that only displays a DisplayRectangle. Everything else, including the tabs you need for yourself!

In addition, in order to draw backgrounds for individual tabs, you may need to override and customize TabPage, but you can only achieve the result you are looking for with a custom tab control.

Check it out http://www.codeproject.com/Articles/42046/Customized-TabControl-by-Repainting-Microsoft-s-Pa

IMHO This is better ... http://www.codeproject.com/Articles/38014/KRBTabControl

IMHO, this is even better ... http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition

also look at the VB Forums ... I know that I have some awesome user tab controls!

+2
source

All Articles