VS2008中如何用tabControl控件实现纵向选项卡效果
将TabControl 的Alignment 改成Left 或者 Right 就可以了 左右两侧的纵向选项卡
改成left/right后选项卡的文字显示任然有问题
需要自己重写以下drawitem方法,如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//设置DrawMode 为 OwnerDrawFixed 可以再可视化编辑里设置
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
//设置Alignment 为 Left/Right 可以再可视化编辑里设置
this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Left;
//将tabcontrol的drawitem 重写 交给自己写的DrawItem方法
this.tabControl1.DrawItem += new System.Windows.Forms.DrawItemEventHandler
(this.tabControl1_DrawItem);
}
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
StringFormat sf = new StringFormat();
// 设置文字是居中的
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
//画出选项卡文字
e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text,
System.Windows.Forms.SystemInformation.MenuFont,
new SolidBrush(Color.Black),
e.Bounds,
sf);
}
}
}
转载于:https://blog.51cto.com/order/787548