VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了VB.net点击表格大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在为我的深夜星星凝视制作一个程序,我需要我的笔记本电脑屏幕只有红色,所以我想制作一个充当红色滤镜的程序.它将覆盖整个屏幕并且是透明的红色.用户可以点击它,就像在屏幕前面放一块透明的红色塑料一样.

到目前为止,我有一个表单可以根据您的屏幕尺寸进行调整,并将自身移动到左上角.它略带透明和红色.

我需要让表单上的所有点击都通过,因为我最终会使表单透明和红色,但我不希望用户能够与它进行交互.

程序称为“Red_Filter”

Public Class Form1

Dim Screens As Array
Dim @R_748_10586@lWidth As Integer
Dim @R_748_10586@lHeight As Integer
Dim Heights As List(Of Integer) = New List(Of Integer)

'Load / Close
Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
    Screens = Screen.AllScreens

    For I As Integer = 0 To UBound(Screens)

        @R_748_10586@lWidth += Screens(I).bounds.Width
        Heights.Add(Screens(I).bounds.Height)

    Next

    @R_748_10586@lHeight = Heights.Max()

    Me.Width = @R_748_10586@lWidth
    Me.Height = @R_748_10586@lWidth

    Me.LOCATIOn = New Point(0,0)

    Me.BACkColor = Color.Red
    Me.opacity = 0.5
    Me.TopMost = True

    'Make it click through
    SetWindowLong(Me.Handle,GWL_EXSTYLE,WS_EX_TRANSPARENT)
End Sub


'Click Through Functionality
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long) As Long
Const GWL_EXSTYLE = -20
Const WS_EX_TRANSPARENT = &H20

End Class

这是我到目前为止,我在网上找到的”点击功能’之后的部分,然而,它给了我这个错误:

A call to PInvoke function 'Red Filter!Red_Filter.Form1::SetWindowLong' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

我不知道我在网上发现的代码是如何工作的,但错误发生在表单的load事件的最后一行.

有谁知道如何制作表单点击?

我从这个代码项目帖子中删除了代码: http://www.codeproject.com/Articles/12877/Transparent-Click-Through-Forms

这是一个复杂的版本,包含所有评论 – 优点:

Imports System.Runtime.Interopservices

Public Class Form1

Private InitialStyle As Integer
Dim PercentVisible As decimal

Private Sub Form_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
    ' Grab the Extended Style information
    ' for this window and store it.
    InitialStyle = GetWindowLong(Me.Handle,GWl.ExStylE)
    PercentVisible = 0.8

    ' Set this window to Transparent
    ' (to the mouse that is!)

    ' This creates a new Extended Style
    ' for our window,which takes effect
    ' immediately upon being set,that
    ' combines the initial style of our window
    ' (saved in Form.Load) and adds the ability
    ' to be Transparent to the mouse.
    ' Both Layered and Transparent must be
    ' turned on for this to work AND have
    '  the window render properly!
    SetWindowLong(Me.Handle,GWl.ExStyle,InitialStyle Or WS_EX.Layered Or WS_EX.Transparent)

    ' Don't forget to set the Alpha
    ' for the window or else you won't be able
    ' to see the window! Possible values
    ' are 0 (visibly transparent)
    ' to 255 (visibly opaquE). I'll set
    ' it to 70% visible here for show.
    ' The second parameter is 0,because
    ' we're not using a ColorKey!
    SetLayeredWindowAttributes(Me.Handle,255 * PercentVisible,LWA.Alpha)

    ' Just for giggles,set this window
    ' to stay on top of all others so we
    ' can see what's happening.
    Me.TopMost = True
    Me.BACkColor = Color.Red
End Sub

Public Enum GWL As Integer
    ExStyle = -20
End Enum

Public Enum WS_EX As Integer
    Transparent = &H20
    Layered = &H80000
End Enum

Public Enum LWA As Integer
    ColorKey = &H1
    Alpha = &H2
End Enum

<DllImport("user32.dll",EntryPoint:="GetWindowLong")> _
Public Shared Function GetWindowLong( _
    ByVal hWnd As IntPtr,_
    ByVal nIndex As GWL _
        ) As Integer
End Function

<DllImport("user32.dll",EntryPoint:="SetWindowLong")> _
Public Shared Function SetWindowLong( _
    ByVal hWnd As IntPtr,_
    ByVal nIndex As GWL,_
    ByVal dwNewLong As WS_EX _
        ) 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 LWA _
        ) As Boolean
End Function
End Class

这是我正在使用的简化版本对我来说更有意义:

Imports System.Runtime.Interopservices

Public Class Form1

Private InitialStyle As Integer
Dim PercentVisible As decimal

Private Sub Form_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
    InitialStyle = GetWindowLong(Me.Handle,-20)
    PercentVisible = 0.8

    SetWindowLong(Me.Handle,-20,InitialStyle Or &H80000 Or &H20)

    SetLayeredWindowAttributes(Me.Handle,&H2)

    Me.BACkColor = Color.Red
    Me.TopMost = True
End Sub

<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

End Class

大佬总结

以上是大佬教程为你收集整理的VB.net点击表格全部内容,希望文章能够帮你解决VB.net点击表格所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。