1

我正在将 VB.NET 代码翻译成 C#.. 有一个问题:

我有一个获取Control对象的方法,我需要向它发送不同的控件

private void ApplyToAllPictureBoxes(ref Control oControl, ViewMode Mode)
{
    // ...
}

ApplyToAllPictureBoxes(ref Panel1, Mode);
ApplyToAllPictureBoxes(ref myFlowLayoutPanel, Mode);

但它抛出

“最好的重载方法匹配有一些无效的参数”

这是 VB.NET 代码:

Private Sub ApplyToAllPictureBoxes(ByRef oControl As Control, ByVal Mode As ViewMode)
    ' ... '
End Sub

ApplyToAllPictureBoxes(myFlowLayoutPanel, Mode)
ApplyToAllPictureBoxes(Panel1, Mode)

我怎样才能做到这一点?

4

1 回答 1

1

试试不带ref,像这样:

private void ApplyToAllPictureBoxes(Control oControl, ViewMode Mode)
{
    // ...
}

用法:

ApplyToAllPictureBoxes(Panel1, Mode);
ApplyToAllPictureBoxes(myFlowLayoutPanel, Mode);
于 2013-11-13T16:40:43.743 回答