Results 1 to 5 of 5

Thread: [RESOLVED] Can MDI parent handle mouseclick?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Resolved [RESOLVED] Can MDI parent handle mouseclick?

    With the following code, I am creating a child form when my main form loads:

    Code:
    Public Class Form1
        Dim cForm As New System.Windows.Forms.Form
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            cForm.MdiParent = Me
            cForm.BackColor = Color.Yellow
            cForm.Left = 0
            cForm.Top = 0
            cForm.ControlBox = False
            cForm.Width = 20
            cForm.Height = Me.Height
            cForm.Show()
        End Sub
    
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
            If e.Button = Windows.Forms.MouseButtons.Right Then
                cform.close()
                Me.Text = "right mouse button clicked"
            End If
        End Sub
    End Class
    Once it loads, the main form doesn't seem to handle the mouseclick event. Is that because the child fom is showing, and somehow IT has to handle the click event (even though I'm not clicking within the boundaries of the child form)?

    Thanks in advance!

    Bryce

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Can MDI parent handle mouseclick?

    Maybe it's a stupid question, however..
    Did you try to put a breakpoint in the first line of the Sub ("If....") and then click somewhere on Form1 (outside of the ChildForm (cForm)?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Can MDI parent handle mouseclick?

    When I put a break point in that sub and click form1 (outside of cForm), it never hits it.

    No, not a stupid question!

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Can MDI parent handle mouseclick?

    The MDI parent doesn't raise a MouseClick event when you click it. In fact, you can't even see the parent form except for its border. The gray area you see filling the background isn't the form itself but a mysterious control called the MDIClient. It's a bit like the TabControl which hosts tab pages. But unlike the TabControl, the MDIClient doesn't expose any public properties or events. That's the way the .Net Framework makers designed it. Maybe it was intended to make sure all MDI forms have the same boring, corporate look.

    There's an article somewhere in the CodeBank where someone found a way to give an MDIClient a color gradient background, using Reflection. Search for MDIClient and you will probably find it. But although the method exposes the MDIClient's private properties, I don't think it will work for events.

    BB

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Can MDI parent handle mouseclick?

    Ok, thanks for the replies, guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width