在我的项目" teacher_gui_windows_form"我试图将我从工具箱中创建的userControl拖到我的表单" teacher_gui"但它给了我错误: "无法创建组件' StudentControl'。错误消息如下:System.MissingMethodException类型' teacher_gui_windows_form.StudentControl'上的构造函数没找到。"
但我确实有一个StudentControl构造函数。 StudentControl类使用另一种形式,这是它的类代码:
public partial class StudentControl : UserControl
{
const int Num = 10;
Image image;
string message;
public StudentForm studentForm = null;
public StudentControl(Image image, string Ip, int index)
{
InitializeComponent();
this.image = image;
pictureBoxImage.Image = image;
labelIp.Text = Ip;
Location = new Point(index % Num * (Width + 5), index / Num * (Height + 5));
}
public void ChangeImage(Image image)
{
pictureBoxImage.Image = image;
}
private void StudentControl_Click(object sender, EventArgs e)
{
studentForm = new StudentForm(pictureBoxImage.Image);
studentForm.ShowDialog();
}
private void pictureBoxImage_Click(object sender, EventArgs e)
{
studentForm = new StudentForm(pictureBoxImage.Image);
studentForm.ShowDialog();
}
private void labelIp_Click(object sender, EventArgs e)
{
studentForm = new StudentForm(pictureBoxImage.Image);
studentForm.ShowDialog();
}
private void seizeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void sendMessageToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
有谁知道为什么会这样? 谢谢!
答案 0 :(得分:5)
要创建UserControl的实例,Windows窗体设计器需要无参数构造函数。它对当前构造函数所需的参数(Image image, string Ip, int index
)一无所知,也不会自动生成虚假值。