ある種のロジックを実行していますが、エラーが発生していますか?
ここに私のコード
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# でこのロジックをどのように実行していますか?
何か助けはありますか?( :D を実行して、まだ C# を学習しています)