Finding the Owner( Launching Form)

Sometimes it is very useful to have reference to the form that launches another form.This is easily done by passing the owner in the form show method.But what if you have to change a lot in the existing code to get that.You can use windows api to get the owner.Lets say you have form1 and form2 in your app and form2 is launched from form1 and if we want to find the launcher of form2 which in our case is form1.This is what you do in form2.

<dllimport("user32", charset:="CharSet.Auto," exactspelling:="True)" setlasterror:="True,">_
Public Shared Function GetWindow(ByVal hwnd As IntPtr, ByVal uCmd As Integer) As Integer
End Function

--get the window now
Dim i As Integer
i = GetWindow(Me.Handle, 4)
Dim ctrl As Control = Form.FromHandle(i)


Popular posts from this blog

Duplicate Folders Freeware - Not Duplicate Files

SSRS Compile Errors

Free SQL Server Management Studio Addin/Plugin/External Tool to get object information quickly