i have a simple usercontrol with following properties:
public partial class RichTextEditorControl : UserControl
{
public string EditorText
{
get { return richTextBox1.Rtf; }
set { richTextBox1.Rtf = value; }
}
public string EditorPlainText
{
get { return richTextBox1.Text; }
set { richTextBox1.Text = value; }
}
}
Now whenever I EDIT a form which contains this control, VS fills its designer file with the following code line, and then throws a designer error :
this.richTextEditorControl1.EditorPlainText =
global::Project.Resources.MyResources_de_DE.SomeString;
Now I don’t know where it gets this value from ??? I’ve searched entire solution, and nowhere there’s mention of this var, except for 1 file, where it’s needed …
Moreover, the code VS writes, has an error in it ?! It doesn’t compile …
The only thing I can do is edit the designer file, but the next time I have to edit the form with the designer, the same error happens again …
Error 25 The type or namespace name 'MyResources_de_DE' does not exist
in the namespace 'Project.Resources' (are you missing an assembly reference?)
Where on earth is VS getting this value from ??
In this case you would think that the designer would compare the value you set in the usercontrol’s property panel (when placed in the consumer) to the value that the property has when the object is first created, and only produce a line of code in the usercontrol consumer’s designer file if the values are different. Not so. You need to throw on an attribute like this right in front of the declaration:
Delete the errant line from the designer and try rebuilding. This will stop the problem.
Sometimes you’ll need to do other fancy stuff to get this to fit, e.g., if your property is of type ‘control’ you would have to use this to get it to tell the designer not to generate extra (useless) code if the property were usually Null:
You should do this even if you don’t care, in case you are refactoring and removing a no-longer or little used method (which you can of course only do if you control all the consuming code) – there are fewer lines to delete from designer files saying things like ‘MyUserControl.UselessProperty=Nothing’.
Good luck.