我做了某种逻辑,但它得到错误?
这是我的代码
private static void DrawText(String text, Font font, Color textColor, Color backColor)
{
Image img = new Bitmap(640, 360);
Graphics drawing = Graphics.FromImage(img);
Color color = textColor;
if (text.Length <= 80) {
Rectangle displayRectangle =
new Rectangle(new Point(20, 100), new Size(img.Width - 1, img.Height - 1));
} else {
Rectangle displayRectangle =
new Rectangle(new Point(20, 80), new Size(img.Width - 1, img.Height - 1));
}
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
StringFormat format2 = new StringFormat(format1);
// ERROR ON NEXT LINE
drawing.DrawString(text, font, Brushes.Red, (RectangleF)displayRectangle, format2);
drawing.Dispose();
string fileName = "f.png";
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
img.Save(path, System.Drawing.Imaging.ImageFormat.Png);
img.Dispose();
}
错误是
错误1 当前上下文中不存在名称'displayRectangle' C:\Documents and Settings\admin\My Documents\Visual Studio 2008>\Projects\template\template\Form1.cs 119 69 模板
在这一行
drawing.DrawString(text, font, Brushes.Red, (RectangleF)displayRectangle, format2);
在 php 中逻辑是正确的,但是在 C# 中它得到错误?,如何在 C# 中执行此逻辑?
有什么帮助吗?(仍在学习 C#:D)