0
我有一個主窗體,它是不可見的,並在某個時候創建一個子窗體。那孩子的形式看起來像這樣designer.cs:隱形父項的子窗體永遠不會顯示?
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
//this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(255, 147);
this.listBox1.TabIndex = 0;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(502, 384);
this.ControlBox = false;
this.Controls.Add(this.listBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form2";
this.Text = "Form2";
,並在主窗體我創建的窗體2如下:
Form2 a = new Form2(new Point(0, Screen.PrimaryScreen.WorkingArea.Height/2)); //This is the location
Thread thtt = new Thread((ThreadStart)delegate()
{
a.CreateControl();
a.Show();
TimeSpan slept = TimeSpan.Zero;
while (!a.Created && slept < TimeSpan.FromMilliseconds(2000))
{
Thread.Sleep(99);
slept += TimeSpan.FromMilliseconds(99);
}
if (!a.Created)
{
MessageBox.Show("after 2 sec no creation?");
System.Diagnostics.Debugger.Break();
}
else
{
//a.Show();
a.Invoke((MethodInvoker)delegate()
{
a.TopMost = true;
a.Location = new Point(0, Screen.PrimaryScreen.WorkingArea.Height/2);
Cursor.Position = new Point(a.Location.X + 10, a.Location.Y + 10);
a.AddAndAct(minimized);
});
}
aa = a;
});
thtt.IsBackground = true;
thtt.Start();
我現在遇到的問題是,該窗體2實際上是在閃爍,但後來神奇地消失了。任何建議appriciated。
謝謝諮詢,亞歷克斯
請問你爲什麼要創建一個無形的父母?第一種形式的可見性屬性是否設置爲false?代碼中父代表觸發器調用上述代碼並創建子代的觸發器是什麼? – 2011-04-18 21:42:46
觸發器是一個熱鍵,父母Visible設置爲false。父窗體正在創建,但在某個時刻Hide();正在呼籲它,所以它不再可見。當調用熱鍵時,會調用一個事件處理程序,然後創建客戶端。 – alex 2011-04-18 22:03:02
其實它被關了!我只是看了一下EnumThreadWindows,窗口顯示1秒,然後關閉了一個字。非常奇怪... – alex 2011-04-18 22:14:11