Winforms 松散耦合一个模态对话框-这可能吗?

Winforms 松散耦合一个模态对话框-这可能吗?,winforms,user-interface,Winforms,User Interface,我有一个winforms自定义UI控件库,其中包含一个用于在图片中显示模式对话框的控件 此自定义控件作为参数接收指向已启动其显示的控件的指针。所以他们被捆绑在一起。这允许控件以模式显示在启动它的窗口上 Dim f As New PiPCustomDialog 'this form wraps another form PictureInPicture style f.FormToLoad = New PrintOptions() 'this is the for

我有一个winforms自定义UI控件库,其中包含一个用于在图片中显示模式对话框的控件

此自定义控件作为参数接收指向已启动其显示的控件的指针。所以他们被捆绑在一起。这允许控件以模式显示在启动它的窗口上

    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   
    Dim dr As DialogResult = f.ShowDialog(Me) 'shows PiPCustonDialog coating, f's OnLoad event initiates display of FormToLoad centered within.   
这个控件要求设置f.Owner这一事实是令人讨厌的。User32.dll有一个函数GetActiveWindow(),该函数可能允许控件更加自给自足


有人想教这只老狗一个新把戏吗?我想学一种更好的方法

我现在将使用此解决方案:

  • 删除任何需要的验证 在显示前设置所有者 形成模式
  • 如果所有者未设置在透明覆盖的类内 (第一种形式)-对
    GetActiveWindow获取所有者,以便可以设置窗口的大小

我不明白。如果只是删除f.Owner分配,看起来会更好吗?不需要,将我传递给ShowDialog()也可以做同样的事情。或者这实际上是一个控件而不是一个窗体?什么是“f”?好吧,你是对的,那还不清楚。f是自定义控件的一个实例。我将添加更多信息。