Saturday, July 3, 2010

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)

No comments:

Post a Comment

IIS Manager Crashes on Load/Start Windows 7, IIS 7.5

IIS Manager Crashes on Start  Windows 7, IIS 7.5, Power Shell 5.1. Here is the error I got in the event viewer. IISMANAGER_CRASH IIS Ma...