开发者

MDI child window cannot be displayed by .ShowDialog() WHY?

开发者 https://www.devze.com 2023-01-06 15:43 出处:网络
I use winforms MDI window and display child windows on it. I need to display some of them using modal dialog mode ( .ShowDialog() ) but still have the开发者_如何学编程m displayed as a child window (th

I use winforms MDI window and display child windows on it. I need to display some of them using modal dialog mode ( .ShowDialog() ) but still have the开发者_如何学编程m displayed as a child window (they should stay within the borders of the parent windows).

When I try to do this I get a compile time error saying that the child window cannot be displayed as a modal dialog mode window.

Is there any way to do it?


I don't think that there is direct way to do this. However, on the low level modal dialogs are implemented by disabling a parent window. Try to show modeless MDI child and keep parent disabled unless this child is closed.


I'd normally get around this by making all the controls on the childform be part of a user control and then add the user control to the childform and make a separate dialog also containing the user control. That means that you can reuse almost all the code and there's usually some code that will be different anyway (the childform normally doesn't have OK/Cancel buttons etc).

However, if you don't want to go down that route here's a codeproject article that supposedly has a workaround (I've not looked at it carefully): MDI child as dialog form (MDI modal workaround)


If you want the modal window to simply open up within the bounds of the parent form, just set the form property StartPosition to CenterParent.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号