2014-07-25 48 views
-1

使用我從這裏檢索的代碼:VB.net Click through form,我終於得到「點擊通過窗體」工作,但我仍然困惑如何禁用點擊通過。禁用點擊通過的形式VB.NET

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 
+0

使用Const聲明來表示幻數通常是明智的。你不會意外地使用-16這種方式,並且可能會看到你只使用InitialStyle來重置樣式。 –

回答

0

好吧,我已經解決了它自己,我只需要刪除一些參數。

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

我只需要刪除「WS_EX.Transparent」值,在這種情況下,值是& H20,所以我刪除「或& H20」

和代碼另一件事就是刪除「PercentVisible」倍增器,我刪除 「* PercentVisible」

代碼

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

那麼它現在就像魅力一樣。