olibara
Messages postés666Date d'inscriptiondimanche 16 décembre 2007StatutMembreDernière intervention11 mars 2010
-
18 mars 2008 à 15:12
olibara
Messages postés666Date d'inscriptiondimanche 16 décembre 2007StatutMembreDernière intervention11 mars 2010
-
22 avril 2008 à 16:34
Afin de pouvoir dialoguer entre deux form, Il me semble que c'est a coup d'event et sans doute de quelque variables a passer que je dois travailler
MAIS MAIS MAIS : je n'ai AUCUNE experience de declaration et d'exploitation d'event ?
Que dois je faire au minimum dans deux form Form1 et Form2 pour que Form2 genere un event qui appelle une fonction dans Form1, sachant que c'est Form1 qui instancie Form2 ?
Liverion
Messages postés296Date d'inscriptionmardi 22 avril 2008StatutMembreDernière intervention18 août 2008 22 avril 2008 à 16:19
Sinon tu as toujours la solution de passer la fenetre appelante dans le constructeur de la fenetre appelée et d'appeler une fonction publique de la fenetre appelante :
(Ici j'ai une fenetre principale MainWindows et une petit fenetre secondaire GeschwindigkeitForm pour choisir un parametre )
namespace SimulatorClient
{
public partial class MainWindows : Form
{
/// <summary>
/// Variable to create the windows for choosing sending speed
/// </summary>
private SimulatorClient.GeschwindigkeitForm speedForm;
/// <summary>
/// Function called by the speed form
/// </summary>
///
/// number of data per second
///
namespace SimulatorClient
{
/// <summary>
/// Secondary windows, only to choose the speed
/// </summary>
public partial class GeschwindigkeitForm : Form
{
/// <summary>
/// Variable to get the calling windows
/// </summary>
private MainWindows caller;
/// <summary>
/// Constructor for the Form
/// </summary>
///
/// Get the parent Form
///
public GeschwindigkeitForm(MainWindows value)
{
InitializeComponent();
caller = value;
}
/// <summary>
/// Button ok event handler
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
// if some value is written when clicking on "Ok"
if (textBox1.Text != "")
{
try
{
// if the value is bigger than 0 and smaller than 251
if (int.Parse(textBox1.Text) > 0 && int.Parse(textBox1.Text) <= 250)
{
// call the parent's method changeSpeed(int value)
caller.changeSpeed(int.Parse(textBox1.Text));
// hide the windows
Hide();
}
// else say to enter a value in the valid range
else MessageBox.Show("Es ist kein richtiges Nummer");
}
// if a FormatException is thrown
catch(FormatException ex)
{
ex.ToString();
// Say to enter a number
MessageBox.Show("Bitte schreiben Sie ein Nummer");
}
}
// if no value is written when clicking on "Ok"
else
{
// ask for entering a value
MessageBox.Show("Bitte schreiben Sie etwas");
}
}
}
}