using System.Drawing;
using System.Windows.Forms;public class Form1 : Form
{
private Rectangle tabArea;
private RectangleF tabTextArea; public Form1()
{
TabControl tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage(); // Allows access to the DrawItem event.
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.Controls.Add(tabPage1);
tabControl1.ItemSize = new Size(80, 30);
tabControl1.Location = new Point(25, 25);
tabControl1.Size = new Size(250, 250);
tabPage1.TabIndex = 0;
ClientSize = new Size(300, 300);
Controls.Add(tabControl1);
TabPage tabPage2 = new TabPage();
tabControl1.Controls.Add(tabPage2);
tabPage2.TabIndex = 1; tabArea = tabControl1.GetTabRect(0);
tabTextArea = (RectangleF)tabControl1.GetTabRect(0);
tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab);
} private void DrawOnTab(object sender, DrawItemEventArgs e)
{
MessageBox.Show(e.Index.ToString());
Graphics g = e.Graphics;
Pen p = new Pen(Color.Red);
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red); g.DrawRectangle(p, tabArea);
g.DrawString("tabPage1", font, brush, tabTextArea);
} static void Main()
{
Application.Run(new Form1());
} private void InitializeComponent()
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); } private void Form1_Load(object sender, System.EventArgs e)
{ }
}
我想重绘tabcontrol,但是只有第一个tab得到了重绘,
using System.Windows.Forms;public class Form1 : Form
{
private Rectangle tabArea;
private RectangleF tabTextArea; public Form1()
{
TabControl tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage(); // Allows access to the DrawItem event.
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.Controls.Add(tabPage1);
tabControl1.ItemSize = new Size(80, 30);
tabControl1.Location = new Point(25, 25);
tabControl1.Size = new Size(250, 250);
tabPage1.TabIndex = 0;
ClientSize = new Size(300, 300);
Controls.Add(tabControl1);
TabPage tabPage2 = new TabPage();
tabControl1.Controls.Add(tabPage2);
tabPage2.TabIndex = 1; tabArea = tabControl1.GetTabRect(0);
tabTextArea = (RectangleF)tabControl1.GetTabRect(0);
tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab);
} private void DrawOnTab(object sender, DrawItemEventArgs e)
{
MessageBox.Show(e.Index.ToString());
Graphics g = e.Graphics;
Pen p = new Pen(Color.Red);
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red); g.DrawRectangle(p, tabArea);
g.DrawString("tabPage1", font, brush, tabTextArea);
} static void Main()
{
Application.Run(new Form1());
} private void InitializeComponent()
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); } private void Form1_Load(object sender, System.EventArgs e)
{ }
}
我想重绘tabcontrol,但是只有第一个tab得到了重绘,
解决方案 »
- winform ftp服务器文件获取问题 紧急
- 关于onPaint事件和wndProcss事件
- C#4.0以后的版本会是什么样子,大家有这方面的信息吗?
- 怎么检测一参数中含有数字?
- 怎样在window madie player控件中添加多首歌曲,在线等
- c# 中空字符串怎么用
- SqlDataReader的sqlCommand是存储过程,如何取得存储过程的返回值?
- 新手在线等,请问高手们如何在C#的winform中,ACCESS中插入数据到指定的地方和修改里面的内容(注:这里最好是同时可以插入到两个表中和同时
- c#写的组件问题
- 怎么样把一个字符串转换为 byte 形式的字符串显示出来
- winForm开发中,怎样能给出数量的“下限提示”?谢大侠,盼回复~~!
- 用C#编写一个可自动更新的小程序,使用Remoting技术
tabArea = tabControl1.GetTabRect(0);
tabTextArea = (RectangleF)tabControl1.GetTabRect(0); //DrawOnTab改成这样就可以了
private void DrawOnTab(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Red);
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red); for (int i = 0; i < tabControl1.TabPages.Count; i++)
{
tabArea = tabControl1.GetTabRect(i);
tabTextArea = (RectangleF)tabControl1.GetTabRect(i);
g.DrawRectangle(p, tabArea);
g.DrawString("tabPage"+(i+1).ToString(),font,brush,tabTextArea); }}