日期:2014-05-17 浏览次数:21107 次
public void ThreadShow() { if (this.InvokeRequired) { MethodInvoker invoker = new MethodInvoker(this.Show); this.Invoke(invoker, null); } else { this.Show(); } } public void ThreadHide() { if (this.InvokeRequired) { MethodInvoker invoker = new MethodInvoker(this.Hide); this.Invoke(invoker, null); } else { this.Hide(); } }
private void FormMain_Load(object sender, EventArgs e) { fingerIm = new FingerIm(); fingerIm.ThreadShow(); fingerIm.ThreadHide(); } 在另一线程中显示该窗体
fingerIm.ThreadShow();
namespace Show { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(96, 92); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "线程开始"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // 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.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } } using System; using System.Collections.Generic; using System.ComponentModel; using Sy