启用/禁用表单? [英] Enable / Disable forms?

查看:78
本文介绍了启用/禁用表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我有两种形式,一种打开另一种形式。开启者在打开另一个窗口时禁用自己

,另一个窗口假设为

在关闭时再次启用第一个窗口。我尝试了这段代码,但是我得知错误'''对象''不包含

''DoEnable''的定义。我是C#的新手,所以希望有一个快速的

方法来解决这个问题...


FORM1:

private void buttonNew_Click(object sender,System.EventArgs e)

{

this.Enabled = false;

NewCDForm myNewCDForm = new NewCDForm(this);

myNewCDForm.Show();

}


public void DoEnable()

{

this.Enabled = true;

}

表格2:

private void NewCDForm_Closed(对象发送者,System.EventArgs e)

{

myCaller.DoEnable();

}


最好的问候,

Andreas

Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "''object'' does not contain a definition for
''DoEnable''". I''m quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas

推荐答案

您是否在Form2的重载构造函数中存储Form引用

作为正确的类型?确保你没有将Form1参考文件存储为

a基本表格。


-

Tim Wilson

..Net Compact Framework MVP

" Andreas" < D9 **** @ efd.lth.se>在消息中写道

news:f7 ************************** @ posting.google.c om ...
Are you storing the Form reference in the overloaded constructor for Form2
as the proper type? Make sure that you''re not storing the Form1 reference as
a basic Form.

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
嗨!

我有两种形式,一种打开另一种形式。当打开另一个窗口时,opener会自动禁用
,而另一个窗口则假设在关闭时再次启用第一个窗口。我尝试了这段代码,但是我得到的错误是''对象''不包含
''DoEnable''的定义。我是C#的新手,所以希望有一个快速的方法来解决这个问题......

FORM1:
private void buttonNew_Click(对象发送者,系统。 EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

表格2:
private void NewCDForm_Closed(对象发送者) ,System.EventArgs e)
{
myCaller.DoEnable();
}

最好的问候,
Andreas
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "''object'' does not contain a definition for
''DoEnable''". I''m quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas



哦,对不起。我还有一个重要的方法,

表2的加载方法设置myCaller = FORM1! (或者至少那是我尝试的b
。)

所以,我的问题仍然存在,为什么我不能调用myCaller.DoEnable()? ?


我不确定你的用法是什么?基本表格蒂姆,我将它存储为

" object"


FORM 1:

private void buttonNew_Click(object sender,System .EventArgs e)

{

this.Enabled = false;

NewCDForm myNewCDForm = new NewCDForm(this);

myNewCDForm.Show();

}


public void DoEnable()

{

this.Enabled = true;

}


表格2:

内部类NewCDForm:System.Windows.Forms.Form

{

object myCaller;

public NewCDForm(object caller)

{

myCaller =来电;

}

private void NewCDForm_Closed(对象发送者,System.EventArgs e)

{

myCaller.DoEnable();

}

}


再次感谢,

Andreas Lundgren


" Tim Wilson" < TIM(下划线)WILSON(AT)ROGERS(PERIOD)COM>在消息新闻中写道:< eZ ************** @ TK2MSFTNGP15.phx.gbl> ...
Oh, sorry. I have one more method of importance, the load-method of
Form 2 that sets myCaller = FORM1! (or at least that is what I try to
do.)
So, my problem is still, why can''t I call myCaller.DoEnable()???

I''m not sure what you ment with "basic Form" Tim, I store it as
"object".

FORM 1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
object myCaller;
public NewCDForm(object caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

Thanks again,
Andreas Lundgren

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message news:<eZ**************@TK2MSFTNGP15.phx.gbl>...
您是否在重载的构造函数中存储Form引用对于Form2
作为正确的类型?确保你没有将Form1参考文件存储为基本表格。

-
Tim Wilson
.Net Compact Framework MVP

安德烈亚斯 < D9 **** @ efd.lth.se>在消息中写道
新闻:f7 ************************** @ posting.google.c om ...
Are you storing the Form reference in the overloaded constructor for Form2
as the proper type? Make sure that you''re not storing the Form1 reference as
a basic Form.

--
Tim Wilson
.Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
嗨!

我有两种形式,一种打开另一种形式。当打开另一个窗口时,opener会自动禁用
,而另一个窗口则假设在关闭时再次启用第一个窗口。我尝试了这段代码,但是我得到的错误是''对象''不包含
''DoEnable''的定义。我是C#的新手,所以希望有一个快速的方法来解决这个问题......

FORM1:
private void buttonNew_Click(对象发送者,系统。 EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

表格2:
private void NewCDForm_Closed(对象发送者) ,System.EventArgs e)
{
myCaller.DoEnable();
}
最好的问候,
Andreas
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "''object'' does not contain a definition for
''DoEnable''". I''m quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas



不将Form存储为Object类型,而是将其存储为实际的Form

类型。编译器需要验证您正在尝试调用的方法实际上是否存在于对象上。所以,让我们说,第一个Form

类引用,即传递给NewCDForm的引用。表格是

称为Form1,然后您需要将其存储为正确的表格类型

而不是对象。


表格2:

内部类NewCDForm:System.Windows.Forms.Form

{

Form1 myCaller;

public NewCDForm(Form1来电)

{

myCaller =来电;

}

private void NewCDForm_Closed (对象发送者,System.EventArgs e)

{

myCaller.DoEnable();

}

}


-

Tim Wilson

..Net Compact Framework MVP


"安德烈亚斯" < D9 **** @ efd.lth.se>在消息中写道

news:f7 ************************** @ posting.google.c om ...
Instead of storing the Form as an Object type, store it as the actual Form
type. The compiler needs to verify that the method that you are attempting
to call actually exists on the object. So, let''s say, that the first Form
class reference, the one that is being passed into the "NewCDForm" Form, is
called "Form1", then you would need to store it as the proper Form type
instead of object.

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
Form1 myCaller;
public NewCDForm(Form1 caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
哦,对不起。我还有一个重要的方法,即表单2的加载方法设置myCaller = FORM1! (或者至少这是我尝试做的事。)
所以,我的问题仍然存在,为什么我不能打电话给myCaller.DoEnable()???
我不确定你用什么基本形式 Tim,我把它存储为
object。

表格1:
private void buttonNew_Click(object sender,System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
表格2:
内部类NewCDForm:System.Windows.Forms.Form
{<对象myCaller;
公共NewCDForm(对象调用者)
myCaller =调用者;
}私有void NewCDForm_Closed(对象发送者,System.EventArgs e)
{
myCaller.DoEnable();
}


再次感谢,
Andreas Lundgren

蒂姆威尔逊 < TIM(下划线)WILSON(AT)ROGERS(PERIOD)COM>在消息中写道
Oh, sorry. I have one more method of importance, the load-method of
Form 2 that sets myCaller = FORM1! (or at least that is what I try to
do.)
So, my problem is still, why can''t I call myCaller.DoEnable()???

I''m not sure what you ment with "basic Form" Tim, I store it as
"object".

FORM 1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
object myCaller;
public NewCDForm(object caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

Thanks again,
Andreas Lundgren

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message



news:< eZ ************** @ TK2MSFTNGP15.phx.gbl> ...


news:<eZ**************@TK2MSFTNGP15.phx.gbl>...

您是否将
Form2的重载构造函数中的Form引用存储为正确的类型?确保您没有将Form1
引用存储为基本表单。

-
Tim Wilson
.Net Compact Framework MVP

安德烈亚斯 < D9 **** @ efd.lth.se>在消息中写道
新闻:f7 ************************** @ posting.google.c om ...
Are you storing the Form reference in the overloaded constructor for Form2 as the proper type? Make sure that you''re not storing the Form1 reference as a basic Form.

--
Tim Wilson
.Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
嗨!

我有两种形式,一种打开另一种形式。当打开另一个窗口时,opener会自动禁用
,而另一个窗口则假设在关闭时再次启用第一个窗口。我尝试了这段代码,但是我得到的错误是''对象''不包含
''DoEnable''的定义。我是C#的新手,所以希望有一个快速的方法来解决这个问题......

FORM1:
private void buttonNew_Click(对象发送者,系统。 EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

表格2:
private void NewCDForm_Closed(对象发送者) ,System.EventArgs e)
{
myCaller.DoEnable();
}
最好的问候,
Andreas
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "''object'' does not contain a definition for
''DoEnable''". I''m quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas



这篇关于启用/禁用表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆