I am developing a Windows application based on the Windows Form template. I am using .NET 3.5 version. In this application, the goal is that all the visual settings of various shapes can be controlled from the App.Config file (background color, background color for different buttons, etc.).
So, basically I have a class βFormBaseβ, from which all my forms are inherited, and this class contains this code:
public class FormBase : Form { protected override void OnLoad(EventArgs e) { BackColor = Color.FromName(ConfigurationManager.AppSettings["backColor"]); foreach (var item in this.Controls) { if (item is Button) { ((Button)item).BackColor = Color.FromName(ConfigurationManager.AppSettings["buttonBackground"]); ((Button)item).ForeColor = Color.FromName(ConfigurationManager.AppSettings["buttonText"]); } if (item is ...) {
And then I have an App.Config file that contains code like:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="buttonText" value="White"/> <add key="buttonBackground" value="Red"/> <add key="backColor" value="White"/> <add key="textColor" value="Red"/> </appSettings> </configuration>
And now, in the declaration of all my forms, I have a line
public partial class Form1 : FormBase
My problem is that when I run the application, it works fine and it works, different colors in the App.Config files are the colors displayed in my forms. But when I just look at the designer in Visual Studio without starting the application, the designer cannot display how the form will look, and I get the following error:
Service.Windows.Forms.Design.IEventHandlerService already exists in the service container. Parameter Name: serviceType
And I do not know how to solve this. This is not a huge problem, as the application works fine, but it bothers me, and I would like to know what is happening
inheritance c # xml winforms app-config
Devbob
source share