我正在尝试通过独占代码 View 在标准 Windows 窗体(加载时)上创建/实例化按钮。我正在尝试做这样的事情:
准系统示例: 注意:不要担心这里的格式。我只是总结一下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
SomeClass BlahFooBarBaz
{
private void Form1_Load(object sender, EventArgs e)
{
Button newBtn = new Button();
newBtn.Width = 25;
newBtn.Height = 25;
newBtn.Visible = true;
Point p = new Point(Location.X, y);
newBtn.Text = "Test";
}
}
当我执行这个时,我得到一个空白表格。如果我设置了正确的属性,这段代码会起作用吗?还是我需要做其他事情?
请您参考如下方法:
您需要将按钮添加到表单中:
this.Controls.Add(newBtn);
