开发者

How do I set up the App.Config for my UserControl?

开发者 https://www.devze.com 2023-03-13 06:26 出处:网络
I\'m developing a UserControl in a Winform application in VS2010.I did this inside a UserControlLibrary project as it seemed logical.However, when I run, the App.Config tha开发者_StackOverflow中文版t

I'm developing a UserControl in a Winform application in VS2010. I did this inside a UserControlLibrary project as it seemed logical. However, when I run, the App.Config tha开发者_StackOverflow中文版t I have in that project is not being read at all, which is causing all kinds of problems.

Is there a different way I'm supposed to do App.Config's in this situation?


individual controls don't have their own App.Config. The app.config of the executing program that hosts the control is used (or the web.config if you're using asp.net). You need to copy the settings out of the user controls config and put them in the config for the winform project.


copy all keys you want from app.config file of UserControlLibrary project into app.config of your winform application


Not sure if it's possible to load any app.config file during design time user control load. You can prevent the need to though by wrapping your user control load methods with:

private void myUserControl_Load(object sender, EventArgs e)
{
    if (!this.DesignMode)
    {
        //....stuff
    }            
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号