zoukankan      html  css  js  c++  java
  • 一个button上两种字体 重写OnPaint方法

     public class XButton : Button
        {
            public XButton()
            {
                UseVisualStyleBackColor = false;
                TextImageRelation = TextImageRelation.ImageAboveText;
            }
            public override string Text
            {
                get { return ""; }
                set { base.Text = value; }
            }
            public string LeftText { get; set; }
            public string RightText { get; set; }
            protected override void OnPaint(PaintEventArgs pevent)
            {
                base.OnPaint(pevent);
                Rectangle rect = ClientRectangle;
                rect.Inflate(-5, -5);
                using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far })
                {
                    using (Brush brush = new SolidBrush(ForeColor))
                    {
                        Font font= new Font(Font,FontStyle.Bold);
                        pevent.Graphics.DrawString(LeftText, font, brush, rect, sf);
                        sf.Alignment = StringAlignment.Far;
                        pevent.Graphics.DrawString(RightText, Font, brush, rect, sf);
                    }
                }
            }
        }
    
    private void Form1_Load(object sender, EventArgs e)
            {
                XButton button = new XButton();
                button.LeftText = "hello";
                button.RightText = "test";
                this.Controls.Add(button);
            }
    

      

  • 相关阅读:
    queue
    hiho1095(二分)
    uvaliva3942(trie树)
    hiho1014(trie树)
    uvalive4329(树状数组)
    Dropping tests POJ
    linux mysql命令
    linux文件系统和mount(硬盘,win分区,光驱,U盘)
    linux共享windows资料
    linux常用命令
  • 原文地址:https://www.cnblogs.com/jack-jun/p/10837096.html
Copyright © 2011-2022 走看看