Modal dialog from .cs file

J

jamie

I have a class that based on a timer will pop up a dialog based on a
lasped amount of time.

The problem is that in the timer elapsed event I create and use
ShowDialog to show the timeout form:
frmTimeout dlg = new frmTimeout();
dlg.ShowDialog(dlgOwner); <-- dlgOwner if the IWin32Window of the
window in focus


When the dialog opens, it is not modal. I've tried passing the
IWin32Window of the dlg in focus, just using ShowDialog() but no luck.

Is there a way to open this dialog from code and have it truely modal?
(I don't want to use the AlwaysOnTop flag).

thanks,

Jamie
 
N

Nicholas Paldino [.NET/C# MVP]

Jamie,

It works for me. Can you post an example of where calling ShowDialog
doesn't make the form modal?
 
J

jamie

Nicholas said:
Jamie,

It works for me. Can you post an example of where calling ShowDialog
doesn't make the form modal?

Hi Nicholas,

I'll post an example and give a little more detail.

The C# code that I'm using is a Class Library and used as a COM Dll from
a VB6 application.

The VB6 application opens a dialog from the C# dll which is modal (this
works as expected). This dialog gets the instance of a singleton class
which contains a timer to track inactivity (dialogs will reset this
timer on mouse_move).

When the timer elapses I want to popup a dialog modally to the VB6
application and the modal C# dialog that is already opened.

Here is my timer elapsed code:

private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.Stop(); // this stops the timer
frmTimeout dlg = new frmTimeout();
dlg.ShowDialog();
}

I've also tried passing the IWin32Window of the opened C# dialog and
using that for the parent in ShowDialog.

This singleton class sits in a cs file that does not contain a UI.

Thanks for your help,

Jamie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top