C#中ShowDialog()方法的问题。 [英] Problem with ShowDialog() method in C#.
本文介绍了C#中ShowDialog()方法的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将表单调用到另一个表单,但我希望调用表单显示为对话框(不调整大小)。我将参数传递给我的new_customer表单的构造函数。
所以我的代码是: -
I want to call a form to another form, but I want the calling form shows like dialog box(not resizing). I passing parameter to my new_customer form's constructor.
so My code is :-
new_customer NC = new new_customer(null);
NC.ShowDialog();
我的new_customer表单构造函数: -
My new_customer form constructor :-
public new_customer(string formType="save")
{
InitializeComponent();
DC = new Data_Conn(Application.StartupPath);
DC1 = new Data_Conn(Application.StartupPath);
paraModi = formType;
}
问题是当我从另一个表单调用new_customer表单时,它的构造函数不执行,这就是我使用该变量时出错的原因:
Problem is when I call new_customer form from another form, its constructor doesn't execute,that's why I get an error when I use that variable :
Object reference not set to an instance of an object.
谢谢在高级..
thanks In advanced ..
推荐答案
你好,
你正在向第二个表单发送null尝试:
hello,
You are sending null to the second form try:
new_customer NC = new new_customer("save");//the string that you need to sent
NC.ShowDialog();
:
on the new_customer form :
public partial class new_customer: Form
{
string formType;
public new_customer(string formType)//formType=save that you have sent
{
this.formType=formType;
InitializeComponent();
DC = new Data_Conn(Application.StartupPath);
DC1 = new Data_Conn(Application.StartupPath);
paraModi = formType;
};
}
这篇关于C#中ShowDialog()方法的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文