µ±Ä£Ì¬±íµ¥×îС»¯Ê±£¬ÎÒÊÔͼÈÃËùÓÐÕß±íµ¥×îС»¯.µ«Êǵ±ÎÒ×îС»¯Ä£Ì¬ÐÎʽʱ¡ª¡ªËüÍêÈ«ÏûʧÁË.(- ÎÒ¿ÉÒÔµã»÷ËùÓÐÕß±íµ¥.)
I'm trying to have the owner-form minimize when the modal-form is minimized. But when I minimize the modal-form ¨C it disappears completely. (- I can click on the owner-form.)
ÎÒ¸ÃÈçºÎ½â¾öÕâ¸öÎÊÌâ?
How do I solve this?
ÎÒÓÐ:
public partial class Form1 : Form
{
Form2 frm2 = new Form2();
public Form1()
{
InitializeComponent();
frm2.Owner = this;
}
private void button1_Click(object sender, EventArgs e)
{
frm2.ShowDialog();
}
}
»¹ÓÐ:
class Form2 : Form
{
Form1 frm1;
FormWindowState ws = new FormWindowState();
public Form2()
{
SizeChanged += new EventHandler(Form2_SizeChanged);
}
void Form2_SizeChanged(object sender, EventArgs e)
{
frm1 = (Form1)Owner;
if (WindowState == FormWindowState.Minimized)
{
ws = frm1.WindowState;
frm1.WindowState = FormWindowState.Minimized;
}
else frm1.WindowState = ws;
}
}
(ÔÚ³¢ÊÔÕâ¸öʱ£¬ÎÒÒ²Óöµ½ÁËÕâ¸ö:ģ̬±íµ¥Ö»ÓÐÔÚ×îС»¯ºÍËùÓÐÕß±íµ¥±»µã»÷Ò»´Îºó²Å»á³öÏÖÔÚÍÐÅÌÖÐ.ÈçºÎÈÃËü³öÏÖ?)
(While trying this, I also ran into this: Modal form doesn't appear in tray until minimized and owner-form is clicked once. How do I make it appear? )
Ìí¼Ó:
Show();
ÔÚ Form2 µÄʼþ´¦Àí³ÌÐòµÄĩβ.
At the end of Form2's event-handler.
Õâƪ¹ØÓÚΪʲôģ̬ÐÎʽÔÚ×îС»¯Ê±»áÍêÈ«Ïûʧ?µÄÎÄÕ¾ͽéÉܵ½ÕâÁË£¬Ï£ÍûÎÒÃÇÍƼöµÄ´ð°¸¶Ô´ó¼ÒÓÐËù°ïÖú£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö¸ú°æÍø£¡