zoukankan      html  css  js  c++  java
  • 摘录的WinForm control 开发1..BorderLabel

    BorderLabel ,对普通的winform拓展。

    1,可以调整字体位置

    2,可以调整的前景色,后景色

    3,可以调整字体位置 

    关键代码如下。 

    代码
    绘制string对象在画板上:
    //First, we begin by setting the smoothing mode to
                
    //AntiAlias, to reduce image sharpening and improve our drawnings
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

    //使用消除锯齿模型,增加图片的显示质量。
                base.OnPaint(e);
                
    this.drawningPath.Reset();


                
    //Second, lets use a GraphicsPath object and write our string into it.
                
    //Our objective, however, is to measure the how much screen space our
                
    //drawning will occupy.
    在路径中加入字符串
                drawningPath.AddString(
    this.text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size,
                    
    new Point(00), StringFormat.GenericTypographic);

                
    //Then, lets calculate the area occuped by our drawning...
                this.drawningSize = GetPathSize(drawningPath);

                
    //..and remember to sum also the future border size
                this.drawningSize.Height += this.borderSize + 5;
                
    this.drawningSize.Width += this.borderSize + 5;



                
    //Lets determine then how we should align our text in
                
    //the control's area, both horizontally and vertically

                
    //If text is Left-Aligned
                if (this.textAlign == ContentAlignment.TopLeft ||
                    
    this.textAlign == ContentAlignment.MiddleLeft ||
                    
    this.textAlign == ContentAlignment.BottomLeft)
                    
    this.drawningPoint.X = this.Padding.Left;

                
    //If text is Center-Aligned
                else if (this.textAlign == ContentAlignment.TopCenter ||
                         
    this.textAlign == ContentAlignment.MiddleCenter ||
                         
    this.textAlign == ContentAlignment.BottomCenter)
                    drawningPoint.X 
    = (this.Width - this.drawningSize.ToSize().Width) / 2;

                
    //If text is Right-Aligned
                else drawningPoint.X = this.Width - (this.Padding.Right + drawningSize.ToSize().Width);



                
    //If text is Top-Aligned
                if (this.textAlign == ContentAlignment.TopLeft ||
                    
    this.textAlign == ContentAlignment.TopCenter ||
                    
    this.textAlign == ContentAlignment.TopRight)
                    drawningPoint.Y 
    = this.Padding.Top;

                
    //If text is Middle-Aligned
                else if (this.textAlign == ContentAlignment.MiddleLeft ||
                         
    this.textAlign == ContentAlignment.MiddleCenter ||
                         
    this.textAlign == ContentAlignment.MiddleRight)
                    drawningPoint.Y 
    = (this.Height - drawningSize.ToSize().Height) / 2;

                
    //If text is Bottom-Aligned
                else drawningPoint.Y = this.Height - (this.Padding.Bottom + drawningSize.ToSize().Height);




                
    //After that we can reset our path so we can draw the text in the proper place now
                drawningPath.Reset();

                
    //Next, we start add our text into its place, ...
                drawningPath.AddString(this.text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size,
                    
    this.drawningPoint, StringFormat.GenericTypographic);
    //调整字符串对齐方式。
                
    //... and then lets use our pen and draw our text to screen
                e.Graphics.DrawPath(drawningPen, drawningPath);



                
    //So lets reset our path and do it again, but now for the foreground
                drawningPath.Reset();

                
    //Again, we add our text into our path ...
                drawningPath.AddString(this.text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size,
                    
    this.drawningPoint, StringFormat.GenericTypographic);

                
    //... but now, we draw also the foreground
                e.Graphics.FillPath(this.drawningForecolorBrush, drawningPath);
                e.Graphics.DrawPath(drawningPen, drawningPath);

     /Files/csharponworking/BorderLabelTest.rar

  • 相关阅读:
    类的加载与ClassLoader的理解
    反射:获取Class 类的实例(四种方法)
    磁盘调度算法
    死锁检测算法
    银行家算法
    最低松弛度调度算法模拟
    多级反馈队列调度算法
    内存中:请求调页存储管理方式的模拟
    内存的动态分区分配方式的模拟
    “短进程优先”调度算法
  • 原文地址:https://www.cnblogs.com/csharponworking/p/1671553.html
Copyright © 2011-2022 走看看