السلام عليكم ورحم الله وبركاته
تفضل أخي الحبيب هذا هو الكود
فقط قم بنسخه واستبدل جميع الكود في مثالك
بالتوفيق
تفضل أخي الحبيب هذا هو الكود
فقط قم بنسخه واستبدل جميع الكود في مثالك
كود :
Public Class Form1
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
Dim MouseMonitor As New System.Threading.Thread(AddressOf MouseMonitoring)
Private Event MouseIn(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Private Event MouseOut(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Delegate Sub SetCallback(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Private Sub MouseMonitoring()
10:
Dim MousePosition As New Point
GetCursorPos(MousePosition)
Dim FormFrameWidth As Integer = (Me.Width - Me.ClientSize.Width) / 2
Dim FormTitleHeight As Integer = Me.Height - Me.ClientSize.Height - FormFrameWidth
Dim CurrentX As Integer = MousePosition.X - Me.Left - FormFrameWidth
Dim CurrentY As Integer = MousePosition.Y - Me.Top - FormTitleHeight
Dim e As New System.Windows.Forms.MouseEventArgs(Nothing, 0, MousePosition.X, MousePosition.Y, 0)
If CurrentX >= 0 AndAlso CurrentX < Me.ClientSize.Width Then
If CurrentY >= 0 AndAlso CurrentY < Me.ClientSize.Height Then
RaiseEvent MouseIn(Me, e)
Else
RaiseEvent MouseOut(Me, e)
End If
Else
RaiseEvent MouseOut(Me, e)
End If
System.Threading.Thread.Sleep(100)
GoTo 10
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
MouseMonitor.Abort()
End Sub
Sub Form1_MouseIn(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseIn
If Me.InvokeRequired Then
Dim Callback As New SetCallback(AddressOf Form1_MouseIn)
Me.Invoke(Callback, New Object() {sender, e})
Else
'هنا يتم وضع الكود
Me.Opacity = 0.5
End If
End Sub
Sub Form1_MouseOut(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseOut
If Me.InvokeRequired Then
Dim Callback As New SetCallback(AddressOf Form1_MouseOut)
Me.Invoke(Callback, New Object() {sender, e})
Else
'هنا يتم وضع الكود
Me.Opacity = 1
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MouseMonitor.Start()
End Sub
End Classبالتوفيق

