禁用点击表格VB.NET

时间:2014-07-25 16:31:52

标签: vb.net visual-studio-2008

使用从此处检索到的代码:VB.net Click through form,我终于得到了#34;点击表格"工作但我仍然困惑如何禁用点击。

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, 0, 255 * PercentVisible, &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

我知道禁用可能在这2个代码中,但我无法使其正常工作,我们将非常感谢任何形式的帮助:

Public Sub BlaButton_click (blah blah) handles bla bla
        SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
        SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
End Sub

1 个答案:

答案 0 :(得分:0)

好的,我自己解决了,我只需要删除一些参数。

之前的代码

SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)

我只需删除“WS_EX.Transparent”值,在这种情况下,该值为&amp; H20,所以我删除了“Or&amp; H20”

另一件事是删除“PercentVisible”乘数,我删除了 “* PercentVisible”

之后的代码
SetWindowLong(Me.Handle, -20, InitialStyle  Or &H80000)
SetLayeredWindowAttributes(Me.Handle, 0, 255, &H2)

然后它就像魅力一样。