1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
public class UCEspaces : Usercontrol
{
public void delegate ClickMonUcHandler(Object sender);
public ClickMonUcHandler ClickMonUcEvent = null;
public UCEspaces()
{
Initialze...(); //je sais plus trop
}
private void pictureBoxEspace_Click(object sender, EventArgs e)
{
//sur le clic de ton usercontrol tu appelles un autre evenement qui sera lié à ton formulaire
if( ClickMonUcEvent!= null)
ClickMonUcEvent(sender);
}
}
public class MaForm : Form
{
//Lors du click sur le bouton
private void pSToolStripMenuItem_Click(object sender, EventArgs e)
{
int i = 0;
int x = 0;
int y = 0;
GestionDesPanneaux();
panelPS.Visible = true;
var espaces = (from esp in this.dc.Espaces where esp.esp_esp == null select esp).ToList();
UCEspaces ucEspaces;
foreach (Espaces espace in espaces)
{
//Création des Users Controls
ucEspaces = new UCEspaces();
this.listEspaces.Add(ucEspaces);
ucEspaces.AfficherTitre(espace.nom_esp, espace.id_esp);
ucEspaces.AfficherImage("..\\..\\Images\\Espaces\\" + espace.image_esp);
if (i % 8 == 0 && i > 0)
{
x = 130;
y += 152;
}
else
x += 130;
ucEspaces.Location = new Point(x, y);
//liaison de l'evenement usercontrol vers ton formulaire
ucEspaces.ClickMonUcEvent += justeUnTest;
this.panelPS.Controls.Add(ucEspaces);
i++;
}
}
//L'User Control appel cette méthode
public void justeUnTest(Object sender)
{
this.id_espace =((MonUc)sender).id;
this.panelPS.Controls.Clear();
}
} |
Partager