Clicking and Focus on MDI child forms...

B2Ben

Well-known member
Joined
Aug 17, 2006
Messages
52
Programming Experience
Beginner
I have an application that uses several child forms on a main MDI form.

I'm building it with VS.NET 2003 (not 2005 like my profile states).

I've noticed that I can only bring focus to my child forms by clicking on their title bars. If I click on the contents of the child form, it does not set focus on the child form.

I have a sub that handles childform.click, and in the sub, it executes "me.setfocus()"

However, if I click on other items in the form, such as labels and pictureboxes, I'd like to my form to pick up this click event, and execute "me.setfocus()". Naturally, I don't want to write a click function for every control on my form.

So... how can my form capture a click event when one of its controls is clicked?

Thanks!
 
May be try out this code?

VB.NET:
'constants to move form
    Private Const WM_NCHITTEST As Integer = &H84
    Private Const WM_NCLBUTTONDBLCLK As Int32 = &HA3
    Private Const HTCLIENT As Integer = &H1
    Private Const HTCAPTION As Integer = &H2
'Windows Form Designer Generated Code - omitted
    'move form
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_NCHITTEST 'to drag
                MyBase.WndProc(m)
                If (m.Result.ToInt32 = HTCLIENT) Then 'client
                    m.Result = IntPtr.op_Explicit(HTCAPTION) 'name of window
                End If
                Exit Sub
            Case WM_NCLBUTTONDBLCLK
                MyBase.WndProc(m)
                If (m.Result.ToInt32 = HTCLIENT) Then 'client
                    m.Result = IntPtr.op_Explicit(HTCLIENT) 'name of window
                    Me.WindowState = FormWindowState.Normal
                    Me.Refresh()
                End If
        End Select
        MyBase.WndProc(m)
    End Sub
 
Back
Top