Modal dialog form became NonModal one
From: Eugene Pankov (eugene.p_at_parks.lv)
Date: 07/19/04
- Next message: Sanjeeva: "Re: ListBox/ComboBox-to-TextBox question"
- Previous message: Jon Skeet [C# MVP]: "Re: SendMessage() PostMessage() equivalents"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 19 Jul 2004 15:57:23 +0300
Hello,
I have a Form1 with one button ("Fire Event").
Also I have a Form2 that should be shown as a modal dialog box.
And I have a Class1:
//- Class1 -----------------
public class Class1
{
public event EventHandler openDialog = null;
private Timer timer;
public Class1()
{
timer = new Timer( 1000 );
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
public void callDialog()
{
timer.Start();
}
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
if( openDialog != null )
openDialog( this, null );
}
}
//- endOfClass1 ------------
This class is initialized on the main Form1. Pressing the "Fire Event"
button we call the method Class1.callDialog(). After one second delay
the Class1 fires the event openDialog(). The handler of the event should
display the Form2 as a modal form (I suppose).
Here you are some part of the Form1:
//- Form1 -------------------
private Class1 cls = null;
private System.Windows.Forms.Button btnFire;
:
cls = new Class1();
cls.openDialog += new EventHandler( onOpenDialog );
:
private void btnFire_Click(object sender, System.EventArgs e)
{
cls.callDialog();
}
public void onOpenDialog( object sender, EventArgs e )
{
Form2 frm = new Form2();
frm.ShowDialog( this );
}
//- endOfForm1 --------------
In that case the Form2 appears as a NonModal form. You can activate the
backgound Form1 and press "Fire..." button again. But the Form2 still is
on the top and acts like the active window except it doesn't capture all
mouse events.
It is just an example. Real application works with the threads and
callbacks but the example with the Timer imitates the situation perfectly.
How to avoid this situation and make realy modal dialog?
I looked at System.Windows.Forms.Form.ShowDialog(). It calls
UnsafeNativeMethods.GetCapture(). (I use .net framework 1.1).
Any ideas?
Thank you
Eugene Pankov
- Next message: Sanjeeva: "Re: ListBox/ComboBox-to-TextBox question"
- Previous message: Jon Skeet [C# MVP]: "Re: SendMessage() PostMessage() equivalents"
- Messages sorted by: [ date ] [ thread ]