Search code examples
c#parameterslocationsystem.drawinglinklabel

How to pass a System.Drawing.Size as a parameter to a method


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


Solution

  • 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