什么是启动表单构造函数?
我需要将以下代码放入启动表单的构造函数中。
JohnKenedy.BusinessSQLEXPRInstaller _ins =
new JohnKenedy.BusinessSQLEXPRInstaller(
" _ <Installation Display Name>",
"localhost",
"<New database instance name>",
"<new database name>",
"<database password>",
"<database backup filename>");
if (_ins.IsDone == false)
_ins.ShowDialog();
if (_ins.IsRestart == true)
{
Application.Exit();
this.Close();
return;
}
什么是构造函数以及如何访问它?
I need to put following code in the constructor of my startup form.
JohnKenedy.BusinessSQLEXPRInstaller _ins =
new JohnKenedy.BusinessSQLEXPRInstaller(
" _ <Installation Display Name>",
"localhost",
"<New database instance name>",
"<new database name>",
"<database password>",
"<database backup filename>");
if (_ins.IsDone == false)
_ins.ShowDialog();
if (_ins.IsRestart == true)
{
Application.Exit();
this.Close();
return;
}
What is a constructor and how do I access it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
构造函数是以类(在本例中是您的表单)命名的方法。这将在您的表单显示之前关闭代码,人们会想知道为什么表单需要这么长时间才能显示。即使这不是问题,这看起来像是您的应用程序安装的一部分,您不想将其放在这里。事实上,你问这个问题表明你只是在学习,所以这就是为什么我回答你的问题,但你被否决的原因是因为你在寻求帮助做一些你不会做的事情平时想做的事。
首先,您应该了解构造函数和表单的 Load 事件之间的差异。如果您确实需要触发一些需要一段时间并且必须在此处执行的操作,那么我建议您从 Load 事件而不是构造函数中执行此操作。如果发生错误并且发生在构造函数中,则调试可能比发生在 Load 事件中且表单对象已完全实例化时更困难。
The constructor is the method that's named after the class (which in this case is your form). This is going to set the code off before your form shows and people will be wondering what is taking so long for the form to show up. Even if that were not a problem, this looks like part of the installation for your app which you wouldn't want to put here. The fact that you're asking this question though is an indication that you're just learning so that's why I'm answering your question but the reason you got downvoted is because you're asking for help in doing something that you wouldn't normally want to do.
First you should read up on the differences between the constructor and form's Load event. If you do need to fire something off that's going to take a while and have to do it here then I would recommend doing it from the Load event rather than the constructor. If there's an error and it happens in the constructor it may be more difficult to debug than if it's in the Load event and the form object is already fully instantiated.