6

I'm writing a Winforms project that needs a settings form. For that settings form, I want to have two modes, a basic and an advanced. I've written the code to make it change between these two, and to save time, I want to have the InitializeComponent() method just call the same method that gets called to switch to the basic mode. I created a partial method like this:

        partial void InitializeComponent()
        {
            BasicSettingsButton_Click(new object(), new EventArgs());
        }

inside my partial class in my program file (not the one the Windows form designer generates), and changed the one in the Window form designer generated code to:

        partial void InitializeComponent();
        //{
        //...
        //}

which I thought was proper syntax for the signature, with the implementing definition as above.

However, when I try to build the code, it tells me it has "no defining declaration found for implementing declaration of partial method InitializeComponent()" and points me to the first code sample I have.

I've checked names, even copying and pasting corresponding names to ensure they're the same, but I still can't get it to run. This is the only error in my code stopping me from building and running. Any ideas?

David Legg
  • 271
  • 1
  • 4
  • 12
  • 1
    The namespace is the same in both halves. They're both in: `public partial class SettingsForm : Form`. Is that the "type-name" you're referring to? – David Legg Nov 20 '12 at 00:14
  • 3
    that's the type-name; is the namespace the same? – Marc Gravell Nov 20 '12 at 07:04
  • 1
    Yes. I have only one namespace, `namespace WindowsFormsApplication1`, and I just used copy and paste to make sure it's the same in all places it's mentioned. Still gives me an error. – David Legg Nov 20 '12 at 17:00
  • is this all in a single project? – Marc Gravell Nov 20 '12 at 18:21
  • Yes. One project, one solution in Microsoft Visual C# Studio 2010. Does the `InitializeComponent()` method have to be in the original spot? I did this in another class (for a different form), leaving the signature in the Designer file and putting my own `InitializeComponent()` method in my program file, and it worked just fine. – David Legg Nov 21 '12 at 00:51
  • it *sounds* like everything should be in place.... hard to answer further without being able to actually see stuff. – Marc Gravell Nov 21 '12 at 08:28
  • 2
    Just figured it out. Had a closing curly bracket in the wrong place, which made the whole thing a nested class when it shouldn't have been. Sorry for the inconvenience. – David Legg Nov 21 '12 at 15:35

0 Answers0