如何编写执行此代码的函数
我使用这段代码在 MdiWindow 中制作并显示一个表单:
if (currentForm != null) {
currentForm.Dispose();
}
currentForm = new ManageCompanies();
currentForm.MdiParent = this;
currentForm.Show();
currentForm.WindowState = FormWindowState.Maximized;
我使用这段代码显示大约 20 种不同的表单...
我想编写一个这样的函数:
private void ShowForm(formClassName) {
if (currentForm != null) {
currentForm.Dispose();
}
currentForm = new formClassName();
currentForm.MdiParent = this;
currentForm.Show();
currentForm.WindowState = FormWindowState.Maximized;
}
我是否必须将 formClassName 作为字符串或其他内容发送?以及如何将其包含在代码中...... 我想要最终的代码...
I've used this code to make and show a form in a MdiWindow:
if (currentForm != null) {
currentForm.Dispose();
}
currentForm = new ManageCompanies();
currentForm.MdiParent = this;
currentForm.Show();
currentForm.WindowState = FormWindowState.Maximized;
I used this code to show about 20 different forms...
I want to write a such function:
private void ShowForm(formClassName) {
if (currentForm != null) {
currentForm.Dispose();
}
currentForm = new formClassName();
currentForm.MdiParent = this;
currentForm.Show();
currentForm.WindowState = FormWindowState.Maximized;
}
Do I have to send formClassName as a string or something else; and how to include it in the code...
I want the final code...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试泛型:
或使用反射
Try generics:
Or using reflection
您还必须指定:
注意那里的 new(),以便您可以默认构造 FormClass,否则它不会让您构造它。
You also have to specify:
Note the new() on there so you can default construct the FormClass, otherwise it won't let you construct it.