StewKlimp
StewKlimp

Reputation: 49

Send control to method

I'm translating VB.NET code into C#.. there is a problem:

I have a method which gets Control objects and I need to send different controls to it

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

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

But it throws

"The best overloaded method match has some invalid arguments"

this is the VB.NET code:

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

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

How can I do that?

Upvotes: 1

Views: 95

Answers (1)

Karl Anderson
Karl Anderson

Reputation: 34846

Try it without ref, like this:

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

Usage:

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

Upvotes: 1

Related Questions