开发者

Loosely couple a modal dialog - is this possible?

I have a winforms custom UI control library which contains a control for displaying modal dialogs Picture-in-Picture.

This custom control receives as a parameter a pointer to the control which has initiated it's display. So they are tied together. This allows the control to be modally displayed over the window which launched it.

    Dim f As New PiPCustomDialog       'this form wraps another form PictureInPicture style  
    f.FormToLoad = New PrintOptions()  'this is the form the user will interact with  
    f.Owner = Me                       'used to determine the size of PiPCustomDialog   
    D开发者_运维知识库im dr As DialogResult = f.ShowDialog(Me) 'shows PiPCustonDialog coating, f's OnLoad event initiates display of FormToLoad centered within.   

The fact that this control requires f.Owner to be set is what is stinky. User32.dll has a function GetActiveWindow() which would maybe allow the control to be more self-sufficient.

Anyone out there who would like to teach this old dog a new trick? I want to learn a better way.


I'll use this solution for now:

  • Remove any validation that requires owner to be set before showing the form modally.
  • if owner isn't set inside the class that is transparent cover (first form) - do a system call into
    GetActiveWindow to get owner so the size of the window can be set.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜