开发者

Modify Config file when User Control is added to form

开发者 https://www.devze.com 2023-02-22 19:39 出处:网络
I have built a User Control library that has a reference to a WCF service. I would like to add the WCF Configuration information to the app.config file of the host project, which will be a Windows For

I have built a User Control library that has a reference to a WCF service. I would like to add the WCF Configuration information to the app.config file of the host project, which will be a Windows Forms app, when the User Control is dropped onto the Form. Is there a good way to do this? My thought is that in the control's load event I could add the necessary section to 开发者_C百科the config file.

Basically, I'm looking for a way to update a host application's config file, when the host app adds the User Control. This of course would be at design time.


Yeah, you can update the config file programmatically. Trouble writing programmatic config changes for WCF


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

精彩评论

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