VB.NET 点击和点击同时点击表格
使用下面的代码,我可以点击,但我必须同时点击表单,因为我想要一个透明的表单点击后面,但每次点击时我都必须放一首歌曲。
这是代码,
Imports System.Runtime.InteropServices
Public Class GhostForm
Private InitialStyle As Integer
Private PercentVisible As Decimal
Public Property WS_EX_TRANSPARENT As Integer
Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer) As Integer
Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitialStyle = GetWindowLong(Me.Handle, -20)
PercentVisible = 0.5
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
Me.TopMost = True
End Sub
Public Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick, Label1.MouseClick, Button1.MouseClick
Label1.Text = String.Format("Clicked ""{0}"" with the {1} mouse button.", sender.name, e.Button.ToString.ToLower)
Select Case e.Button
Case MouseButtons.Left
Label1.Text = "Left"
Case MouseButtons.Right
Label1.Text = "Right"
Case MouseButtons.Middle
Label1.Text = "Middle"
Case Else
Label1.Text = "Some other button"
End Select
End Sub
Private Sub GhostForm_Click(sender As Object, e As EventArgs) Handles Me.Click
Console.Beep()
Dim sp As New System.Media.SoundPlayer("C:\WINDOWS\MEDIA\Ding.wav")
sp.Play()
sp.Dispose()
End Sub
End Class
点击表单后如何才能播放歌曲?
所以我重新表述我的问题。我有触摸屏,并且支持的驱动程序没有给我“蜂鸣声”选项,因此我想开发一个小型应用程序,让客户每次触摸触摸屏时都能听到蜂鸣声。为此,我必须创建一个透明表单,以便我可以单击表单后面的内容。然而,这段代码做得很完美,它不支持我的点击功能,因为点击会通过它。所以问题是:当我点击表单时如何获得音频输出?
With the code below, I can click-through but I have to click on the form at the same time because I want a transparent form to click behind but I have to put a song when I click every time.
This is the code
Imports System.Runtime.InteropServices
Public Class GhostForm
Private InitialStyle As Integer
Private PercentVisible As Decimal
Public Property WS_EX_TRANSPARENT As Integer
Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer) As Integer
Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitialStyle = GetWindowLong(Me.Handle, -20)
PercentVisible = 0.5
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
Me.TopMost = True
End Sub
Public Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick, Label1.MouseClick, Button1.MouseClick
Label1.Text = String.Format("Clicked ""{0}"" with the {1} mouse button.", sender.name, e.Button.ToString.ToLower)
Select Case e.Button
Case MouseButtons.Left
Label1.Text = "Left"
Case MouseButtons.Right
Label1.Text = "Right"
Case MouseButtons.Middle
Label1.Text = "Middle"
Case Else
Label1.Text = "Some other button"
End Select
End Sub
Private Sub GhostForm_Click(sender As Object, e As EventArgs) Handles Me.Click
Console.Beep()
Dim sp As New System.Media.SoundPlayer("C:\WINDOWS\MEDIA\Ding.wav")
sp.Play()
sp.Dispose()
End Sub
End Class
How can I have a song when a click-through the form?
So I rephrase my question. I have touch screens and the supported drivers don't give me the "beep" option so I want to develop a small app that will allow to hear a beep every time the customer touches the touch screen. to do this I have to create a transparent form that will allow me to click on what is behind the form. What this code does perfectly, however, it does not support my click function because the click passes through it. so the question is: How can I get audio output when I click through the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论