Keep Mdi Child Form Focused

Simcoder

Centurion
Joined
Apr 18, 2003
Messages
125
Location
South Carolina
Im having an issue with child forms. Normally, when I want a specific form to stay focused, I use the ShowDialog method. But it won't let me use ShowDialog on childforms so I have to use the Show method instead. The problem is that the show method doesn't ensure that the child form stays focused. Is there a quick fix for this? Thanks in advance.

-=Simcoder=-
 
Simcoder said:
Could be a number of reasons. The user trys to click something on another child form that is already up or even the Parent form.
so you want a child form to remain open preventing any other forms from opening until it is closed???
 
fool around with this in the child form. . .


[CS]protected override void OnValidating(CancelEventArgs e)
{
e.Cancel = this.DialogResult != DialogResult.OK;
base.OnValidating(e);
}
protected override void OnClosing(CancelEventArgs e)
{
this.DialogResult = DialogResult.OK;
base.OnClosing (e);
} [/CS]
 
Sort of. You are right in saying that I don't want any other forms opening up once a particular child form is opened. But I also don't want the user to give any other previous forms that are already open focus either.
 
play around with the code I posted. . .

Attach a delegate to disable your method that opens new forms. . . detach the delegate when the form closes.

I am sure some vb'er out there can hack it together.
 
Simcoder said:
Sort of. You are right in saying that I don't want any other forms opening up once a particular child form is opened. But I also don't want the user to give any other previous forms that are already open focus either.
Sounds like something that will seriously piss off users. An MDI app isn't supposed to work that way. If you want a form to be the only one that can have focus until it's closed it should be modal.
 
Sounds like the form you are showing should *not* be an MDI Child. Just call it like you would a regular form, the use ShowDialog() like you always would.

Again, do not set the MdiParent on this particular form, because it sounds like you are not wanting this to be an MDI Child form.

I realize this is coming years after you posted the question, but I just happened across it and understood what you were asking. It looks like others might have missed it.
 
Back
Top