0

I have created a new button class within my project:

using System;
using System.Windows.Forms;

namespace CEditor
{
    public class CustomButton : Button
    {
        public CustomButton()
        {
            this.SetStyle(ControlStyles.Selectable, false);
        }
    } 
}

After I drop the custom button on the form, two lines of code are generated in the designer.cs, each producing the same error:

namespace CEditor
{
    partial class CEditor
    {
        private CEditor.CustomButton button1;
        // Error:
        // The type name 'CustomButton' does not exist in the type 'CEditor.CEditor'

        this.button1 = new CEditor.CustomButton();
        // Error:
        // The type name 'CustomButton' does not exist in the type 'CEditor.CEditor'
    }
}

Everything runs fine, if I remove the "CEditor." parts from both lines, so far so good, but as soon as I generate an event per double-click in the property panel of a control, the designer "repairs" the above lines and I have to delete the "CEditor." parts again, which gets more annoying the more buttons there are.

Is there anything I can do to stop that behavior?

betaFlux
  • 183
  • 1
  • 3
  • 12
  • 3
    This is why you shouldn't give your class the same name as its namespace. http://blogs.msdn.com/b/ericlippert/archive/2010/03/09/do-not-name-a-class-the-same-as-its-namespace-part-one.aspx – SLaks Oct 12 '14 at 14:06
  • You are right, a simple underscore solved this issue. Thanks! – betaFlux Oct 12 '14 at 14:14

1 Answers1

0

This is why you shouldn't give your class the same name as its namespace.

Change either name (eg, CEditorControl) and you'll be fine.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964