|
-
Oct 6th, 2011, 09:56 AM
#1
[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
-
Oct 6th, 2011, 10:26 AM
#2
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!
-
Oct 6th, 2011, 11:44 AM
#3
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!
-
Oct 6th, 2011, 12:26 PM
#4
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
-
Oct 7th, 2011, 08:48 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|