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