I am trying to make a Generic FindControl method and I get the following error:
Cannot convert type ‘System.Windows.Forms.Control’ to ‘T’
Code:
public T Control<T>(String id)
{
foreach (Control ctrl in MainForm.Controls.Find(id, true))
{
return (T)ctrl; // Form Controls have unique names, so no more iterations needed
}
throw new Exception("Control not found!");
}
try this