REPOST:按钮上的弹出窗体 [英] REPOST: Popup form on button
问题描述
嗨 - 这是上周末发布的,遗憾的是没有解决。发布的
解决方案几乎可以使用,但是在每晚工作代码的另外5天后,我不会再领先了。
如果你有什么想法我真的很想听他们。
谢谢
科林
- 0 - 0 - 0 -
我想在一个按钮上显示一个美化的弹出/上下文菜单,只显示当按下按钮时按下鼠标按钮时
,并且当
鼠标按钮随处可见。这是一个完整的描述。
当在Button1上按下鼠标按钮时,我想要显示
弹出窗体(formPopup的一个实例)。如果鼠标
按钮在任何地方发布,光标可以在任何地方,即使在另一个应用程序或桌面或其他地方,也可以是
,
我希望隐藏弹出窗体。我的代码意味着
如果我将光标移离显示窗体,然后释放鼠标按钮,那么窗体并不总是隐藏的。我还想要
来捕获formPopup实例中的各种事件,例如
mouseenter等用于该窗体上的控件。通过添加
Button1.Capture = True,可以捕获formPopup
实例中的事件。
Colin
这是我已经拥有的完整代码。
1.启动Visual Studio .Net 2003并创建一个新的winforms
应用程序。
2.使用VS IDE工具栏在表单上放置一个新按钮Button1。
3.粘贴以下代码
Public Class Form1
继承System.Windows.Forms.Form
//并在此处包含Windows窗体设计器代码
公共类formPopup
继承System.Windows.Forms.Form
Private Sub formPopup_Load(ByVal sender As Object,_
ByVal e As System.EventArgs)处理MyBase.Load
Dim b1作为新按钮
b1.Size =新尺寸(15,15)
b1.Location =新点(10,10)
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter,Addre ssOf subMEnter
AddHandler b1.MouseLeave,AddressOf subMLeave
AddHandler b1.MouseUp,AddressOf subMUp
Dim b2 As New Button
b2.Size =新尺寸(15,15)
b2.Location =新点(30,10)
b2.BackColor =颜色.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(发送者,按钮)
b.BackColor = Color.Gray
End Sub
Private Sub subMEnter(ByVal sender As Object,_
ByVal e As EventArgs)
Dim b As Button = CType(发送者) ,按钮)
b.BackColor = Color.Bl ub
结束次级
结束班级
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 =新尺寸(80,80)
f.BackColor = Color.Yellow
f.Show()
''Button1.Capture = True''必须发表评论否则我不能
''陷阱鼠标陷阱事件为
表格上的控件
结束子
私人子按钮1 _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
结束班
"科林麦奎尔" <共*********** @ lycos.co.uk> schriebPrivate Sub Button1_MouseDown(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs)_
Handles Button1.MouseDown
Debug.WriteLine (" Button1_MouseDown")
f =新formPopup
f.Size =新尺寸(80,80)
f.BackColor = Color.Yellow
f.Show()
''Button1.Capture = True''必须对此进行评论,否则我无法
''捕获鼠标陷阱事件的控件
表格
End Sub
AFAIR我建议使用
f.capture = true
而不是
button1.capture = true
我的上一个回复。
-
Armin
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Armin:
我也认为这已经完成并且已经粉碎了。看看
它出现的原始线程他还想在弹出窗体上显示
陷阱按钮事件。
Colin:
试试这个(代码如下)。关键代码在
formPopup_MouseLeave中。如果我理解你所描述的用户
界面,你必须有一个非常好的理由想要编码这种行为。对于
它的价值,我发现它很烦人而且不是什么东西
我会把它放到我的任何应用程序中。
请注意,MouseLeave不是''离开''
a控制权的唯一方法!你需要让它更健壮。
Hexathioorthooxalate
公共类Form1
继承System.Windows。 Forms.Form
''[+] Windows窗体设计器生成的代码
公共类formPopup
继承系统.Windows.Forms.Form
公共事件popupNotification()
私有_按钮按钮=无任何
公开ReadOnly Property getButton()As Button
获取
返回_button
结束获取
结束物业
Private Sub formPopup_Load(ByVal sender As Object,_
ByVal e As System.EventArgs)Handles MyBase.Load
Dim b1 As New Button
b1.Size =新尺寸(15,15)
b1.Location =新点(10,10)
b1.BackColor = Color.Gray
b1.Text =" 1"
Me.Controls.Add(b1)
AddHandler b1.MouseEnter,AddressOf subMnter
AddHandler b1.MouseLeave,A ddressOf subMLeave
AddHandler b1.MouseUp,AddressOf subMUp
Dim b2 As New Button
b2.Size =新尺寸(15 ,15)
b2.Location =新点(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)处理MyBase.MouseUp
RaiseEvent popupNotification()
End Sub
Private Sub subMLeave(ByVal sender As Object,_
ByVal e As EventArgs)
Dim b As Button = CType(发送者,按钮)
b.BackColor = Color.Gray
_button = Nothing
End Sub
Private Sub subMEnter(ByVal sender As Object, _
ByVal e As EventArgs )
Dim b As Button = CType(发送者,按钮)
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
如果不是rect.Contains(cursorPosition)然后
RaiseEvent popupNotification()
结束如果
结束次级
结束班级
Dim WithEvents f as formPopup
Private Sub Button1_MouseDown(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs)_
处理Button1.MouseDown
Const FORMWIDTH As Integer = 80
Const FORMHEIGHT As Integer = 80
f = New formPopup
f.Size =新尺寸(FORMWIDTH,FORMHEIGHT)
f.BackColor = Color.Yellow
f.FormBorderSty le = 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()
结束子
私人子disposeOfPopupForm()
如果不是没有,那么
f.Close()
f.Hide()
f =没什么
结束如果
结束子
Private Sub f_popupNotification()处理f.popupNotification
Dim buttonPressed As Button = f.getButton
调用disposeOfPopupForm()
如果Nothing是buttonPressed然后
Debug.WriteLine(没有按下按钮)
否则
Debug.WriteLine(" Selected button:" + buttonPressed.Text)
结束如果
结束子
结束班
>
" Armin Zingler" < AZ ******* @ freenet.de>在消息中写道
news:%2 **************** @ TK2MSFTNGP11.phx.gbl ..." Colin McGuire <共*********** @ lycos.co.uk> schriebPrivate Sub Button1_MouseDown(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs)_
Handles Button1.MouseDown
Debug.WriteLine (" Button1_MouseDown")
f =新formPopup
f.Size =新尺寸(80,80)
f.BackColor = Color.Yellow
f.Show()
''Button1.Capture = True''必须对此进行评论,否则我无法
''捕获鼠标陷阱事件的控件
表格
End Sub
AFAIR我建议使用
f.capture = true
而不是
button1.capture = true
在我的上一篇回复中。
-
Armin
http://www.plig.net/nnq/nquote.html
http:/ /www.netmeister.org/news/learn2quote.html
试一试科林。它在我尝试时起作用了。你需要将按钮
capture设置为True。然后创建按钮的矩形以查看该点是否在
或按钮之外。另外,为什么你有Button1_MouseUp处理
f.mouseup?删除它,它将工作。
Private Sub Button1_MouseDown(ByVal发送者为对象,_
ByVal e As System.Windows.Forms.MouseEventArgs)_
Handles Button1.MouseDown
Debug.WriteLine(" Button1_MouseDown")
f = new formPopup()
f .Size =新尺寸(80,80)
f.BackColor = Color.Yellow
f.Show()
'' - 你需要将其设置为true!
Button1.Capture = True
结束子
Private Sub Button1_MouseUp(ByVal sender As Object,ByVal e As
System.Windows.Forms.MouseEventArgs)_
处理Button1.MouseUp''------ ----- f.MouseUp< -------- Get
摆脱这个。这是为什么?
Debug.WriteLine(" Button1_MouseUp")
'' - 创建按钮的矩形
Dim rect As New Rectangle(0,0,Button1.Width,Button1.Height)
'' - 如果鼠标点不在矩形关闭它
如果不是rect.Contains(eX,eY)那么
f.Close()
f.Hide()
f = Nothing
结束如果
'' - 释放按钮捕获
Button1.Capture = False
< br $>
End Sub
" Colin McGuire" <共*********** @ lycos.co.uk>在消息中写道
news:ab ************************** @ posting.google.c om ...嗨 - 这是上周末发布的,遗憾的是没有解决。发布的
解决方案几乎可以工作,但是在每周工作代码5天之后,我不会再领先了。
如果你有任何想法,我真的很想听听他们。
谢谢
科林
- 0 - 0 - 0 -
我想在一个按钮上显示一个美化的弹出/上下文菜单,只显示<鼠标按钮按下按钮,当任何地方释放
鼠标按钮时消失。这是一个完整的描述。
当按下Button1上的鼠标按钮时,我想要显示
弹出窗体(formPopup的一个实例)。如果在任何地方释放鼠标
按钮,光标可以在任何地方,甚至在其他应用程序或桌面或其他地方,
我希望隐藏弹出窗体。我的代码意味着如果我将光标移离显示窗体,然后释放鼠标按钮,表单并不总是隐藏的。我还希望
能够在formPopup的实例中捕获各种事件,例如
mouseenter等,以获取该窗体上的控件。通过添加
Button1.Capture = True,可以捕获formPopup
实例中的事件。
Colin
这是完整的代码我已经有了。
1.启动Visual Studio .Net 2003并创建一个新的winforms
应用程序。
2.使用VS IDE工具栏将一个新按钮Button1打开表格。
3.粘贴以下代码
Public Class Form1
继承System.Windows.Forms.Form
//并包含Windows窗体设计器代码在这里
公共类formPopup
继承System.Windows.Forms.Form
私有Sub formPopup_Load(ByVal sender As Object,_
ByVal e As System.EventArgs)处理MyBase.Load
Dim b1作为新按钮
b1.Size =新尺寸(15,15)
b1.Location =新点(10,10) )
b1.BackColor = Color.Gray
Me.Controls.Add(b1)
AddHandler b1.MouseEnter,AddressOf subMEnter
AddHandler b1.MouseLeave,AddressOf subMLeave
ADDH andler 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
结束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
结束子
私有子子计算器(ByVal发送者为对象,_
ByVal e As EventArgs)
Dim b As Button = CType(发送者,按钮)
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 =新尺寸(80,80)
f.BackColor = Color.Yellow
f.Show()
''Button1.Capture =真''必须评论这个或者我不能
''捕捉鼠标陷阱事件的控件在
表格上
结束子
私人子按钮1_MouseUp(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs)_
Handles Button1.MouseUp,f.MouseUp
Debug.WriteLine(" Button1_MouseUp")
f。关闭()
f.Hide()
f =无结果子结束
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
"Colin McGuire" <co***********@lycos.co.uk> schriebPrivate 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> schriebPrivate 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
这篇关于REPOST:按钮上的弹出窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!