private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
int with = 0;
int x = 0;
for (int i = 0; i < tabControl1.TabPages.Count; i++)
{
with = tabControl1.TabPages[i].Bounds.Right;
}
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
Bitmap b = new Bitmap("G:\\1.jpg");
e.Graphics.DrawImage(b, e.Bounds); //给tabpage标题背景画图
Pen p = new Pen(Color.Black);
e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text, System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
Rectangle endRec = tabControl1.GetTabRect(tabControl1.TabPages.Count - 1); //最后一个tabpage边框
Rectangle HeaderBackRect = new Rectangle(new Point(endRec.X + endRec.Width, endRec.Y),
new Size(tabControl1.Width - (endRec.X+endRec.Width), tabControl1.Height-tabControl1.TabPages[0].Bounds.Height)); //tabcontrol需要填充的矩形
e.Graphics.DrawImage(b, HeaderBackRect);
}
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
最新推荐文章于 2023-02-15 08:51:35 发布
本文将介绍如何在Windows应用程序中使用自定义图像作为TabControl控件的标签背景,并实现居中显示文本和背景图的技巧。
1410

被折叠的 条评论
为什么被折叠?



