【问题标题】:Loosely couple a modal dialog - is this possible?松散地耦合一个模态对话框 - 这可能吗?
【发布时间】:2010-01-06 15:32:31
【问题描述】:

我有一个 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() 函数,它可能允许控件更加自给自足。

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

【问题讨论】:

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

标签: winforms user-interface


【解决方案1】:

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

  • 删除任何需要的验证 在显示之前设置所有者 模态形式。
  • 如果在透明覆盖的类中没有设置所有者 (第一种形式)- 进行系统调用
    GetActiveWindow 获取所有者,以便设置窗口的大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-27
    • 2011-03-15
    • 2011-01-20
    • 2017-06-05
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2020-10-26
    相关资源
    最近更新 更多