把标签放到左边就看不字了,怎么回事?请教^^
解决方案 »
- c#使用Firebird.Data.Provider链接Interbase6.5存储过程总是出现问题啊?请高人指教
- c# DataGridView 如何判断是否有选中行
- COM相关问题:这样的事件如何设置?
- C#中換行問題--在線等
- 向数据库插入图片时,发生ORA-25153 临时表空间为空
- 字符串截取邮箱地址
- 请教大家:c#.net winform 程序,需要在课户机器上安装运行,数据库在远程的服务器上,需要怎么个思路做?
- 用DataSet做水晶报表的数据源,ACCESS数据库,出现登录失败的问题
- pictureBox 如何循环播放文件夹里的图片 谢谢各位高手
- Twain 在window7下无法找到高拍设备
- 同样Section 同样Key 同样的值 为什么ini写入分两行
- 请问有在成都 海辉 上班的吗?
/// 自定义 TabControl 的文字显示、注意:只实用于TabControl.Alignment = Right/Left.
/// </summary>
/// <res>注意:只实用于TabControl.Alignment = Right/Left.</res>
public class DrawTabControlItemText
{
static Graphics g;
static StringFormat strFormat;
static Font font;
static SolidBrush brush;
static RectangleF tabTextArea; public enum TabItemType
{
Horizontal, // 横
Vertical, // 竖
} /// <summary>
/// 绘画Tab控件的文字.
/// </summary>
public static void OwnerDrawTabItem(System.Windows.Forms.TabControl tab)
{
tab.DrawMode = TabDrawMode.OwnerDrawFixed;
tab.DrawItem += new DrawItemEventHandler(tab_DrawItem);
} /// <summary>
/// 具体绘画方法.
/// </summary>
private static void tab_DrawItem(object sender, DrawItemEventArgs e)
{
g = e.Graphics;
font = ((System.Windows.Forms.TabControl)sender).Font;
brush = new SolidBrush(((System.Windows.Forms.TabControl)(sender)).TabPages[ e.Index ].ForeColor);
strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
tabTextArea = ((System.Windows.Forms.TabControl)sender).GetTabRect(e.Index); g.DrawString(((System.Windows.Forms.TabControl)(sender)).TabPages[ e.Index ].Text, font, brush, tabTextArea, strFormat);
}
} 调用:DrawTabControlItemText.OwnerDrawTabItem(TabControl);
public void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{
Font f;
Brush backBrush;
Brush foreBrush;
TabControl tabControl1 = (TabControl)sender; if (e.Index == tabControl1.SelectedIndex)
{
//f = new Font(e.Font, FontStyle.Italic | FontStyle.Bold);
f = new Font(e.Font, FontStyle.Regular);
//渐变色
//backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Blue, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
//backBrush = new SolidBrush(Color.Coral);
foreBrush = Brushes.PowderBlue;
}
else
{
f = e.Font;
backBrush = new SolidBrush(e.ForeColor);
foreBrush = new SolidBrush(e.ForeColor);
} //被选择的页文本
string tabName = tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center; e.Graphics.FillRectangle(backBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
e.Graphics.DrawString(tabName, f, foreBrush, r, sf); sf.Dispose();
if (e.Index == tabControl1.SelectedIndex)
{
f.Dispose();
backBrush.Dispose();
}
else
{
backBrush.Dispose();
foreBrush.Dispose();
}
}