本文介绍了如何使一个TabPage的标题文字加粗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中的Windows应用程序的一些TabControl的。它有一些的TabPages。有谁kwows如何使标签页文本成为粗体..?

解决方案

 私人无效tabControl1_DrawItem(对象发件人,DrawItemEventArgs E)
        {

            图形G = e.Graphics;
            刷_TextBrush;

            //从收集的项目。
            TabPage的_TabPage = tabControl1.TabPages [e.Index]

            //获取标签的矩形真正的界限。
            矩形_TabBounds = tabControl1.GetTabRect(e.Index);

            如果(e.State == DrawItemState.Selected)
            {
                //画出不同的背景颜色,不画一个焦点矩形。
                _TextBrush =新SolidBrush(Color.Blue);
                g.FillRectangle(Brushes.Gray,e.Bounds);
            }
            其他
            {
                _TextBrush =新System.Drawing.SolidBrush(e.ForeColor);
               // e.DrawBackground();
            }

            //使用我们自己的字体。因为我们可以。
            字体_TabFont =新的字体(e.Font.FontFamily,(浮点)9,FontStyle.Bold,GraphicsUnit.Pixel);
            //字体FNT =新的字体(e.Font.FontFamily,(浮动)7.5,FontStyle.Bold);

            //绘制字符串。居中的文本。
            的StringFormat _StringFlags =新的StringFormat();
            _StringFlags.Alignment = StringAlignment.Center;
            _StringFlags.LineAlignment = StringAlignment.Center;
            g.DrawString(tabControl1.TabPages [e.Index]。文,_TabFont,_TextBrush,
                         _TabBounds,新的StringFormat(_StringFlags));

        }
 

I have some tabControl in C# Windows app. It has some tabPages. Does anyone kwows how to make the tabPage Text to become Bold..?

解决方案
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {

            Graphics g = e.Graphics;
            Brush _TextBrush;

            // Get the item from the collection.
            TabPage _TabPage = tabControl1.TabPages[e.Index];

            // Get the real bounds for the tab rectangle.
            Rectangle _TabBounds = tabControl1.GetTabRect(e.Index);

            if (e.State == DrawItemState.Selected)
            {
                // Draw a different background color, and don't paint a focus rectangle.
                _TextBrush = new SolidBrush(Color.Blue);
                g.FillRectangle(Brushes.Gray, e.Bounds);
            }
            else
            {
                _TextBrush = new System.Drawing.SolidBrush(e.ForeColor);
               // e.DrawBackground();
            }

            // Use our own font. Because we CAN.
            Font _TabFont = new Font(e.Font.FontFamily, (float)9, FontStyle.Bold, GraphicsUnit.Pixel);
            //Font fnt = new Font(e.Font.FontFamily, (float)7.5, FontStyle.Bold);

            // Draw string. Center the text.
            StringFormat _StringFlags = new StringFormat();
            _StringFlags.Alignment = StringAlignment.Center;
            _StringFlags.LineAlignment = StringAlignment.Center;
            g.DrawString(tabControl1.TabPages[e.Index].Text, _TabFont, _TextBrush,
                         _TabBounds, new StringFormat(_StringFlags));

        }

这篇关于如何使一个TabPage的标题文字加粗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 09:27