将应用程序设置传递给类库中的控件 [英] Passing application settings to Controls in class library

查看:90
本文介绍了将应用程序设置传递给类库中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我刚刚开始使用应用程序设置功能来保存用户和系统数据.我的应用程序第一次运行时,它会找到各种路径并设置一些用户数据.用户数据然后在运行时保存(最后选择的路径等).

我已经在主窗体中添加了应用程序设置,并在启动时填充了这些设置.但是,这是我的问题.我不知道如何将这些设置传递给我在类库中开发的子控件.

我的项目就是这样的结构

+解决方案代码控制器"(4个项目)
+ CodeControl(Windows应用程序
-属性
-Settings.settings
-MainForm.cs
-app.config
+ DatabaseLib(类库)
+ GuiClassLib(类库)
+ GuiControlLib(类库)
-属性
设置.设置
-app.config
-ReleaseControlBrowser(用户控件)
-BuildManager(用户控制)

在此示例中,ReleaseControlBrowser和BuildManager包含在主窗体中的单独选项卡上.我需要做的是在启动时希望将设置从主窗体传递到子控件(在guicontrollib中),并在运行时让子控件在需要时(在关闭或触发时)更新设置通过诸如build之类的操作).

谁能给我建议吗?我尝试了许多解决方案,包括在GuiControlLib中添加到app.config的链接,但这似乎没有用.

预先感谢,
G

Hi All,
I have just started using the applications settings feature to save user and system data. The first time my application runs it finds a variety of paths and sets up some user data. User data is then saved at run time (last selected path etc).

I have added application settings to my main form and populate these on start up. But here is my problem. I can not figure out how to pass these settings on to sub-controls I have developed in a class library.

my project is structured thus

+ Solution ''codecontroller'' (4 projects)
+ CodeControl (windows application
- Properties
-Settings.settings
- MainForm.cs
- app.config
+ DatabaseLib (class lib)
+ GuiClassLib (class lib)
+ GuiControlLib (class lib)
- properties
Setting.settings
- app.config
- ReleaseControlBrowser (User Control)
- BuildManager (user Control)

In this example ReleaseControlBrowser and BuildManager are included in the main form on separate tabs. What I need to happen is on start up I want to be able to pass settings from the main form to the sub controls (in the guicontrollib) and at run time for the sub-controls to update the settings when required (on close or triggered by an action such as build).

Can anyone give me advice on this? I have tried a number of solution including adding a link to the app.config in the GuiControlLib but this didn''t seem to work.

thanks in advance,
G

推荐答案

仅出于完整性考虑.我已经去了一个单例对象来保存全局设置,并将其与settings.settings结合使用,以允许在运行之间存储这些值.

G
Just for completeness. I have went for a singleton object to hold the global settings and combined this with settings.settings to allow these values to be stored between runs.

G


您可以使用类属性.

在子控件中,主类具有属性,例如

You can use class properties.

In your sub control main class have properties e.g.

public class SubControl1
{
    public Int32 Id
    {
         get;
         set;
    }
    //set more properties here
   //you can access these properties using the this.Id within your class or SubControl1.Id outside your class
}



在主窗体中,可以设置并获取子控件的属性
Google上有许多教程可以帮助您,例如



In from your main form you can set and get the properties for your sub-controls
There are many tutorials on google to help here e.g.

SubControl1.Id = 1; //or get value from your application settings


这篇关于将应用程序设置传递给类库中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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