当前位置: 首页>>代码示例>>C#>>正文


C# GraphicsPath.GetBounds方法代码示例

本文整理汇总了C#中GraphicsPath.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.GetBounds方法的具体用法?C# GraphicsPath.GetBounds怎么用?C# GraphicsPath.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicsPath的用法示例。


在下文中一共展示了GraphicsPath.GetBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPaint

    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.CompositingMode = CompositingMode.SourceOver;

        GraphicsPath stroke = new GraphicsPath();
        stroke.AddString(this.Text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        string tmp = this.Text;
        while (stroke.GetBounds().Width > this.Width - 8) {
            tmp = tmp.Substring(0, tmp.Length - 1);
            stroke = new GraphicsPath();
            stroke.AddString(tmp + "...", this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        }

        RectangleF bounds = stroke.GetBounds();
        Matrix translationMatrix = new Matrix();
        if (this.TextAlign == ContentAlignment.TopRight || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.BottomRight) {
            translationMatrix.Translate(this.Width - bounds.Width - 8, 0);
        } else if (this.TextAlign == ContentAlignment.TopCenter || this.TextAlign == ContentAlignment.MiddleCenter || this.TextAlign == ContentAlignment.BottomCenter) {
            translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, 0);
        }
        if (this.TextAlign == ContentAlignment.MiddleLeft || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.MiddleCenter) {
            translationMatrix.Translate(0, (this.Height - bounds.Height - 5) / 2);
        } else if (this.TextAlign == ContentAlignment.BottomLeft || this.TextAlign == ContentAlignment.BottomCenter || this.TextAlign == ContentAlignment.BottomRight) {
            translationMatrix.Translate(0, (this.Height - bounds.Height - 5));
        }
        stroke.Transform(translationMatrix);
        e.Graphics.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
        e.Graphics.FillPath(Brushes.White, stroke); /* Text */
    }
开发者ID:klange,项目名称:acoustics-windows,代码行数:31,代码来源:TransparentLabel.cs

示例2: updateClock

    /*
    private void updateClock() {
        lblSongTime.Text = timeToString(coolProgressBar1.Value) + " / " + timeToString(coolProgressBar1.Maximum);
        lblSongTime.Refresh();
    }
     */
    private void RenderText(Graphics g)
    {
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.CompositingMode = CompositingMode.SourceOver;

        String text = valueToString(this.Value) + " / " + valueToString(this.Maximum);

        GraphicsPath stroke = new GraphicsPath();
        stroke.AddString(text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
        RectangleF bounds = stroke.GetBounds();
        /* Align right */
        Matrix translationMatrix = new Matrix();
        translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, (this.Height - bounds.Height - 5) / 2);
        stroke.Transform(translationMatrix);
        g.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
        g.FillPath(Brushes.White, stroke); /* Text */
    }
开发者ID:klange,项目名称:acoustics-windows,代码行数:24,代码来源:CoolProgressBar.cs


注:本文中的GraphicsPath.GetBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。