vb.net - vb.net Click through windows form, just right or left mouseclick
问题描述
As described here I managed to have a Windows-Form one can click through.
My (in my opinion for this question most) relevant code parts read as follows:
First imports:
...
Imports System.Runtime.InteropServices
...
then definition and import of DLLs
...
Private InitialStyle As Integer
Dim PercentVisible As Decimal
...
<DllImport("user32.dll", EntryPoint:="GetWindowLong")> Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("user32.dll", EntryPoint:="SetWindowLong")> Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll", EntryPoint:="SetLayeredWindowAttributes")> Public Shared Function SetLayeredWindowAttributes(ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
End Function
...
and finally using it
...
InitialStyle = GetWindowLong(Me.Handle, -20)
PercentVisible = 0.8
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
...
As mentioned, this code makes it possible to click throug a windows form, so the clicks reach the programm placed behind the windows form. In my opinion the feature is best described as color filter for parts of or the whole monitor.
Is there a possibility to modify the code in such a way, that only left clicks are transferred through the form? Right mouse clicks are needed to open a contextmenu or the like...
解决方案
如果要接收鼠标事件,则必须&H20
像这样从窗口样式中删除
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000)
但这可以防止所有鼠标事件通过您的表单传播。现在您可以根据需要处理事件。并且您必须自己将鼠标左键单击相关事件传播到其他应用程序。
推荐阅读
- pandas - 如何在 SageMaker 笔记本终端中更新 pandas 版本?
- java - 如何删除计划作业的特定触发器
- c - C中 malloc() 函数的神秘行为
- parallel-processing - 函数式编程对并行计算有何好处?
- xslt - 将一长段重复的 XSLT 分配给变量
- asp.net-core - 从 C# 生成有效的 __RequestVerificationToken
- docker - 如果我使用绑定挂载,为什么我还需要在我的 Dockerfile 中执行 COPY?
- python - Python - 从 2 个集合中查找最接近的索引
- react-native - React native material dropdown - 如何根据下拉值呈现文本
- javascript - 如何为我的 html 表单制作验证器?