【发布时间】: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 是自定义控件的一个实例。我会添加更多信息。