[英]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.