Nej nej, den kan sagtens compile alle forms/filer, mit problem er bare, at hvis jeg gemmer noget i den ene fil/form, så kan jeg ikke hente det i en anden form/fil
du sender en reference til din hoved form med over i constructor til din sub form, som gemmer den således at sub formens metoder kan kalde metoder/properties på hoved formen.
Jeg kan ikke helt få det til at virke. Enten er det fordi jeg ikke fatter det, eller også er det fordi jeg skriver noget forkert.
Hvad gør this.mf = mf;?
den kan ikke finde den label der ligger i mainformen.
MainForm:
using System; using System.Drawing; using System.Windows.Forms;
namespace MultipleForms { /// <summary> /// Description of MainForm. /// </summary> public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // }
[STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); }
#region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(48, 80); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(192, 40); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.Button1Click); // // label1 // this.label1.Location = new System.Drawing.Point(64, 168); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(152, 24); this.label1.TabIndex = 1; this.label1.Text = "label1"; // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.Name = "MainForm"; this.Text = "MainForm"; this.ResumeLayout(false); } void Button1Click(object sender, System.EventArgs e) { SubForm sf = new SubForm(this); sf.ShowDialog(); } } }
SubForm:
using System; using System.Drawing; using System.Windows.Forms;
namespace MultipleForms { /// <summary> /// Description of SubForm. /// </summary> public class SubForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private MainForm mf; public SubForm(MainForm mf) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // }
#region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(56, 64); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(192, 64); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.Button1Click); // // SubForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button1); this.Name = "SubForm"; this.Text = "SubForm"; this.ResumeLayout(false); } #endregion
public SubForm(MainForm mf) { this.mf = mf; // <---- her // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.