本文整理汇总了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 */
}
示例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 */
}