473,851 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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.MouseEven tArgs) _
Handles Button1.MouseUp , f.MouseUp
Debug.WriteLine ("Button1_Mouse Up")
f.Close()
f.Hide()
f = Nothing
End Sub
End Class
Nov 20 '05 #1
18 2993
"Colin McGuire" <co***********@ lycos.co.uk> schrieb
Private Sub Button1_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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_Mouse Leave. 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.
Hexathioorthoox alate


Public Class Form1
Inherits System.Windows. Forms.Form

'[+]Windows Form Designer generated code

Public Class formPopup
Inherits System.Windows. Forms.Form

Public Event popupNotificati on()
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.EventArg s) 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 popupNotificati on()
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_Mouse Leave(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.MouseLea ve
Dim cursorPosition As Point = PointToClient(C ursor.Position( ))
Dim rect As Rectangle = Me.ClientRectan gle
If Not rect.Contains(c ursorPosition) Then
RaiseEvent popupNotificati on()
End If
End Sub
End Class
Dim WithEvents f As formPopup

Private Sub Button1_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Const FORMWIDTH As Integer = 80
Const FORMHEIGHT As Integer = 80
f = New formPopup
f.Size = New Size(FORMWIDTH, FORMHEIGHT)
f.BackColor = Color.Yellow
f.FormBorderSty le = FormBorderStyle .FixedSingle
f.ControlBox = False
f.StartPosition = FormStartPositi on.Manual
f.Location = New Point(Cursor.Po sition.X - FORMWIDTH \ 2, _
Cursor.Position .Y - FORMHEIGHT \ 2)
f.Show()
End Sub

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

Private Sub f_popupNotifica tion() Handles f.popupNotifica tion
Dim buttonPressed As Button = f.getButton
Call disposeOfPopupF orm()
If Nothing Is buttonPressed Then
Debug.WriteLine ("no button was pressed")
Else
Debug.WriteLine ("Selected button: " + buttonPressed.T ext)
End If
End Sub

End Class


"Armin Zingler" <az*******@free net.de> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
"Colin McGuire" <co***********@ lycos.co.uk> schrieb
Private Sub Button1_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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.MouseEven tArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
rid of this. Why is this here?
Debug.WriteLine ("Button1_Mouse Up")

'-- 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.goo gle.com...
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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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.MouseEven tArgs) _
Handles Button1.MouseUp , f.MouseUp
Debug.WriteLine ("Button1_Mouse Up")
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.

Hexathioorthoox alate

"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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.MouseEven tArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get rid of this. Why is this here?
Debug.WriteLine ("Button1_Mouse Up")

'-- 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.goo gle.com...
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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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.MouseEven tArgs) _
Handles Button1.MouseUp , f.MouseUp
Debug.WriteLine ("Button1_Mouse Up")
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?

"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** *******@damia.u k.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.

Hexathioorthoox alate

"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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.MouseEven tArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <--------

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

'-- 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.goo gle.com...
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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
f = New formPopup

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

f.Show()
'Button1.Captur e = 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.MouseEven tArgs) _
Handles Button1.MouseUp , f.MouseUp
Debug.WriteLine ("Button1_Mouse Up")
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.super news.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.

Hexathioorthoox alate
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?

"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** *******@damia.u k.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.

Hexathioorthoox alate

"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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.MouseEven tArgs) _
Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
rid of this. Why is this here?
Debug.WriteLine ("Button1_Mouse Up")

'-- 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.goo gle.com...
> 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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
> ByVal e As System.Windows. Forms.MouseEven tArgs) _
> Handles Button1.MouseDo wn
> Debug.WriteLine ("Button1_Mouse Down")
> f = New formPopup
>
> f.Size = New Size(80, 80)
> f.BackColor = Color.Yellow
>
> f.Show()
> 'Button1.Captur e = 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.MouseEven tArgs) _
> Handles Button1.MouseUp , f.MouseUp
> Debug.WriteLine ("Button1_Mouse Up")
> 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_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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 = FormStartPositi on.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.EventArg s) 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.FormBorderSt yle = 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(ByVa l sender As Object, ByVal e As
System.EventArg s) 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



"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** ********@damia. uk.clara.net...
"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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.

Hexathioorthoox alate
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?

"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** *******@damia.u k.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.

Hexathioorthoox alate

"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, _
> ByVal e As System.Windows. Forms.MouseEven tArgs) _
> Handles Button1.MouseDo wn
> Debug.WriteLine ("Button1_Mouse Down")
> 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.MouseEven tArgs) _
> Handles Button1.MouseUp ' ----------- f.MouseUp <-------- Get
> rid of this. Why is this here?
>
>
> Debug.WriteLine ("Button1_Mouse Up")
>
> '-- 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.goo gle.com...
> > 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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
> > ByVal e As System.Windows. Forms.MouseEven tArgs) _
> > Handles Button1.MouseDo wn
> > Debug.WriteLine ("Button1_Mouse Down")
> > f = New formPopup
> >
> > f.Size = New Size(80, 80)
> > f.BackColor = Color.Yellow
> >
> > f.Show()
> > 'Button1.Captur e = 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.MouseEven tArgs) _
> > Handles Button1.MouseUp , f.MouseUp
> > Debug.WriteLine ("Button1_Mouse Up")
> > 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
Hexathioorthoox alate


"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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 = FormStartPositi on.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.EventArg s) 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.FormBorderSt yle = 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(ByVa l sender As Object, ByVal e As
System.EventArg s) 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



"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** ********@damia. uk.clara.net...
"Brian" <no****@prairie .lakes.com> wrote in message
news:vr******** ****@corp.super news.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.

Hexathioorthoox alate
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?

"hexathioorthoo xalate" <ru***@REMOVESP AM.clara.co.uk> wrote in message
news:10******** *******@damia.u k.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. >
> Hexathioorthoox alate
>
>
>
> "Brian" <no****@prairie .lakes.com> wrote in message
> news:vr******** ****@corp.super news.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_MouseDo wn(ByVal sender As Object, _
> > ByVal e As System.Windows. Forms.MouseEven tArgs) _
> > Handles Button1.MouseDo wn
> > Debug.WriteLine ("Button1_Mouse Down")
> > 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.MouseEven tArgs) _
> > Handles Button1.MouseUp ' ----------- f.MouseUp

<--------
> Get
> > rid of this. Why is this here?
> >
> >
> > Debug.WriteLine ("Button1_Mouse Up")
> >
> > '-- 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.goo gle.com...
> > > 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.EventArg s) 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_MouseDo wn(ByVal sender As Object, _
> > > ByVal e As System.Windows. Forms.MouseEven tArgs) _
> > > Handles Button1.MouseDo wn
> > > Debug.WriteLine ("Button1_Mouse Down")
> > > f = New formPopup
> > >
> > > f.Size = New Size(80, 80)
> > > f.BackColor = Color.Yellow
> > >
> > > f.Show()
> > > 'Button1.Captur e = 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.MouseEven tArgs) _
> > > Handles Button1.MouseUp , f.MouseUp
> > > Debug.WriteLine ("Button1_Mouse Up")
> > > 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_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
Debug.WriteLine ("Button1_Mouse Down")
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 = FormStartPositi on.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.MouseEven tArgs) 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.EventArg s) 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.FormBorderSt yle = 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.Le ft, b1.Top, b1.Width, b1.Height)
rect1 = New Rectangle(b2.Le ft, b2.Top, b2.Width, b2.Height)

End Sub

Private Sub fMouseMove(ByVa l sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseMov e

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.MouseEven tArgs) 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

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

Similar topics

4
1518
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: dim f as form set f = forms("MainForm") ---this works
1
11604
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 http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
2
1649
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 me to chese between editing or deleting the item from the list view. That works fine. However, in addition to calling the context menu on Click, I can call it also by RightClick which causes application to either freeze, crash, call Delete...
0
1849
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 button called "cmdFilter" which retrieves data from the database using any criteria thus selected. For any of the records retrieved into the grid match certain conditions, one of the columns will be formed into a hyperlink. Clicking on this will...
2
6967
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. After entering these two items the user can either hit the enter key or press the submit button. The popup window will close and then those two text boxes in the original webpage will be filled in automatically. I would like to have the two...
4
1870
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). FrmParent has a list box that lists all the Last Names of parents in the db. Clicking on one of the lastname of parent in the list box shows children of selected parent in the SfrmChild. I have a button on frmParent that opens up a pop up form...
4
8869
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 which allows me to edit the record in the subform. What I want to happen is for subform with the new edits to be updated on the main form when I close the popup. I'm sure this is a very small bit of code in the the 'On close' event for the popup...
3
2787
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 for ok and cancel, both of which call the popup's toggle() method (same thing that is called from the button). The form that this button is in has fields that can be added or removed by the user. Everything works great in firefox and netscape,...
5
2463
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 filter on 5 fields in this table, and can include as many field values as s/he needs. The popup is reached from a command button on the main form : This button is on the main form, Datasystem:
0
9895
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7900
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.