创建首选项窗口 [英] Creating a preference window

查看:81
本文介绍了创建首选项窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说,我有一个表单类...


公共类MainForm:表单{

private CustomClass cc;


public MainForm(){

DoSomething()

InitializeComponent();

}

///做更多的事情

public void ShowPreference(){

PreferenceForm pf = new PreferenceForm();

pf。 sometextbox.text = cc.something;

///等

pf.ShwoDialog();

}

}


公共类PreferenceForm:表格{

///另一种表格

}


基本上,当用户尝试关闭Preference表单时,我想要它

能够直接在我的主表单中修改我的Custom类....如何

我可以这样做吗?

Let''s say, I have a form class...

public class MainForm : Form {
private CustomClass cc;

public MainForm() {
DoSomething()
InitializeComponent();
}
/// Do something more
public void ShowPreference() {
PreferenceForm pf = new PreferenceForm();
pf.sometextbox.text = cc.something;
/// etc
pf.ShwoDialog();
}
}

public class PreferenceForm: Form {
/// another form
}

Basically, when the user try to close the Preference form, I want it
to be able to modify my Custom class in my main form directly.... how
could I do that?

推荐答案

2007年5月10日星期四13:36:57 -0700,甜瓜< el*****@gmail.com写道:
On Thu, 10 May 2007 13:36:57 -0700, melon <el*****@gmail.comwrote:

[...]

基本上,当用户尝试关闭Preference表单,我希望它能够直接在我的主表单中修改我的Custom类....

我可以这样做吗?
[...]
Basically, when the user try to close the Preference form, I want it
to be able to modify my Custom class in my main form directly.... how
could I do that?



只要该类对您的MainForm类是私有的,您就不能使用PreferenceForm直接修改它。

/>

一种方法是将类公开,并允许PreferenceForm保持对该类实例的

引用。在显示对话框之前,您的MainForm类会给出PreferenceForm的引用(通过

在PreferenceForm的构造函数中传递它,通过设置属性,
通过调用方法,无论如何),然后PreferenceForm可以通过这种方式访问​​

。这个主题的一个细微变化是只需要创建一个公共的

接口(可能是由设置对话框类声明的,但是你可以把它放在任何可以访问的地方的
)您的私人类可以公开并传递给设置对话框。


另一种方法是将对话框输入公开为对话框'类中的属性

然后当我在对话框中使用

时,让该类的客户端使用它们来应用它们。这需要更多的输入,但这意味着

设置对话框与客户端的类无关。在许多情况下,对话框中的

设置是如此特定于客户端,让它知道客户端并不是真正的问题,但有时候你'将会有一个更通用的

对话框。习惯保持

两个分隔意味着你可以在适当的时候重复使用对话框,

而无需进行额外的设计工作。


这些方法中的任何一个对我来说都是可以接受的。哪一个最适合你

主要取决于与你的其他

建筑风格最合适的东西。


Pete

As long as that class is private to your MainForm class, you can''t have
the PreferenceForm modify it directly.

One way is to make the class public and allow the PreferenceForm to keep a
reference to an instance of that class. The reference would be given to
the PreferenceForm by your MainForm class before showing the dialog (by
passing it in the constructor for PreferenceForm, by setting a property,
by calling a method, whatever), and then the PreferenceForm could access
it that way. A slight variation on this theme is to just make a public
interface (probably declared by the settings dialog class, but you could
put it anywhere that is accessible to both) that your private class can
expose and pass to the settings dialog.

Another way is to expose dialog input as properties in the dialog''s class
and then have the client of that class use those to apply them when I use
the dialog. This requires a little more typing, but it means that the
settings dialog isn''t tied to the client''s class. In many cases, the
settings in the dialog are so specific to the client that having it be
aware of the client isn''t really a problem, but sometimes you''ll have a
dialog that is more general-purpose. Being in the habit of keeping the
two seperated means that you can always reuse the dialog when appropriate,
without having to do additional design work.

Any of these methods seem acceptable to me. Which one works best for you
depends mostly just on what seems to fit in best with the rest of your
architectural style.

Pete




" melon" < el ***** @ gmail.com在留言中写道

news:11 ********************** @ h2g2000hsg。 googlegro ups.com ...

"melon" <el*****@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...

让我们说,我有一个表格类......


public class MainForm:Form {

private CustomClass cc;


public MainForm(){

DoSomething()

InitializeComponent();

}

///做更多的事情

public void ShowPreference(){

PreferenceForm pf = new PreferenceForm();

pf.sometextbox.text = cc.something;

/// etc

pf。 ShwoDialog();

}

}


公共类PreferenceForm:表格{

// /另一种形式

}


基本上,当用户尝试关闭Preference表单时,我想要它

能够直接在我的主窗体中修改我的自定义类....如何我可以这样做?b $ b?
Let''s say, I have a form class...

public class MainForm : Form {
private CustomClass cc;

public MainForm() {
DoSomething()
InitializeComponent();
}
/// Do something more
public void ShowPreference() {
PreferenceForm pf = new PreferenceForm();
pf.sometextbox.text = cc.something;
/// etc
pf.ShwoDialog();
}
}

public class PreferenceForm: Form {
/// another form
}

Basically, when the user try to close the Preference form, I want it
to be able to modify my Custom class in my main form directly.... how
could I do that?



将自定义类作为参数传递给PreferenceForm构造函数。


PS

Pass custom class as a parameter in your PreferenceForm constructor.

PS


2007年5月10日星期四14:31:58 -0700,PS< ec *********** @ hotmail.comwrote:
On Thu, 10 May 2007 14:31:58 -0700, PS <ec***********@hotmail.comwrote:

将自定义类作为参数传递给PreferenceForm构造函数。
Pass custom class as a parameter in your PreferenceForm constructor.



这是私人课程。它不能传递给PreferenceForm

构造函数,因为PreferenceForm类无法访问它。

It''s a private class. It can''t be passed to the PreferenceForm
constructor, because the PreferenceForm class doesn''t have access to it.


这篇关于创建首选项窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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