简体   繁体   中英

C# - In a method, how can I have 2 parameters that are one?

In my project I have forms and user controls. I have this important method for changing the mouse cursor.

public static void Cursor_Hand(Form frm)
{
      foreach (Control control in frm.Controls)
      {
            if (control.Cursor == Cursors.Hand)
            {
                 control.Cursor = Program.SystemHandCursor;
            }
      }
 }

However, it only works if I submit a Form as an argument, I need it to accept Form and Usercontrol.

If possible, I also need both to have the same name, so I don't have to check with IF which argument was sent.

Ignore the wrong syntax, but I wanted something like:

public static void Cursor_Hand(Form frm || UserControl frm)

Both of those types inherit from Control :

public static void Cursor_Hand(Control frm)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM