Hi all,
I have a child form within my form. When I click inside the child form, the parent form (my form) loses focus. How can I prevent this from occurring and maintain focus of main parent form even if clicking in child form?
Just to clarify what I mean by "in-focus", this picture demonstrates a focused form (the one at the front), and a form that's not in focus (the one at the back):
http://www.functionx.com/vcsharp/images/modal1.gif
Thanks in advance. :D
My code:
<pre>Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MAXIMIZE As Integer = &HF030
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Friend Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Private Sub SetChildTimer1_Tick(sender As Object, e As EventArgs) Handles SetChildTimer1.Tick
Dim NtPdProcess As Process = Process.GetProcessesByName("notepad").FirstOrDefault
If NtPdProcess IsNot Nothing Then
SetParent(NtPdProcess.MainWindowHandle, Panel1.Handle)
SendMessage(NtPdProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim startInfo As New ProcessStartInfo("notepad.exe")
Process.Start(startInfo)
End Sub
End Class
What I have tried:
I've tried experimenting with ZOrder, but frankly, I'm not very experienced yet.
I've tried experimenting with ShowDialog's, to no avail.