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 18 2862
"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
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
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
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
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
"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
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 > >
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 > > > > >
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
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
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
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
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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:...
|
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...
|
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...
|
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...
|
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. ...
|
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)....
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |