473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

REPOST: Popup form on button

Hi - this was posted last weekend and unfortunately not resolved. The
solutions that were posted almost worked but after another 5 days of
working on the code everynight, I am not further ahead.
If you do have any ideas I would really like to hear them.
Thanks
Colin

- 0 - 0 - 0 -

I want a glorified popup/context menu on a button that shows only when
the mouse button is pressed over the button, and disappears when the
mouse button is released anywhere. Here's a full description.

When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form. By adding
Button1.Capture=True, no events in the instance of formPopup
can be caught.

Colin
Here is the full code I already have.

1. Launch Visual Studio .Net 2003 and create a new winforms
application.
2. Use the VS IDE toolbar to put a new button, Button1, on the form.
3. Paste in the following code

Public Class Form1
Inherits System.Windows.Forms.Form

//and include the Windows Form Designer Code in here

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on the
form
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp, f.MouseUp
Debug.WriteLine("Button1_MouseUp")
f.Close()
f.Hide()
f = Nothing
End Sub
End Class
Nov 20 '05 #1
18 2917
"Colin McGuire" <co***********@lycos.co.uk> schrieb
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on
the
form
End Sub


AFAIR I suggested to use

f.capture = true

instead of

button1.capture = true

in my last reply.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Armin:
I too thought this was done and dusted. Looking at
the original thread it appears he also wants to
trap button events on the popup form.
Colin:
Try this (the code is below). The key code is in
formPopup_MouseLeave. If I understand the user
interface you are describing, you must have a really
good reason for wanting to code this behaviour. For
what it's worth, I find it annoying and not something
I would put into any of my applications.

Note that MouseLeave is not the only way to 'leave'
a control ! You will need to make it more robust.
Hexathioorthooxalate


Public Class Form1
Inherits System.Windows.Forms.Form

'[+]Windows Form Designer generated code

Public Class formPopup
Inherits System.Windows.Forms.Form

Public Event popupNotification()
Private _button As Button = Nothing

Public ReadOnly Property getButton() As Button
Get
Return _button
End Get
End Property

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
b1.Text = "1"
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
b2.Text = "2"

Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
AddHandler b2.MouseUp, AddressOf subMUp
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles MyBase.MouseUp
RaiseEvent popupNotification()
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
_button = Nothing
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
_button = b
End Sub

Private Sub formPopup_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.MouseLeave
Dim cursorPosition As Point = PointToClient(Cursor.Position())
Dim rect As Rectangle = Me.ClientRectangle
If Not rect.Contains(cursorPosition) Then
RaiseEvent popupNotification()
End If
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Const FORMWIDTH As Integer = 80
Const FORMHEIGHT As Integer = 80
f = New formPopup
f.Size = New Size(FORMWIDTH, FORMHEIGHT)
f.BackColor = Color.Yellow
f.FormBorderStyle = FormBorderStyle.FixedSingle
f.ControlBox = False
f.StartPosition = FormStartPosition.Manual
f.Location = New Point(Cursor.Position.X - FORMWIDTH \ 2, _
Cursor.Position.Y - FORMHEIGHT \ 2)
f.Show()
End Sub

Private Sub disposeOfPopupForm()
If Not Nothing Is f Then
f.Close()
f.Hide()
f = Nothing
End If
End Sub

Private Sub f_popupNotification() Handles f.popupNotification
Dim buttonPressed As Button = f.getButton
Call disposeOfPopupForm()
If Nothing Is buttonPressed Then
Debug.WriteLine("no button was pressed")
Else
Debug.WriteLine("Selected button: " + buttonPressed.Text)
End If
End Sub

End Class


"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Colin McGuire" <co***********@lycos.co.uk> schrieb
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on
the
form
End Sub


AFAIR I suggested to use

f.capture = true

instead of

button1.capture = true

in my last reply.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #3

Try this out Colin. It worked when I tried it. You need to set the button
capture to True. Then create a rect of the button to see if the point is in
or out of the button. Also, why do you have Button1_MouseUp handling the
f.mouseup? Remove it and it will work.
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()

'-- You NEED to set this to true!
Button1.Capture = True

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
rid of this. Why is this here?
Debug.WriteLine("Button1_MouseUp")

'-- Create a rect of the button
Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)

'-- If mouse point isn't in the rect close it
If Not rect.Contains(e.X, e.Y) Then
f.Close()
f.Hide()
f = Nothing
End If

'-- Release Button capture
Button1.Capture = False

End Sub



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hi - this was posted last weekend and unfortunately not resolved. The
solutions that were posted almost worked but after another 5 days of
working on the code everynight, I am not further ahead.
If you do have any ideas I would really like to hear them.
Thanks
Colin

- 0 - 0 - 0 -

I want a glorified popup/context menu on a button that shows only when
the mouse button is pressed over the button, and disappears when the
mouse button is released anywhere. Here's a full description.

When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form. By adding
Button1.Capture=True, no events in the instance of formPopup
can be caught.

Colin
Here is the full code I already have.

1. Launch Visual Studio .Net 2003 and create a new winforms
application.
2. Use the VS IDE toolbar to put a new button, Button1, on the form.
3. Paste in the following code

Public Class Form1
Inherits System.Windows.Forms.Form

//and include the Windows Form Designer Code in here

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on the
form
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp, f.MouseUp
Debug.WriteLine("Button1_MouseUp")
f.Close()
f.Hide()
f = Nothing
End Sub
End Class

Nov 20 '05 #4
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons
on the popup form while the mouse button is down, and further only display
the popup form while the mouse button is down. If the mouse button is ever
released, regardless of where it is, then the popup form is hidden/disposed
of.
When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form.

Colin, could you reply to confirm your exact desired behaviour please.

Hexathioorthooxalate

"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
Try this out Colin. It worked when I tried it. You need to set the button
capture to True. Then create a rect of the button to see if the point is in or out of the button. Also, why do you have Button1_MouseUp handling the
f.mouseup? Remove it and it will work.
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()

'-- You NEED to set this to true!
Button1.Capture = True

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get rid of this. Why is this here?
Debug.WriteLine("Button1_MouseUp")

'-- Create a rect of the button
Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)

'-- If mouse point isn't in the rect close it
If Not rect.Contains(e.X, e.Y) Then
f.Close()
f.Hide()
f = Nothing
End If

'-- Release Button capture
Button1.Capture = False

End Sub



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hi - this was posted last weekend and unfortunately not resolved. The
solutions that were posted almost worked but after another 5 days of
working on the code everynight, I am not further ahead.
If you do have any ideas I would really like to hear them.
Thanks
Colin

- 0 - 0 - 0 -

I want a glorified popup/context menu on a button that shows only when
the mouse button is pressed over the button, and disappears when the
mouse button is released anywhere. Here's a full description.

When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form. By adding
Button1.Capture=True, no events in the instance of formPopup
can be caught.

Colin
Here is the full code I already have.

1. Launch Visual Studio .Net 2003 and create a new winforms
application.
2. Use the VS IDE toolbar to put a new button, Button1, on the form.
3. Paste in the following code

Public Class Form1
Inherits System.Windows.Forms.Form

//and include the Windows Form Designer Code in here

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on the
form
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp, f.MouseUp
Debug.WriteLine("Button1_MouseUp")
f.Close()
f.Hide()
f = Nothing
End Sub
End Class



Nov 20 '05 #5
What? How do you select another button when the a button is already down?
You have to release the button before you can select another. It seems to me
like he's trying to create a custom popup menu that works like the standard
Cut/Paste/SelectAll menu but with buttons. Is this right?

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10***************@damia.uk.clara.net...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons on the popup form while the mouse button is down, and further only display
the popup form while the mouse button is down. If the mouse button is ever
released, regardless of where it is, then the popup form is hidden/disposed of.
When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form.
Colin, could you reply to confirm your exact desired behaviour please.

Hexathioorthooxalate

"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...

Try this out Colin. It worked when I tried it. You need to set the

button capture to True. Then create a rect of the button to see if the point is

in
or out of the button. Also, why do you have Button1_MouseUp handling the
f.mouseup? Remove it and it will work.
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()

'-- You NEED to set this to true!
Button1.Capture = True

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <--------

Get
rid of this. Why is this here?
Debug.WriteLine("Button1_MouseUp")

'-- Create a rect of the button
Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)

'-- If mouse point isn't in the rect close it
If Not rect.Contains(e.X, e.Y) Then
f.Close()
f.Hide()
f = Nothing
End If

'-- Release Button capture
Button1.Capture = False

End Sub



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hi - this was posted last weekend and unfortunately not resolved. The
solutions that were posted almost worked but after another 5 days of
working on the code everynight, I am not further ahead.
If you do have any ideas I would really like to hear them.
Thanks
Colin

- 0 - 0 - 0 -

I want a glorified popup/context menu on a button that shows only when
the mouse button is pressed over the button, and disappears when the
mouse button is released anywhere. Here's a full description.

When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form. By adding
Button1.Capture=True, no events in the instance of formPopup
can be caught.

Colin
Here is the full code I already have.

1. Launch Visual Studio .Net 2003 and create a new winforms
application.
2. Use the VS IDE toolbar to put a new button, Button1, on the form.
3. Paste in the following code

Public Class Form1
Inherits System.Windows.Forms.Form

//and include the Windows Form Designer Code in here

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on the
form
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp, f.MouseUp
Debug.WriteLine("Button1_MouseUp")
f.Close()
f.Hide()
f = Nothing
End Sub
End Class


Nov 20 '05 #6
"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
What? How do you select another button when the a button is already down?
You have to release the button before you can select another. It seems to me

Yes - I think he is wanting something like this although clearly as we can
both see, he can't select the button via normal button clicks. I think it
explains why he says he wants to capture MouseOver events for controls on
the popup form, rather than click events.

I'm still waiting for Colin to repost and confirm exactly what he wants.

Hexathioorthooxalate
like he's trying to create a custom popup menu that works like the standard Cut/Paste/SelectAll menu but with buttons. Is this right?

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10***************@damia.uk.clara.net...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons
on the popup form while the mouse button is down, and further only display the popup form while the mouse button is down. If the mouse button is ever released, regardless of where it is, then the popup form is

hidden/disposed
of.
> When the mouse button is depressed over Button1, I want the
> popup form (an instance of formPopup) to show. If the mouse
> button is released anywhere, the cursor could be anywhere,
> even over another application or on the desktop or somewhere else,
> I want the popup form to be hidden. The code I have means that
> if I move the cursor away from the display form, then release
> the mouse button, the form isn't always hidden. I also want
> to trap various events in the instance of formPopup, such as
> mouseenter etc for controls on that form.


Colin, could you reply to confirm your exact desired behaviour please.

Hexathioorthooxalate

"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...

Try this out Colin. It worked when I tried it. You need to set the button capture to True. Then create a rect of the button to see if the point is in
or out of the button. Also, why do you have Button1_MouseUp handling
the f.mouseup? Remove it and it will work.
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()

'-- You NEED to set this to true!
Button1.Capture = True

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
rid of this. Why is this here?
Debug.WriteLine("Button1_MouseUp")

'-- Create a rect of the button
Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)

'-- If mouse point isn't in the rect close it
If Not rect.Contains(e.X, e.Y) Then
f.Close()
f.Hide()
f = Nothing
End If

'-- Release Button capture
Button1.Capture = False

End Sub



"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
> Hi - this was posted last weekend and unfortunately not resolved.

The > solutions that were posted almost worked but after another 5 days of
> working on the code everynight, I am not further ahead.
> If you do have any ideas I would really like to hear them.
> Thanks
> Colin
>
> - 0 - 0 - 0 -
>
> I want a glorified popup/context menu on a button that shows only when > the mouse button is pressed over the button, and disappears when the
> mouse button is released anywhere. Here's a full description.
>
> When the mouse button is depressed over Button1, I want the
> popup form (an instance of formPopup) to show. If the mouse
> button is released anywhere, the cursor could be anywhere,
> even over another application or on the desktop or somewhere else,
> I want the popup form to be hidden. The code I have means that
> if I move the cursor away from the display form, then release
> the mouse button, the form isn't always hidden. I also want
> to trap various events in the instance of formPopup, such as
> mouseenter etc for controls on that form. By adding
> Button1.Capture=True, no events in the instance of formPopup
> can be caught.
>
> Colin
>
>
> Here is the full code I already have.
>
> 1. Launch Visual Studio .Net 2003 and create a new winforms
> application.
> 2. Use the VS IDE toolbar to put a new button, Button1, on the form.
> 3. Paste in the following code
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> //and include the Windows Form Designer Code in here
>
> Public Class formPopup
> Inherits System.Windows.Forms.Form
>
> Private Sub formPopup_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim b1 As New Button
> b1.Size = New Size(15, 15)
> b1.Location = New Point(10, 10)
> b1.BackColor = Color.Gray
> Me.Controls.Add(b1)
> AddHandler b1.MouseEnter, AddressOf subMEnter
> AddHandler b1.MouseLeave, AddressOf subMLeave
> AddHandler b1.MouseUp, AddressOf subMUp
>
> Dim b2 As New Button
> b2.Size = New Size(15, 15)
> b2.Location = New Point(30, 10)
> b2.BackColor = Color.Gray
> Me.Controls.Add(b2)
> AddHandler b2.MouseEnter, AddressOf subMEnter
> AddHandler b2.MouseLeave, AddressOf subMLeave
> End Sub
>
> Private Sub subMUp(ByVal sender As Object, _
> ByVal e As MouseEventArgs)
> Debug.WriteLine("MouseUp")
> End Sub
>
> Private Sub subMLeave(ByVal sender As Object, _
> ByVal e As EventArgs)
> Dim b As Button = CType(sender, Button)
> b.BackColor = Color.Gray
> End Sub
>
> Private Sub subMEnter(ByVal sender As Object, _
> ByVal e As EventArgs)
> Dim b As Button = CType(sender, Button)
> b.BackColor = Color.Blue
> End Sub
> End Class
>
>
> Dim WithEvents f As formPopup
>
> Private Sub Button1_MouseDown(ByVal sender As Object, _
> ByVal e As System.Windows.Forms.MouseEventArgs) _
> Handles Button1.MouseDown
> Debug.WriteLine("Button1_MouseDown")
> f = New formPopup
>
> f.Size = New Size(80, 80)
> f.BackColor = Color.Yellow
>
> f.Show()
> 'Button1.Capture = True 'Have to comment this or else I cannot
> 'trap mouse trap events for controls on the > form
> End Sub
>
> Private Sub Button1_MouseUp(ByVal sender As Object, _
> ByVal e As System.Windows.Forms.MouseEventArgs) _
> Handles Button1.MouseUp, f.MouseUp
> Debug.WriteLine("Button1_MouseUp")
> f.Close()
> f.Hide()
> f = Nothing
> End Sub
> End Class



Nov 20 '05 #7
Ok, let's try this. This acts like a context menu with buttons. If this
isn't it, I don't know what he wants.

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual

f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

AddHandler Me.Leave, AddressOf subLeaving

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

Dim b3 As New Button()
b3.Size = New Size(15, 15)
b3.Location = New Point(50, 10)
b3.BackColor = Color.Gray
Me.Controls.Add(b3)

Dim b4 As New Button()
b4.Size = New Size(15, 15)
b4.Location = New Point(70, 10)
b4.BackColor = Color.Gray
Me.Controls.Add(b4)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
AddHandler b3.MouseEnter, AddressOf subMEnter
AddHandler b3.MouseLeave, AddressOf subMLeave
AddHandler b4.MouseEnter, AddressOf subMEnter
AddHandler b4.MouseLeave, AddressOf subMLeave
End Sub
Private Sub subLeaving(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class



"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10****************@damia.uk.clara.net...
"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
What? How do you select another button when the a button is already down?
You have to release the button before you can select another. It seems
to me

Yes - I think he is wanting something like this although clearly as we can
both see, he can't select the button via normal button clicks. I think it
explains why he says he wants to capture MouseOver events for controls on
the popup form, rather than click events.

I'm still waiting for Colin to repost and confirm exactly what he wants.

Hexathioorthooxalate
like he's trying to create a custom popup menu that works like the standard
Cut/Paste/SelectAll menu but with buttons. Is this right?

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10***************@damia.uk.clara.net...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select"

buttons
on the popup form while the mouse button is down, and further only

display the popup form while the mouse button is down. If the mouse button is ever released, regardless of where it is, then the popup form is

hidden/disposed
of.

> > When the mouse button is depressed over Button1, I want the
> > popup form (an instance of formPopup) to show. If the mouse
> > button is released anywhere, the cursor could be anywhere,
> > even over another application or on the desktop or somewhere else,
> > I want the popup form to be hidden. The code I have means that
> > if I move the cursor away from the display form, then release
> > the mouse button, the form isn't always hidden. I also want
> > to trap various events in the instance of formPopup, such as
> > mouseenter etc for controls on that form.

Colin, could you reply to confirm your exact desired behaviour please.

Hexathioorthooxalate

"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
>
> Try this out Colin. It worked when I tried it. You need to set the

button
> capture to True. Then create a rect of the button to see if the point is
in
> or out of the button. Also, why do you have Button1_MouseUp handling the > f.mouseup? Remove it and it will work.
>
>
> Private Sub Button1_MouseDown(ByVal sender As Object, _
> ByVal e As System.Windows.Forms.MouseEventArgs) _
> Handles Button1.MouseDown
> Debug.WriteLine("Button1_MouseDown")
> f = New formPopup()
>
> f.Size = New Size(80, 80)
> f.BackColor = Color.Yellow
> f.Show()
>
> '-- You NEED to set this to true!
> Button1.Capture = True
>
> End Sub
>
>
>
> Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) _
> Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
> rid of this. Why is this here?
>
>
> Debug.WriteLine("Button1_MouseUp")
>
> '-- Create a rect of the button
> Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)
>
> '-- If mouse point isn't in the rect close it
> If Not rect.Contains(e.X, e.Y) Then
> f.Close()
> f.Hide()
> f = Nothing
> End If
>
> '-- Release Button capture
> Button1.Capture = False
>
> End Sub
>
>
>
>
>
>
>
> "Colin McGuire" <co***********@lycos.co.uk> wrote in message
> news:ab**************************@posting.google.c om...
> > Hi - this was posted last weekend and unfortunately not resolved. The > > solutions that were posted almost worked but after another 5 days
of > > working on the code everynight, I am not further ahead.
> > If you do have any ideas I would really like to hear them.
> > Thanks
> > Colin
> >
> > - 0 - 0 - 0 -
> >
> > I want a glorified popup/context menu on a button that shows only

when > > the mouse button is pressed over the button, and disappears when the > > mouse button is released anywhere. Here's a full description.
> >
> > When the mouse button is depressed over Button1, I want the
> > popup form (an instance of formPopup) to show. If the mouse
> > button is released anywhere, the cursor could be anywhere,
> > even over another application or on the desktop or somewhere else,
> > I want the popup form to be hidden. The code I have means that
> > if I move the cursor away from the display form, then release
> > the mouse button, the form isn't always hidden. I also want
> > to trap various events in the instance of formPopup, such as
> > mouseenter etc for controls on that form. By adding
> > Button1.Capture=True, no events in the instance of formPopup
> > can be caught.
> >
> > Colin
> >
> >
> > Here is the full code I already have.
> >
> > 1. Launch Visual Studio .Net 2003 and create a new winforms
> > application.
> > 2. Use the VS IDE toolbar to put a new button, Button1, on the form. > > 3. Paste in the following code
> >
> > Public Class Form1
> > Inherits System.Windows.Forms.Form
> >
> > //and include the Windows Form Designer Code in here
> >
> > Public Class formPopup
> > Inherits System.Windows.Forms.Form
> >
> > Private Sub formPopup_Load(ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles MyBase.Load
> > Dim b1 As New Button
> > b1.Size = New Size(15, 15)
> > b1.Location = New Point(10, 10)
> > b1.BackColor = Color.Gray
> > Me.Controls.Add(b1)
> > AddHandler b1.MouseEnter, AddressOf subMEnter
> > AddHandler b1.MouseLeave, AddressOf subMLeave
> > AddHandler b1.MouseUp, AddressOf subMUp
> >
> > Dim b2 As New Button
> > b2.Size = New Size(15, 15)
> > b2.Location = New Point(30, 10)
> > b2.BackColor = Color.Gray
> > Me.Controls.Add(b2)
> > AddHandler b2.MouseEnter, AddressOf subMEnter
> > AddHandler b2.MouseLeave, AddressOf subMLeave
> > End Sub
> >
> > Private Sub subMUp(ByVal sender As Object, _
> > ByVal e As MouseEventArgs)
> > Debug.WriteLine("MouseUp")
> > End Sub
> >
> > Private Sub subMLeave(ByVal sender As Object, _
> > ByVal e As EventArgs)
> > Dim b As Button = CType(sender, Button)
> > b.BackColor = Color.Gray
> > End Sub
> >
> > Private Sub subMEnter(ByVal sender As Object, _
> > ByVal e As EventArgs)
> > Dim b As Button = CType(sender, Button)
> > b.BackColor = Color.Blue
> > End Sub
> > End Class
> >
> >
> > Dim WithEvents f As formPopup
> >
> > Private Sub Button1_MouseDown(ByVal sender As Object, _
> > ByVal e As System.Windows.Forms.MouseEventArgs) _
> > Handles Button1.MouseDown
> > Debug.WriteLine("Button1_MouseDown")
> > f = New formPopup
> >
> > f.Size = New Size(80, 80)
> > f.BackColor = Color.Yellow
> >
> > f.Show()
> > 'Button1.Capture = True 'Have to comment this or else I cannot
> > 'trap mouse trap events for controls on the > > form
> > End Sub
> >
> > Private Sub Button1_MouseUp(ByVal sender As Object, _
> > ByVal e As System.Windows.Forms.MouseEventArgs) _
> > Handles Button1.MouseUp, f.MouseUp
> > Debug.WriteLine("Button1_MouseUp")
> > f.Close()
> > f.Hide()
> > f = Nothing
> > End Sub
> > End Class
>
>


Nov 20 '05 #8
This looks good, he has more than enough to work with now.

I sent him through an eMail message a few hours ago but it's a dummy account
he probably uses to control spam (it was rejected). I look forward to him
replying confirming the detail.

Cheers Brian
Hexathioorthooxalate


"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
Ok, let's try this. This acts like a context menu with buttons. If this
isn't it, I don't know what he wants.

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual

f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

AddHandler Me.Leave, AddressOf subLeaving

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

Dim b3 As New Button()
b3.Size = New Size(15, 15)
b3.Location = New Point(50, 10)
b3.BackColor = Color.Gray
Me.Controls.Add(b3)

Dim b4 As New Button()
b4.Size = New Size(15, 15)
b4.Location = New Point(70, 10)
b4.BackColor = Color.Gray
Me.Controls.Add(b4)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
AddHandler b3.MouseEnter, AddressOf subMEnter
AddHandler b3.MouseLeave, AddressOf subMLeave
AddHandler b4.MouseEnter, AddressOf subMEnter
AddHandler b4.MouseLeave, AddressOf subMLeave
End Sub
Private Sub subLeaving(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
End Sub
End Class



"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10****************@damia.uk.clara.net...
"Brian" <no****@prairie.lakes.com> wrote in message
news:vr************@corp.supernews.com...
What? How do you select another button when the a button is already down? You have to release the button before you can select another. It seems to
me

Yes - I think he is wanting something like this although clearly as we can both see, he can't select the button via normal button clicks. I think it explains why he says he wants to capture MouseOver events for controls on the popup form, rather than click events.

I'm still waiting for Colin to repost and confirm exactly what he wants.

Hexathioorthooxalate
like he's trying to create a custom popup menu that works like the standard
Cut/Paste/SelectAll menu but with buttons. Is this right?

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message
news:10***************@damia.uk.clara.net...
> Brian, I'm not sure your code does exactly what he wants. This is the > confusion I think: from his posting I believe he wants to "select"

buttons

> on the popup form while the mouse button is down, and further only

display
> the popup form while the mouse button is down. If the mouse button is
ever
> released, regardless of where it is, then the popup form is
hidden/disposed
> of.
>
> > > When the mouse button is depressed over Button1, I want the
> > > popup form (an instance of formPopup) to show. If the mouse
> > > button is released anywhere, the cursor could be anywhere,
> > > even over another application or on the desktop or somewhere
else, > > > I want the popup form to be hidden. The code I have means that
> > > if I move the cursor away from the display form, then release
> > > the mouse button, the form isn't always hidden. I also want
> > > to trap various events in the instance of formPopup, such as
> > > mouseenter etc for controls on that form.
>
> Colin, could you reply to confirm your exact desired behaviour please. >
> Hexathioorthooxalate
>
>
>
> "Brian" <no****@prairie.lakes.com> wrote in message
> news:vr************@corp.supernews.com...
> >
> > Try this out Colin. It worked when I tried it. You need to set the
button
> > capture to True. Then create a rect of the button to see if the

point
is
> in
> > or out of the button. Also, why do you have Button1_MouseUp handling the
> > f.mouseup? Remove it and it will work.
> >
> >
> > Private Sub Button1_MouseDown(ByVal sender As Object, _
> > ByVal e As System.Windows.Forms.MouseEventArgs) _
> > Handles Button1.MouseDown
> > Debug.WriteLine("Button1_MouseDown")
> > f = New formPopup()
> >
> > f.Size = New Size(80, 80)
> > f.BackColor = Color.Yellow
> > f.Show()
> >
> > '-- You NEED to set this to true!
> > Button1.Capture = True
> >
> > End Sub
> >
> >
> >
> > Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
> > System.Windows.Forms.MouseEventArgs) _
> > Handles Button1.MouseUp ' ----------- f.MouseUp

<--------
> Get
> > rid of this. Why is this here?
> >
> >
> > Debug.WriteLine("Button1_MouseUp")
> >
> > '-- Create a rect of the button
> > Dim rect As New Rectangle(0, 0, Button1.Width, Button1.Height)
> >
> > '-- If mouse point isn't in the rect close it
> > If Not rect.Contains(e.X, e.Y) Then
> > f.Close()
> > f.Hide()
> > f = Nothing
> > End If
> >
> > '-- Release Button capture
> > Button1.Capture = False
> >
> > End Sub
> >
> >
> >
> >
> >
> >
> >
> > "Colin McGuire" <co***********@lycos.co.uk> wrote in message
> > news:ab**************************@posting.google.c om...
> > > Hi - this was posted last weekend and unfortunately not
resolved. The
> > > solutions that were posted almost worked but after another 5
days of > > > working on the code everynight, I am not further ahead.
> > > If you do have any ideas I would really like to hear them.
> > > Thanks
> > > Colin
> > >
> > > - 0 - 0 - 0 -
> > >
> > > I want a glorified popup/context menu on a button that shows
only when
> > > the mouse button is pressed over the button, and disappears when the > > > mouse button is released anywhere. Here's a full description.
> > >
> > > When the mouse button is depressed over Button1, I want the
> > > popup form (an instance of formPopup) to show. If the mouse
> > > button is released anywhere, the cursor could be anywhere,
> > > even over another application or on the desktop or somewhere
else, > > > I want the popup form to be hidden. The code I have means that
> > > if I move the cursor away from the display form, then release
> > > the mouse button, the form isn't always hidden. I also want
> > > to trap various events in the instance of formPopup, such as
> > > mouseenter etc for controls on that form. By adding
> > > Button1.Capture=True, no events in the instance of formPopup
> > > can be caught.
> > >
> > > Colin
> > >
> > >
> > > Here is the full code I already have.
> > >
> > > 1. Launch Visual Studio .Net 2003 and create a new winforms
> > > application.
> > > 2. Use the VS IDE toolbar to put a new button, Button1, on the

form. > > > 3. Paste in the following code
> > >
> > > Public Class Form1
> > > Inherits System.Windows.Forms.Form
> > >
> > > //and include the Windows Form Designer Code in here
> > >
> > > Public Class formPopup
> > > Inherits System.Windows.Forms.Form
> > >
> > > Private Sub formPopup_Load(ByVal sender As Object, _
> > > ByVal e As System.EventArgs) Handles MyBase.Load
> > > Dim b1 As New Button
> > > b1.Size = New Size(15, 15)
> > > b1.Location = New Point(10, 10)
> > > b1.BackColor = Color.Gray
> > > Me.Controls.Add(b1)
> > > AddHandler b1.MouseEnter, AddressOf subMEnter
> > > AddHandler b1.MouseLeave, AddressOf subMLeave
> > > AddHandler b1.MouseUp, AddressOf subMUp
> > >
> > > Dim b2 As New Button
> > > b2.Size = New Size(15, 15)
> > > b2.Location = New Point(30, 10)
> > > b2.BackColor = Color.Gray
> > > Me.Controls.Add(b2)
> > > AddHandler b2.MouseEnter, AddressOf subMEnter
> > > AddHandler b2.MouseLeave, AddressOf subMLeave
> > > End Sub
> > >
> > > Private Sub subMUp(ByVal sender As Object, _
> > > ByVal e As MouseEventArgs)
> > > Debug.WriteLine("MouseUp")
> > > End Sub
> > >
> > > Private Sub subMLeave(ByVal sender As Object, _
> > > ByVal e As EventArgs)
> > > Dim b As Button = CType(sender, Button)
> > > b.BackColor = Color.Gray
> > > End Sub
> > >
> > > Private Sub subMEnter(ByVal sender As Object, _
> > > ByVal e As EventArgs)
> > > Dim b As Button = CType(sender, Button)
> > > b.BackColor = Color.Blue
> > > End Sub
> > > End Class
> > >
> > >
> > > Dim WithEvents f As formPopup
> > >
> > > Private Sub Button1_MouseDown(ByVal sender As Object, _
> > > ByVal e As System.Windows.Forms.MouseEventArgs) _
> > > Handles Button1.MouseDown
> > > Debug.WriteLine("Button1_MouseDown")
> > > f = New formPopup
> > >
> > > f.Size = New Size(80, 80)
> > > f.BackColor = Color.Yellow
> > >
> > > f.Show()
> > > 'Button1.Capture = True 'Have to comment this or else I cannot
> > > 'trap mouse trap events for controls

on the
> > > form
> > > End Sub
> > >
> > > Private Sub Button1_MouseUp(ByVal sender As Object, _
> > > ByVal e As System.Windows.Forms.MouseEventArgs) _
> > > Handles Button1.MouseUp, f.MouseUp
> > > Debug.WriteLine("Button1_MouseUp")
> > > f.Close()
> > > f.Hide()
> > > f = Nothing
> > > End Sub
> > > End Class
> >
> >
>



Nov 20 '05 #9
OK, I think i got it (maybe).

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual
f.Capture = True
f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1 mouseup")
If Not f Is Nothing Then
f.Hide()
f.Close()
f = Nothing
End If

End Sub
End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Dim rect As Rectangle
Dim rect1 As Rectangle

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None

AddHandler Me.MouseUp, AddressOf fMouseUp
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp
AddHandler Me.MouseMove, AddressOf fMouseMove

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave

rect = New Rectangle(b1.Left, b1.Top, b1.Width, b1.Height)
rect1 = New Rectangle(b2.Left, b2.Top, b2.Width, b2.Height)

End Sub

Private Sub fMouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

If rect.Contains(e.X, e.Y) OrElse rect1.Contains(e.X, e.Y) Then
If Not Me.Capture = False Then
Me.Capture = False
End If
ElseIf Me.Capture = False Then
Me.Capture = True
End If

End Sub

Private Sub fMouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

Me.Capture = False
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue

End Sub
Nov 20 '05 #10
OK, I think i got it (maybe).

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual
f.Capture = True
f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1 mouseup")
If Not f Is Nothing Then
f.Hide()
f.Close()
f = Nothing
End If

End Sub
End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Dim rect As Rectangle
Dim rect1 As Rectangle

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None

AddHandler Me.MouseUp, AddressOf fMouseUp
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp
AddHandler Me.MouseMove, AddressOf fMouseMove

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave

rect = New Rectangle(b1.Left, b1.Top, b1.Width, b1.Height)
rect1 = New Rectangle(b2.Left, b2.Top, b2.Width, b2.Height)

End Sub

Private Sub fMouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

If rect.Contains(e.X, e.Y) OrElse rect1.Contains(e.X, e.Y) Then
If Not Me.Capture = False Then
Me.Capture = False
End If
ElseIf Me.Capture = False Then
Me.Capture = True
End If

End Sub

Private Sub fMouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

Me.Capture = False
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue

End Sub
Nov 20 '05 #11
Hex, this is exactly what I was wanting.
Thank you
Colin

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message news:<10***************@damia.uk.clara.net>...
Armin:
I too thought this was done and dusted. Looking at
the original thread it appears he also wants to
trap button events on the popup form.
Colin:
Try this (the code is below). The key code is in
formPopup_MouseLeave. If I understand the user
interface you are describing, you must have a really
good reason for wanting to code this behaviour. For
what it's worth, I find it annoying and not something
I would put into any of my applications.

Note that MouseLeave is not the only way to 'leave'
a control ! You will need to make it more robust.
Hexathioorthooxalate


Public Class Form1
Inherits System.Windows.Forms.Form

'[+]Windows Form Designer generated code

Public Class formPopup
Inherits System.Windows.Forms.Form

Public Event popupNotification()
Private _button As Button = Nothing

Public ReadOnly Property getButton() As Button
Get
Return _button
End Get
End Property

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
b1.Text = "1"
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
b2.Text = "2"

Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
AddHandler b2.MouseUp, AddressOf subMUp
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles MyBase.MouseUp
RaiseEvent popupNotification()
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
_button = Nothing
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
_button = b
End Sub

Private Sub formPopup_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.MouseLeave
Dim cursorPosition As Point = PointToClient(Cursor.Position())
Dim rect As Rectangle = Me.ClientRectangle
If Not rect.Contains(cursorPosition) Then
RaiseEvent popupNotification()
End If
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Const FORMWIDTH As Integer = 80
Const FORMHEIGHT As Integer = 80
f = New formPopup
f.Size = New Size(FORMWIDTH, FORMHEIGHT)
f.BackColor = Color.Yellow
f.FormBorderStyle = FormBorderStyle.FixedSingle
f.ControlBox = False
f.StartPosition = FormStartPosition.Manual
f.Location = New Point(Cursor.Position.X - FORMWIDTH \ 2, _
Cursor.Position.Y - FORMHEIGHT \ 2)
f.Show()
End Sub

Private Sub disposeOfPopupForm()
If Not Nothing Is f Then
f.Close()
f.Hide()
f = Nothing
End If
End Sub

Private Sub f_popupNotification() Handles f.popupNotification
Dim buttonPressed As Button = f.getButton
Call disposeOfPopupForm()
If Nothing Is buttonPressed Then
Debug.WriteLine("no button was pressed")
Else
Debug.WriteLine("Selected button: " + buttonPressed.Text)
End If
End Sub

End Class


"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Colin McGuire" <co***********@lycos.co.uk> schrieb
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on
the
form
End Sub


AFAIR I suggested to use

f.capture = true

instead of

button1.capture = true

in my last reply.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #12
Hex, this is exactly what I was wanting.
Thank you
Colin

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message news:<10***************@damia.uk.clara.net>...
Armin:
I too thought this was done and dusted. Looking at
the original thread it appears he also wants to
trap button events on the popup form.
Colin:
Try this (the code is below). The key code is in
formPopup_MouseLeave. If I understand the user
interface you are describing, you must have a really
good reason for wanting to code this behaviour. For
what it's worth, I find it annoying and not something
I would put into any of my applications.

Note that MouseLeave is not the only way to 'leave'
a control ! You will need to make it more robust.
Hexathioorthooxalate


Public Class Form1
Inherits System.Windows.Forms.Form

'[+]Windows Form Designer generated code

Public Class formPopup
Inherits System.Windows.Forms.Form

Public Event popupNotification()
Private _button As Button = Nothing

Public ReadOnly Property getButton() As Button
Get
Return _button
End Get
End Property

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
b1.Text = "1"
Me.Controls.Add(b1)
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

Dim b2 As New Button
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
b2.Text = "2"

Me.Controls.Add(b2)
AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave
AddHandler b2.MouseUp, AddressOf subMUp
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles MyBase.MouseUp
RaiseEvent popupNotification()
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
_button = Nothing
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue
_button = b
End Sub

Private Sub formPopup_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.MouseLeave
Dim cursorPosition As Point = PointToClient(Cursor.Position())
Dim rect As Rectangle = Me.ClientRectangle
If Not rect.Contains(cursorPosition) Then
RaiseEvent popupNotification()
End If
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Const FORMWIDTH As Integer = 80
Const FORMHEIGHT As Integer = 80
f = New formPopup
f.Size = New Size(FORMWIDTH, FORMHEIGHT)
f.BackColor = Color.Yellow
f.FormBorderStyle = FormBorderStyle.FixedSingle
f.ControlBox = False
f.StartPosition = FormStartPosition.Manual
f.Location = New Point(Cursor.Position.X - FORMWIDTH \ 2, _
Cursor.Position.Y - FORMHEIGHT \ 2)
f.Show()
End Sub

Private Sub disposeOfPopupForm()
If Not Nothing Is f Then
f.Close()
f.Hide()
f = Nothing
End If
End Sub

Private Sub f_popupNotification() Handles f.popupNotification
Dim buttonPressed As Button = f.getButton
Call disposeOfPopupForm()
If Nothing Is buttonPressed Then
Debug.WriteLine("no button was pressed")
Else
Debug.WriteLine("Selected button: " + buttonPressed.Text)
End If
End Sub

End Class


"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Colin McGuire" <co***********@lycos.co.uk> schrieb
Private Sub Button1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
f = New formPopup

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()
'Button1.Capture = True 'Have to comment this or else I cannot
'trap mouse trap events for controls on
the
form
End Sub


AFAIR I suggested to use

f.capture = true

instead of

button1.capture = true

in my last reply.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #13
Brian - this isn't what I described or wanted. It is better!
Thank you very much.
Colin
"Brian" <no****@prairie.lakes.com> wrote in message news:<vr************@corp.supernews.com>...
OK, I think i got it (maybe).

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual
f.Capture = True
f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1 mouseup")
If Not f Is Nothing Then
f.Hide()
f.Close()
f = Nothing
End If

End Sub
End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Dim rect As Rectangle
Dim rect1 As Rectangle

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None

AddHandler Me.MouseUp, AddressOf fMouseUp
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp
AddHandler Me.MouseMove, AddressOf fMouseMove

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave

rect = New Rectangle(b1.Left, b1.Top, b1.Width, b1.Height)
rect1 = New Rectangle(b2.Left, b2.Top, b2.Width, b2.Height)

End Sub

Private Sub fMouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

If rect.Contains(e.X, e.Y) OrElse rect1.Contains(e.X, e.Y) Then
If Not Me.Capture = False Then
Me.Capture = False
End If
ElseIf Me.Capture = False Then
Me.Capture = True
End If

End Sub

Private Sub fMouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

Me.Capture = False
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue

End Sub

Nov 20 '05 #14
Brian - this isn't what I described or wanted. It is better!
Thank you very much.
Colin
"Brian" <no****@prairie.lakes.com> wrote in message news:<vr************@corp.supernews.com>...
OK, I think i got it (maybe).

Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")
Dim pt As Point
Dim pt2 As Point
f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
pt = Cursor.Position

f.StartPosition = FormStartPosition.Manual
f.Capture = True
f.Location = pt
f.Show()

Cursor.Position = f.PointToScreen(New Point(0, 0))

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1 mouseup")
If Not f Is Nothing Then
f.Hide()
f.Close()
f = Nothing
End If

End Sub
End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Dim rect As Rectangle
Dim rect1 As Rectangle

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None

AddHandler Me.MouseUp, AddressOf fMouseUp
AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp
AddHandler Me.MouseMove, AddressOf fMouseMove

Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave

rect = New Rectangle(b1.Left, b1.Top, b1.Width, b1.Height)
rect1 = New Rectangle(b2.Left, b2.Top, b2.Width, b2.Height)

End Sub

Private Sub fMouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

If rect.Contains(e.X, e.Y) OrElse rect1.Contains(e.X, e.Y) Then
If Not Me.Capture = False Then
Me.Capture = False
End If
ElseIf Me.Capture = False Then
Me.Capture = True
End If

End Sub

Private Sub fMouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

Me.Capture = False
Me.Close()
End Sub

Private Sub subMUp(ByVal sender As Object, _
ByVal e As MouseEventArgs)
Debug.WriteLine("MouseUp")
End Sub

Private Sub subMLeave(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue

End Sub

Nov 20 '05 #15
Comments inline. Thanks Brian, Hex, and Armin.
Colin

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message news:<10***************@damia.uk.clara.net>...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons
on the popup form while the mouse button is down, and further only display
the popup form while the mouse button is down. If the mouse button is ever
released, regardless of where it is, then the popup form is hidden/disposed
of.
When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form.


Colin, could you reply to confirm your exact desired behaviour please.

I did want to select buttons while the mouse button was down. I did
want the popup to disappear whenever the mouse button was released.
What Brian has written behaves more like a slick Windows programme and
this is what I will use. What Hex has written is what I asked for. I
asked for the wrong thing :(

Thank you both again
Colin
Nov 20 '05 #16
Comments inline. Thanks Brian, Hex, and Armin.
Colin

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message news:<10***************@damia.uk.clara.net>...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons
on the popup form while the mouse button is down, and further only display
the popup form while the mouse button is down. If the mouse button is ever
released, regardless of where it is, then the popup form is hidden/disposed
of.
When the mouse button is depressed over Button1, I want the
popup form (an instance of formPopup) to show. If the mouse
button is released anywhere, the cursor could be anywhere,
even over another application or on the desktop or somewhere else,
I want the popup form to be hidden. The code I have means that
if I move the cursor away from the display form, then release
the mouse button, the form isn't always hidden. I also want
to trap various events in the instance of formPopup, such as
mouseenter etc for controls on that form.


Colin, could you reply to confirm your exact desired behaviour please.

I did want to select buttons while the mouse button was down. I did
want the popup to disappear whenever the mouse button was released.
What Brian has written behaves more like a slick Windows programme and
this is what I will use. What Hex has written is what I asked for. I
asked for the wrong thing :(

Thank you both again
Colin
Nov 20 '05 #17
Colin,

I went and read your first post and finally figured out what you wanted
(should have done that in the first place). Place this into your form mouse
up event: It will handle the mouse up event as long as the mouse is within
the form. I haven't figured it out (yet) when the mouse is off the form. It
will get you 90% where you what to be, i think.
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

If Not f Is Nothing Then Button1_MouseUp(sender, e)

End Sub

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Comments inline. Thanks Brian, Hex, and Armin.
Colin

"hexathioorthooxalate" <ru***@REMOVESPAM.clara.co.uk> wrote in message

news:<10***************@damia.uk.clara.net>...
Brian, I'm not sure your code does exactly what he wants. This is the
confusion I think: from his posting I believe he wants to "select" buttons on the popup form while the mouse button is down, and further only display the popup form while the mouse button is down. If the mouse button is ever released, regardless of where it is, then the popup form is hidden/disposed of.
> When the mouse button is depressed over Button1, I want the
> popup form (an instance of formPopup) to show. If the mouse
> button is released anywhere, the cursor could be anywhere,
> even over another application or on the desktop or somewhere else,
> I want the popup form to be hidden. The code I have means that
> if I move the cursor away from the display form, then release
> the mouse button, the form isn't always hidden. I also want
> to trap various events in the instance of formPopup, such as
> mouseenter etc for controls on that form.


Colin, could you reply to confirm your exact desired behaviour please.

I did want to select buttons while the mouse button was down. I did
want the popup to disappear whenever the mouse button was released.
What Brian has written behaves more like a slick Windows programme and
this is what I will use. What Hex has written is what I asked for. I
asked for the wrong thing :(

Thank you both again
Colin

Nov 20 '05 #18
Here's the final code. And it works!
Dim WithEvents f As formPopup

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Debug.WriteLine("Button1_MouseDown")

f = New formPopup()

f.Size = New Size(80, 80)
f.BackColor = Color.Yellow

f.Show()

'-- Trap button1 messages
Button1.Capture = True

End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Debug.WriteLine("Button1 mouseup")

'-- Kill menu if it exists
If Not f Is Nothing Then
'-- Release capture
Button1.Capture = False
f.Hide()
f.Close()
f = Nothing
End If

End Sub
'-- Resets button1 capture back to true if mouse left the context menu
'-- without the user releasing the button
Private Sub Mouseleft() Handles f.MouseLeft
Button1.Capture = True
End Sub


Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove

'-- See if the user is over the context menu.
'-- If so, release button1 capture so the
'-- context menu can receive its events.
If Not f Is Nothing Then
Dim pt As New Point()
Dim pt2 As Point
pt2 = Cursor.Position()
pt = f.Location
Dim rect As New Rectangle(pt.X, pt.Y, f.Width, f.Height)
'-- If over the menu, release capture.
If rect.Contains(pt2.X, pt2.Y) Then
Button1.Capture = False
End If
End If

End Sub

End Class

Public Class formPopup
Inherits System.Windows.Forms.Form

Event MouseLeft()

Private Sub formPopup_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b1 As New Button()
b1.Size = New Size(15, 15)
b1.Location = New Point(10, 10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
Me.FormBorderStyle = FormBorderStyle.None


AddHandler b1.MouseEnter, AddressOf subMEnter
AddHandler b1.MouseLeave, AddressOf subMLeave
AddHandler b1.MouseUp, AddressOf subMUp

'-- Add new handler for form mouse leave
AddHandler Me.MouseLeave, AddressOf subformLeave

'-- Optional, if you want to form to
'-- die when the user lifts the button up
AddHandler Me.MouseUp, AddressOf fMouseUp
Dim b2 As New Button()
b2.Size = New Size(15, 15)
b2.Location = New Point(30, 10)
b2.BackColor = Color.Gray
Me.Controls.Add(b2)

AddHandler b2.MouseEnter, AddressOf subMEnter
AddHandler b2.MouseLeave, AddressOf subMLeave

End Sub

'-- Raise a event if user didn't release button over the menu
'-- and they moved it back over the form or another window
Private Sub subformLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MouseLeave
RaiseEvent MouseLeft()
End Sub

'****************************************
'-- Optional, if you want to form to
'-- die when the user lifts the button up
Private Sub fMouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

'-- Close the form if that's what you want
Me.Close()
Debug.WriteLine("fMouseUp")

End Sub

'***************************************
Private Sub subMUp(ByVal sender As Object, ByVal e As MouseEventArgs)

'-- Do you want to do this whe an user lifts over a button? If not,
remove this.
Me.Close()

Debug.WriteLine("MouseUp")

End Sub

Private Sub subMLeave(ByVal sender As Object, ByVal e As EventArgs)

Dim b As Button = CType(sender, Button)
b.BackColor = Color.Gray
End Sub

Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs)
Dim b As Button = CType(sender, Button)
b.BackColor = Color.Blue

End Sub


Nov 20 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ken | last post by:
Hi, I have a MainForm and a SubForm. I also have a popup form that is opened by a button click on the subform. On that form I want to set the main form and subform. to set mainform you do this:...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Dino M. Buljubasic | last post by:
I have several context menus added to my form. The form is displaying items in listviews connected to the context menus. When I click on an item in a list view, a popup context menu shows allowing...
0
by: teddysnips | last post by:
I have Search form that allows users to retrieve records into a DataGrid. There are two search criteria - a Month and a Year, which are selected from drop-down lists. There is a server-side...
2
by: jackson2005 | last post by:
OK, I need to do three different things. On the ONLOAD event I would like a popup box to open. In this popup box I need two text boxes. One for the UserName and one for the BillingTo name. ...
4
by: Kaur | last post by:
I am reposting this message. I am a beginner using MS Access. I am working in MS Access 2000 and have created two forms. Form 1 is called frmParent (which has a read only subform called SfrmChild)....
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
3
by: cmo | last post by:
Well I hope I this isn't too nebulous of a problem. The problem I currently have is this: I have a button in a form that opens up a javascript/css poup that has an input field and two ahref links...
5
by: Thelma Roslyn Lubkin | last post by:
I am still having trouble trying to use a popup form to allow user to set filters for the main form. The main form is based on a single table. The popup contains 5 listboxes, so the user can...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.