VSCode向不工作的表单添加控件



我有一个win forms项目设置在Visual Studio Code与Program.cs, form .cs等。当窗口加载时,我试图向Form1添加控件,但它似乎不起作用。

这是我的代码:

public void Form1_Load(object sender, System.EventArgs e)
{
Console.WriteLine("form loaded!");
//cant see this debug log in output
//program main window launch
Button startButton = new Button();
startButton.Name = "startButton1";
startButton.Click += (sender, e) => {
//start button clicked
MessageBox.Show("siema");
};
this.Controls.Add(startButton);
startButton.Show();
startButton.Location = new Point(0, 0);
startButton.AutoSize = false;
startButton.Size = new Size(80, 80);
startButton.Text = "fuck you bitch";
startButton.BringToFront();
startButton.Invalidate();
this.Refresh();
}

我试过把相同的代码InitializeComponent(),但没有效果。

似乎dotnet new winforms在bin/Debug中创建了两个单独的文件夹它将项目构建为Debug/net7.0-windows,同时从Debug/net7.0/project.exe

运行可执行文件。每次构建时,我都必须运行正确的可执行文件:/