• 摘录的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

  • 相关阅读:
    随机点名系统
    JQuery
    百度搜索下拉提示
    正则表达式
    严格模式
    CSS引入方式有哪些,区别是什么
    Js中的函数
    float浮动造成高度塌陷的解决办法
    PC端页面开发基础-问题总结(一)
    PC端页面开发基础-IE6常见CSS解析Bug及Hack
  • 原文地址:https://www.cnblogs.com/csharponworking/p/1671553.html
Copyright © 2020-2023  润新知