gpt4 book ai didi

c# - 如何在 GDI+ 中旋转文本?

转载 作者:可可西里 更新时间:2023-11-01 08:15:23 26 4
gpt4 key购买 nike

我想以特定角度显示给定的字符串。我试图用 System.Drawing.Font 来做到这一点类(class)。这是我的代码:

Font boldFont = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold, GraphicsUnit.Pixel, 1, true);<br/>
graphics.DrawString("test", boldFont, textBrush, 0, 0);

谁能帮帮我?

最佳答案

String theString = "45 Degree Rotated Text";
SizeF sz = e.Graphics.VisibleClipBounds.Size;
//Offset the coordinate system so that point (0, 0) is at the
center of the desired area.
e.Graphics.TranslateTransform(sz.Width / 2, sz.Height / 2);
//Rotate the Graphics object.
e.Graphics.RotateTransform(45);
sz = e.Graphics.MeasureString(theString, this.Font);
//Offset the Drawstring method so that the center of the string matches the center.
e.Graphics.DrawString(theString, this.Font, Brushes.Black, -(sz.Width/2), -(sz.Height/2));
//Reset the graphics object Transformations.
e.Graphics.ResetTransform();

取自here .

关于c# - 如何在 GDI+ 中旋转文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4421381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com