views:

26

answers:

1

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   
    Dim 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.

A: 

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.
BPerreault