Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am converting a VB6 program to .NET. It consists of an MDI form with a button on it. When the user moves the mouse over the button, another form opens. When the user moves the mouse out of that second form, it hides. It makes for a quick show/hide form without the user having to manually close the popup form.

 

In VB6, I used the MouseMove event in the MDI form to hide the popup form. It worked fine. However, the MouseMove event does not work for MDI forms in .NET.

 

I have tried MouseMove in my popup form and checking the mouse coordinates to determine if it should close, but that doesn't work. Probably because if I move out of the bounds of the form, it would no longer trigger the MouseMove event for that form! (I just realized that while typing this).

 

Is there a good way to handle this?

 

Also... in VB6, the popup form would appear on top of the button (actually, I did not use a button in VB6, I used a small form with no border that looked like a button). In .NET, the form appears under the button which I do not want. BringToFront does not seem to fix the problem. How to fix that too?

 

Thanks.

Posted

I just tried them again because I couldn't remember what the problem was... MouseLeave doesn't work with the popup form because everytime I mouse over one of the controls on the form, it triggers the form's MouseLeave event and hides the form.

 

MouseEnter just doesn't work at all on the MDI form.

Posted
I am sorry. I tried to open it, but it won't let me. It is telling me that it is incompatible with my version of VS (I have 2002). Thank you for taking the time, though.
Posted

Thanks for the tip on that conversion utility. That worked.

 

That is exactly what I want to do. The only problem is... if you add a button to your child form and mouse over that button, it triggers the MouseLeave event for the form and closes the form.

Posted

Private Sub mdiChild_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave

Dim rBounds As Rectangle

rBounds = Me.Bounds

 

 

'

'if you remove the comments

'you'll get more acuracy

'

'rBounds = New Rectangle(rBounds.X + 10, _

' rBounds.Y + 10, rBounds.Width - 20, rBounds.Height - 20)

 

If Not rBounds.Contains(Control.MousePosition) Then

Me.Close()

End If

 

End Sub

 

hope it helps

Posted

I see what you are saying. I haven't gotten it to work yet, though. I am still messing with it. Here is my code:

 

   Private Sub TestsForm_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
       Dim rBounds As Rectangle
       rBounds = Me.Bounds

       
       If Not rBounds.Contains(btnTestEditor.MousePosition) Then
           Me.Hide()
       End If

   End Sub

 

It is still hiding when I mouse over the button.

Posted

I changed it to

 

If Not rBounds.Contains(Control.MousePosition) Then

 

like you had it instead of btnTestEditor.MousePosition. It still isn't working. If I leave the bounds of the form, it closes, like it should. But, it also closes when I mouse over the buttons.

 

I added this line:

 

MessageBox.Show(rBounds.ToString & "--" & Control.MousePosition.ToString)

 

so I could see what it was testing, and this is what it gave me:

 

{x=0,y=330,width=300,height=335}--{x=52,y=672}

 

If the form's y is 330 and its height is 335 then its lower bound is 665 which means the point (52,672) is not in there! Why would it be saying that? The button is on that form. It's not even close to the edge! What am I missing?

Posted
Yeah, I did that. I had already changed it back to the way you had it. Same result. Check out my last post. Why is it showing that a point on my button is not located within the bounds of the form?
Posted

Right! It is telling me that my mouse position is at Y=672 when I am hovering over the button which is on my form. But the form, apparently, has a lower bound of 665!

 

So, it is obviously closing the form because 672 is not within the bounds 330-665. But my button, which is where my mouse pointer is when the form closes, is definitely within the bounds of my form.

 

This makes no sense at all. I don't see any reason this would be happening.

 

To sum up:

 

myForm.Bounds.ToString = {X=0,Y=330,Width=300,Height=335}

 

while, at the SAME TIME, when I mouse over a button on myForm:

 

Control.MousePosition.toString = {x=52,y=672}

 

So, the Y of a point on myForm.myButton is greater than the lower bound of myForm. ????

Posted

that's the hole point of getting the control.mouseposition it return the position to the screen and not the location on any forms

 

so the locations you are getting are point to screen.

 

you should be able to do it with the code i provided you

 

in my example here it works fine i don't see way it should work with yours

Posted

I just checked yours again. The only reason yours works is because when you show the child form, you are not actually creating a child form. You were doing this:

 

       Dim child As New mdiChild()
       child.ShowDialog(Me)

 

If I change it to this:

 

       Dim child As New mdiChild()
       child.MdiParent = Me
       child.Show()

 

in order to create an MDI child form, it has the same problem I'm having with mine. Try it out. Put a button near the bottom of the form. Move your mouse up onto the button from below it. The form will close. I figured out the reason is because it sees the form's desktop location as being relative to the MDI Parent instead of relative to the screen. So mdiChild.Bounds = {0,0,width,height} if the form is just below the MDI Parent's title bar and menu bar. However, Control.MousePosition still shows the mouse position relative to the screen. So, that is why I'm having so much trouble.

 

I appreciate your help, though. You gave me the method I need to use to fix this. I think if I just add the Parent's top and left border into the equation, I will have what I need.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...