Bonjour,

j'aimerai avoir une fonction générique un peu comme ça:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void fnEHAAll<U>(U param)
{
 string[] Types = new string[] { "comboBox", "dateTime", "groupBox", "text" };
/* QUELQUE CHOSE DE DYNAMIQUE ICI POUR TYPER f EN FONCTION DU TYPE DE param
 Form f = param as Form;
 GroupBox f = param as GroupBox;
*/
 for (int i = 0; i < f.Controls.Count; i++)
 {
  if (f.Controls[i].Name.Split(Types, StringSplitOptions.None).Length > 0)
  {
   if (f.Controls[i].Name.Contains("groupBox"))
   {
    fnEHAAll<GroupBox>(((GroupBox)f.Controls[i]));
   }
   else
   {
    f.Controls[i].Validating += new CancelEventHandler(fnVerification);
   }
  }
 }
}
Qui remplacerai mes 2 fonctions actuel:

Pour les Form
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public static void fnEHAAll(Form param)
{
 string[] Types = new string[] { "comboBox", "dateTime", "groupBox", "text" };
 Form f = param as Form;
 for (int i = 0; i < f.Controls.Count; i++)
 {
  if (f.Controls[i].Name.Split(Types, StringSplitOptions.None).Length > 0)
  {
   if (f.Controls[i].Name.Contains("groupBox"))
   {
    fnEHAAll(((GroupBox)f.Controls[i]));
   }
   else
   {
    f.Controls[i].Validating += new CancelEventHandler(fnVerification);
   }
  }
 }
}
Pour les GroupBox
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public static void fnEHAAll(GroupBox param)
{
 string[] Types = new string[] { "comboBox", "dateTime", "groupBox", "text" };
 GroupBox f = param as GroupBox;
 for (int i = 0; i < f.Controls.Count; i++)
 {
  if (f.Controls[i].Name.Split(Types, StringSplitOptions.None).Length > 0)
  {
   if (f.Controls[i].Name.Contains("groupBox"))
   {
    fnEHAAll(((GroupBox)f.Controls[i]));
   }
   else
   {
    f.Controls[i].Validating += new CancelEventHandler(fnVerification);
   }
  }
 }
}
Ici, j'aimerai savoir si il est possible d'instancier dynamiquement un Form ou un GroupBox passer en argument?

Je vous remercie d'avance, si vous pouviez faire la modif de façon à bien être clair.