public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; private Test _test; // l'object qu'on passe à l'autre form public Form1() { InitializeComponent(); // On remplit l'object (struct) _test.test1 = 1; _test.test2 = "test"; _test.test3 = 't'; // On construit la nouvelle form en passant l'object Form2 frm2 = new Form2(_test); frm2.Show(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); this.Text = "Form1"; } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } } struct Test { public int test1; public string test2; public char test3; }
public class Form2 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; private Test _test; // La référence public Form2(Test test) { InitializeComponent(); this._test = test; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question