简体   繁体   English

在哪里可以找到有关冒泡的好教程?

[英]Where can I find a good tutorial on bubbling?

I'm new to C# and would like to allow to Windows forms to comminicate with each other. 我是C#的新手,并且希望允许Windows窗体相互简化。 I googled bubbling in C# but it wasn't much help. 用C#在Google上冒泡,但是并没有太大帮助。 What are some good ways I can learn bubbling? 有哪些我可以学习冒泡的好方法?

EDIT : I want to have an options form that is shown/created when my user clicks on Edit->Preferances. 编辑 :我想拥有一个当我的用户单击“编辑”->“首选项”时显示/创建的选项表单。 I then want the settings the user changed in the options form to be relayed to the main form. 然后,我希望将用户在选项表单中更改的设置中继到主表单。

Two approaches: 两种方法:

Put properties on your preferences form and access them from the main form when the user clicks OK. 将属性放在您的首选项表单上,并在用户单击“确定”时从主表单访问它们。

if (preferenceForm.ShowDialog() == DialogResult.OK)
{
     this.Color = preferenceForm.UserSelectedColor;
     //etc...
}

Send your preference form a delegate from the main form and let the preference form call it with the appropriate changes. 从主表单中发送您的首选项表单的委托,并通过适当的更改让首选项表单进行调用。

class FormSettings
{
     object Color {get, set}
}


class MainForm
{
    ...

    void ChangeSettings(FormSettings newSettings)
    { ... }

    void EditPreferences_Click(...)
    {
        ...

        EditPreferencesForm editPreferences = new EditPreferencesForm(this.ChangeSettings)
        editPreferences.ShowDialog();
    }     
}

class EditPreferencesForm
{
     ...
     ChangeSettingsDelegate changeSettings;
     FormSettings formSettings;

     void OkButton_Click(...)
     {
          changeSettings(formSettings);
     }
}

You don't state as much, but is the main form also the form that contains the Edit->Preferences menu? 您不需要说明太多,但是主表单还是包含“编辑”->“首选项”菜单的表单吗? If so, you are already at the correct point in the code 如果是这样,那么您已经在代码中的正确位置了

// This is the event handler in the main form
private void mnuEditPreferencesClicked...
{
    FrmPreferences frmPreferences = new FrmPreferences();
    frmPreferences.ShowDialog(this);
    // Preferences saved, implement changes to main form here
}

If the preferences form is not generated from the main form, fire off an event when the preferences form closes, and have the main form handle the event that way. 如果首选项表单不是从主表单生成的,则在首选项表单关闭时触发事件 ,并让主表单以这种方式处理该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在哪里可以找到关于如何制作简单内容管理系统的C#ASP.NET教程? - Where can I find a C# ASP.NET tutorial on how to make a simple content management system? 在哪里可以找到使用linq和lambda表达式生成动态where和orderby sql的好例子? - where can I find a good example of using linq & lambda expressions to generate dynamic where and orderby sql? 我在哪里可以找到一个很好的 C# 控制台应用程序来演示轮询? - Where can I find a good C# console app that demonstrates polling? 有谁知道我在哪里可以找到一个使用C#的OFX wsdl文件的好例子? - Does anyone know where I can find a good example of using the OFX wsdl file with C#? 我在哪里可以在asp.net mvc 2上找到一些好的在线资源 - Where can I find some good online resources on asp.net mvc 2 我能找到 .NET 4.0 的 WPF 的图表控件教程吗 - Were I can find Chart Controls tutorial for WPF of .NET 4.0 在哪里可以找到 ServiceAccountCredential - where can i find ServiceAccountCredential 在哪里可以找到CSharpEvaluator? - Where can I find CSharpEvaluator? 我在哪里可以看到WPF能够提供的一些好例子? - Where can I see some good examples of what WPF is capable of? 我可以简化一下吗? WPF中的冒泡与隧道? - Can I make this easier? Bubbling vs Tunneling in WPF?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM