Found this old thread because I had to do something similar. I modified Megatron's code a bit to make the focus rectangle appear in all 4 quadrants. So no matter where you drag the mouse you will always have your focus rectangle on the screen. Enjoy.
Code:Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim FocusRect As RECT Dim LeftStart As Long Dim TopStart As Long Private Sub Form_Load() Me.ScaleMode = 3 Me.AutoRedraw = True End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Set the starting points If Button = 1 Then FocusRect.Left = X FocusRect.Top = Y LeftStart = X TopStart = Y End If End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Draw the Focus Rectangle If Button = 1 Then Cls If X < LeftStart And Y > TopStart Then 'Q3 FocusRect.Right = LeftStart FocusRect.Left = X FocusRect.Bottom = Y FocusRect.Top = TopStart ElseIf X > LeftStart And Y < TopStart Then 'Q2 FocusRect.Right = X FocusRect.Left = LeftStart FocusRect.Bottom = TopStart FocusRect.Top = Y ElseIf X < LeftStart And Y < TopStart Then 'Q1 FocusRect.Right = LeftStart FocusRect.Left = X FocusRect.Bottom = TopStart FocusRect.Top = Y Else 'Q4 X < LeftStart and Y > TopStart FocusRect.Right = X FocusRect.Left = LeftStart FocusRect.Bottom = Y FocusRect.Top = TopStart End If DrawFocusRect Me.hdc, FocusRect End If End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Clear the Screen Cls End Sub




Reply With Quote