我正在尝试开发一个控制台应用程序,该应用程序从特定的.txt文件读取并将字符串绘制到表单上,但是即使我能够运行该表单,paint函数也不会被调用。我怎么称呼它?
class Form1 : Form
{
string[] SpielField;
int column;
int line;
public Form1(int c,int l,string[] input)
{
this.Width = 600;
this.Height = 600;
this.column = c;
this.line = l;
SpielField = new string[c];
SpielField = input;
}
public void Form1_Paint(object sender, PaintEventArgs e)
{
for (int i = 0; i < column-2; i++)
{
e.Graphics.DrawString(SpielField[i+2].ToString(), new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
new SolidBrush(Color.Black), 10, 550-i*50);
}
}
}
class Program
{
[STAThread]
static void Main(string[] args)
{
string filePath = System.IO.Directory.GetCurrentDirectory() + "\\maze.txt";
string[] input = File.ReadAllLines(filePath);
int c = Convert.ToInt32(input[0]);
int l = Convert.ToInt32(input[1]);
Form1 form = new Form1(c, l, input);
Application.EnableVisualStyles();
Application.Run(form);
Console.ReadLine();
}
}
窗体被调用并打开,但什么也没画。