Reputation: 43
I had long time developing windows applications using VB.NET and one of thing that I was always use is:
Class (Test) and inside it there are some subs like the following:
VB.NET Code
Friend Sub FLoadKeyLock(ByVal FRMNAME As Object)
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
End Sub
Where FRMNAME refers to forms name that I send from different forms and I use (me) keyword to send current form name to apply that sub.
That was totally works fine in VB.NET but I cannot use it the same way in C#.NET.
C#.NET Code
internal void FLoadKeyLock (Form FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}
The Error is: System.Windows.Forms.Form' does not contain a definition for 'Button3' and no extension method 'Button3' accepting a first argument of type
And same error for all used buttons.
So I have two questions:
1 - How to use such a function in C#.NET?
2 - Why it's not working the same way as VB.NET?
Upvotes: 0
Views: 58
Reputation: 43
As @Maarten said. dynamic has solved my problem
internal void FLoadKeyLock (dynamic FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}
Upvotes: 1