/*
* Created by SharpDevelop.
* User: ai
* Date: 2006-10-16
* Time: 20:15
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
namespace Test
{
partial class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <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.lblTest = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblTest
//
this.lblTest.Location = new System.Drawing.Point(40, 25);
this.lblTest.Name = "lblTest";
this.lblTest.Size = new System.Drawing.Size(100, 23);
this.lblTest.TabIndex = 0;
this.lblTest.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.lblTest);
this.Name = "Form1";
this.Text = "Test";
this.ResumeLayout(false);
}
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label lblTest;
}
}
======================================
/*
* Created by SharpDevelop.
* User: ai
* Date: 2006-10-16
* Time: 20:15
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Test
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class Form1
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public Form1()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, System.EventArgs e)
{
Form1 f = new Form1();
f.lblTest.Text = "OK";
f.Show();
}
}
}
大家注意了,上面的代码
private System.Windows.Forms.Label lblTest;
但在 Button1Click事件中
Form1 f = new Form1();
f.lblTest.Text = "OK";
是可以的。不知为何?