I had searching on internet about how draw a rectangular hole on Form, and I found this good example in Delphi language, then I have tried reproduce this example in VB.NET, until now I had success in draw the rectangle hole on Form, but the dimensions this rectangle is not correspond with real mouse position on my computer screen
And also relative to Delphi example, had dificulties for adapt ClientToScreen
function to my example, that probably could be solution for this problem.
Someone could help me with this, please?
Here is my last attempt:
<DllImport("user32.dll")> _
Private Shared Function ClientToScreen(ByVal hWnd As IntPtr, ByRef lpPoint As Point) As Boolean
End Function
Dim mRect As Rectangle
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
mRect = New Rectangle(e.X, e.Y, 0, 0)
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim gp As New System.Drawing.Drawing2D.GraphicsPath
gp.AddRectangle(New Rectangle(0, 0, Me.Width, Me.Height))
mRect = New Rectangle(mRect.Left, mRect.Top, e.X - mRect.Left, e.Y - mRect.Top)
gp.AddRectangle(mRect)
Me.Region = New Region(gp)
Me.Invalidate()
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Using pen As New Pen(Color.Red, 3)
e.Graphics.DrawRectangle(pen, mRect)
End Using
End Sub
That produces the following: result