0

I am creating a my account page for my C# application. I have it setup with loads of different edit buttons for different details, i was to make it less tedious to produce and create 1 method which will change the form to the way it is needed.

Here is my code which i hope will stop the code re-use.

   private void OnEditButton(string boxSelected, Size size)
    {
        if (doneBtn.Visible)
        {
            MessageBox.Show("Must edit current detail before editting a new one");
            return;
        }
        lnametxt.Enabled = true;
        lnameLink.Visible = false;
        doneBtn.Visible = true;
        doneBtn.Location = new Point(size);
        TextBoxSelected = boxSelected;
    }

The TextBoxSelected Property tells the database which column they will be changing, so this is a parameter as it will change for each edit link.

What am i trying to do? - I am trying to pass the Size as a parameter to this method. Here is the code that will call the method.

private void lnameLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        OnEditButton("lname", (495, 55));
    }

at "(495, 55)" it has an error i have put the second lots of brackets to try and see if it will work with that there instead of having it on its own. Both show it has 3 parameters.

Here is the idea i am trying to go for, but without the parameters in place:

 private void OnEditButton()
    {
        if (doneBtn.Visible)
        {
            MessageBox.Show("Must edit current detail before editting a new one");
            return;
        }
        lnametxt.Enabled = true;
        lnameLink.Visible = false;
        doneBtn.Visible = true;
        doneBtn.Location = new Point(495, 55);
        TextBoxSelected = "lname";
    }

if you would like any more information then please let me know and i will add it. Thank you in advance

Brendon
  • 334
  • 1
  • 2
  • 14

1 Answers1

5

the function OnEditButton takes two parameters, a string boxSelected and an object size of type Size.

So when you call it you have to do

OnEditButton("lname",  new Size(495.0, 55.0));

You have to pass an instance of the type Size

George Papadakis
  • 1,273
  • 13
  • 22
  • Thank you haha, it was a lot more simple than i first thought, thank you for the help. Now that makes me feel a little stupid because of the simplicity of it - It wont let me select the answer as correct for 4 minutes so give me a few minutes – Brendon May 12 '16 at 14:24
  • Think always OOP thats the way – George Papadakis May 12 '16 at 14:29
  • Yeah, just i didnt think new Size(); which is why i feel stupid haha – Brendon May 12 '16 at 14:30