简体   繁体   English

C# - 在一个方法中,我怎样才能有 2 个参数是一个?

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

In my project I have forms and user controls.在我的项目中,我有 forms 和用户控件。 I have this important method for changing the mouse cursor.我有这个改变鼠标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.如果可能的话,我还需要两者都具有相同的名称,因此我不必检查 IF 发送了哪个参数。

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 :这两种类型都继承自Control

public static void Cursor_Hand(Control frm)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在C#中使用默认参数吗? - Can I have defaults for parameters in C#? 如何在C#中包装带有可选参数的方法? - How can I wrap a method with optional parameters in C#? C#:我可以或如何为方法参数指定属性吗? - C#: Can I or how to assign attributes to method parameters? 如何在方法中使用抽象参数? - How Can I have abstract parameters in method? 我的 c# 表单应用程序 (10-20) 中有非常相似的图表。 如何使用一种可以将图表名称作为变量传递的方法对图表进行编程? - I have very similar charts in my c# form app (10-20). How can I program this charts with one method where I can pass the chart name as variable? 在C#4中,如何在具有重载构造函数的父类的子类中具有带可选参数的构造函数? - In C# 4, how can I have constructors with optional parameters in a subclass of a parent with an overloaded constructor? 在C#中,是否可以使用“尽可能多的参数”调用方法(具有默认参数)? - In C#, is it possible to call a method (which has default parameters) with “as many parameters as I have”? C#-如何确保静态方法直接影响其参数,而不仅仅是实例? - C# - How can I insure a static method effects its parameters directly and not just instances? C#MVC - 如何在Controller中传递一些方法参数作为参数? - C# MVC - How can I pass some method arguments as parameters inside a Controller? 如何使用C#通过POST方法将参数从网站发布到HttpHandler - How can I post parameters from web site to HttpHandler with POST method using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM