微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c#TabControl控件左边选项卡左边显示,文字横向显示

c#TabControl控件左边选项卡左边显示,文字横向显示
  259人阅读  评论(0)  收藏  举报

  分类

 代码简单移动


public class TabControlNF : System.Windows.Forms.TabControl

    {
        public TabControlNF()
        {
            InitializeComponent();
            TabSet();
        }


        /// <summary>
        /// 设定控件绘制模式
        /// </summary>
        private void TabSet()
        {
            this.DrawMode = TabDrawMode.OwnerDrawFixed;
            this.Alignment = TabAlignment.Left;
            this.SizeMode = TabSizeMode.Fixed;
            this.Multiline = true;
            this.ItemSize = new Size(50,210);
        }


        /// <summary>
        /// 重绘控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabLeft_DrawItem(object sender,DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            Font font = new Font("微软雅黑",10.0f); 
            SolidBrush brush = new SolidBrush(Color.Black);
            RectangleF tRectangleF = GetTabRect(e.Index);
            StringFormat sf = new StringFormat();//封装文本布局信息 
            sf.LineAlignment = Stringalignment.Center;
            sf.Alignment = Stringalignment.Near;
            g.DrawString(this.Controls[e.Index].Text,font,brush,tRectangleF,sf);
        }


        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabLeft_DrawItem);
            this.ResumeLayout(false);
        }

    }


结果显示

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐