• VerticalLabel的简单实现


    一早收到CodeProject的订阅邮件,大概看了一下。里面有一个做VerticalLabel的例子,我没看,就想自己做一个试试。抛砖引玉!

    VerticalLabel.JPG

    using System;
    using System.Drawing;
    using System.Windows.Forms;

    namespace Webb.Publics.WinForm
    {
        
    /// <summary>
        
    /// Summary description for VerticalLabel.
        
    /// </summary>

        public class VerticalLabel : System.Windows.Forms.Label
        
    {
            
    private int _Span = 0;
            
    public int TextSpan
            
    {
                
    get{return this._Span;}
                
    set{
                    
    this._Span = value;
                    
    this.Refresh();
                }

            }


            
    public VerticalLabel()
            
    {
                
    //
                
    // TODO: Add constructor logic here
                
    //    
                this.Width = 35;
                
    this.Height = 100;
            }
        

            
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            
    {
                
    //base.OnPaint (e);
                SizeF m_size = e.Graphics.MeasureString(this.Text,this.Font);
                
    float m_SingleWidth = m_size.Width/this.Text.Length+2;
                
    float m_SingleHeight = m_size.Height;
                
    float m_TotalWidth = m_SingleWidth;
                
    float m_TotalHeight = m_size.Height*this.Text.Length;
                
    //int i = 0;
                PointF m_Offset = this.MeasurePosition(m_TotalWidth,m_TotalHeight);
                
    for(int i = 0;i<this.Text.Length;i++)
                
    {
                    RectangleF m_Rec 
    = new RectangleF(m_Offset.X,m_Offset.Y+(m_SingleHeight+this.TextSpan)*i,m_SingleWidth,m_SingleHeight);
                    e.Graphics.DrawString(
    this.Text.Substring(i,1),this.Font,new SolidBrush(this.ForeColor),m_Rec);
                }

            }


            
    private PointF MeasurePosition(float i_TotalWidth,float i_TotalHeight)
            
    {
                PointF m_Result;
                
    switch(this.TextAlign)
                
    {
                    
    //Bottom
                    case ContentAlignment.BottomCenter:
                        m_Result 
    = new PointF((this.Width-i_TotalWidth)/2,this.Height-i_TotalHeight);
                        
    break;
                    
    case ContentAlignment.BottomLeft:
                        m_Result 
    = new PointF(0,this.Height-i_TotalHeight);
                        
    break;
                    
    case ContentAlignment.BottomRight:
                        m_Result 
    = new PointF(this.Width-i_TotalWidth,this.Height-i_TotalHeight);
                        
    break;
                    
    //Middle
                    case ContentAlignment.MiddleCenter:
                        m_Result 
    = new PointF((this.Width-i_TotalWidth)/2,(this.Height-i_TotalHeight)/2);
                        
    break;
                    
    case ContentAlignment.MiddleLeft:
                        m_Result 
    = new PointF(0,(this.Height-i_TotalHeight)/2);
                        
    break;
                    
    case ContentAlignment.MiddleRight:
                        m_Result 
    = new PointF(this.Width-i_TotalWidth,(this.Height-i_TotalHeight)/2);
                        
    break;
                    
    //Top
                    case ContentAlignment.TopCenter:
                        m_Result 
    = new PointF((this.Width-i_TotalWidth)/2,0);
                        
    break;
                    
    default:
                    
    case ContentAlignment.TopLeft:
                        m_Result 
    = new PointF(0,0);
                        
    break;                
                    
    case ContentAlignment.TopRight:
                        m_Result 
    = new PointF(this.Width-i_TotalWidth,0);
                        
    break;
                }

                
    return m_Result;
            }

        }

    }


    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;

    namespace WindowsApplication1
    {
        
    /// <summary>
        
    /// Summary description for Form5.
        
    /// </summary>

        public class Form5 : System.Windows.Forms.Form
        
    {
            
    private System.Windows.Forms.PropertyGrid propertyGrid1;
            
    private Webb.Publics.WinForm.VerticalLabel verticalLabel2;
            
    /// <summary>
            
    /// Required designer variable.
            
    /// </summary>

            private System.ComponentModel.Container components = null;

            
    public Form5()
            
    {
                
    //
                
    // Required for Windows Form Designer support
                
    //
                InitializeComponent();

                
    //
                
    // TODO: Add any constructor code after InitializeComponent call
                
    //
            }


            
    /// <summary>
            
    /// Clean up any resources being used.
            
    /// </summary>

            protected override void Dispose( bool disposing )
            
    {
                
    if( disposing )
                
    {
                    
    if(components != null)
                    
    {
                        components.Dispose();
                    }

                }

                
    base.Dispose( disposing );
            }


            
    Windows Form Designer generated code

            
    private void Form5_Load(object sender, System.EventArgs e)
            
    {
            
            }

        }

    }

  • 相关阅读:
    lxml webdriver 抓取街拍
    python 正则抓取古诗词
    2021 最新版 Spring Boot 速记教程
    hbase 命令查看表大小
    Spring AOP,应该不会有比这更详细的介绍了!
    SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等
    API接口的安全设计验证:ticket,签名,时间戳
    5.控制台输出空心菱形
    4.灯泡开关问题
    EXCEL函数
  • 原文地址:https://www.cnblogs.com/WuCountry/p/838599.html
Copyright © 2020-2023  润新知