我同意大多數這裏提出的意見。標準的TabControl在微軟的部分上畫得很差......即使在Windows Vista/7中,它看起來也不太好!您最好通過繼承TabControl編寫自己的自定義實現,然後繪製所需的其他內容。
您可能會考慮將其用作新控件的模板。你只需要添加一些很酷的設計/繪圖工作到OnPaint和OnPaintBackground方法。
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
}
}
請記住,上面的代碼繪製了一個絕對空白的TabControl,它只顯示DisplayRectangle。其他一切包括你需要自己做的標籤!
此外,要爲單個TabPages繪製背景,您可能還需要重寫和自定義實現TabPage,但是您可能只需使用自定義選項卡控件即可實現所需的結果。
檢查了這一點 http://www.codeproject.com/Articles/42046/Customized-TabControl-by-Repainting-Microsoft-s-Pa
恕我直言,這是更好的... ... http://www.codeproject.com/Articles/38014/KRBTabControl
恕我直言,這是更好... http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition
也期待VB的論壇...我知道我看起來有一些很棒的自定義選項卡控件!
截圖將幫助很多**。 – CodeCaster 2012-08-08 11:07:59
繼承該控件並按照您希望的方式繪製它。這就是人們如何能夠擁有不是正方形和/或矩形的按鈕。我不明白投訴。簡單的解決方案是設計你自己的沒有這個邊框的控件。 – 2012-08-08 11:22:05
哦!你如何做到這一點?更多的細節請 – Cdeez 2012-08-08 11:23:55