2019-10-15 16:16:50 +02:00

133 lines
4.5 KiB
VB.net

Imports DigitalData.Modules.Windows
Imports DigitalData.Modules.Windows.Window
Public Class frmControlCapture
Public Property TopLeft As RectangleInfo
Public Property TopRight As RectangleInfo
Public Property BottomLeft As RectangleInfo
Public Property BottomRight As RectangleInfo
Public Property ControlName As String
Public Property ControlBounds As String
Private WithEvents Watcher As ClipboardWatcher = ClipboardWatcher.Singleton
Private Window As Window
Private EditMode As Boolean = False
Public Sub New(EditMode As Boolean, Optional ControlBounds As String = "", Optional ControlName As String = "")
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
Me.EditMode = EditMode
Me.ControlName = ControlName
Me.ControlBounds = ControlBounds
End Sub
Private Sub frmControlCapture_Load(sender As Object, e As EventArgs) Handles Me.Load
Window = New Window(LogConfig)
rbControlName.Checked = True
If ControlName <> String.Empty Then
rbControlName.Checked = True
txtControlName.Text = ControlName
End If
If ControlBounds <> String.Empty Then
rbControlPosition.Checked = True
txtControlBounds.Text = ControlBounds
End If
AddHandler Watcher.Changed, AddressOf Watcher_Changed
End Sub
Private Sub Watcher_Changed(sender As Object, e As EventArgs)
' === CONTROL NAME ===
Dim oControl As WindowInfo = Window.GetFocusedControl(Handle)
If oControl IsNot Nothing Then
txtControlName.Text = oControl.ControlName
ControlName = oControl.ControlName
End If
' === CONTROL POSITION ===
For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor))
Dim oRect As RectangleInfo = Window.GetFocusedControlLocation(Handle, oAnchor)
Select Case oAnchor
Case Window.Anchor.TopLeft
If oRect IsNot Nothing Then
TopLeft = oRect
End If
Case Window.Anchor.TopRight
If oRect IsNot Nothing Then
TopRight = oRect
End If
Case Window.Anchor.BottomLeft
If oRect IsNot Nothing Then
BottomLeft = oRect
End If
Case Window.Anchor.BottomRight
If oRect IsNot Nothing Then
BottomRight = oRect
End If
End Select
txtControlBounds.Text = GetBoundsString(TopLeft, TopRight, BottomLeft, BottomRight)
Next
End Sub
Public Shared Function GetBoundsString(TopLeft As RectangleInfo, TopRight As RectangleInfo, BottomLeft As RectangleInfo, BottomRight As RectangleInfo)
Dim oResult As String = String.Empty
If TopLeft IsNot Nothing Then
oResult &= TopLeft.ToString & vbNewLine
End If
If TopRight IsNot Nothing Then
oResult &= TopRight.ToString & vbNewLine
End If
If BottomLeft IsNot Nothing Then
oResult &= BottomLeft.ToString & vbNewLine
End If
If BottomRight IsNot Nothing Then
oResult &= BottomRight.ToString & vbNewLine
End If
Return oResult
End Function
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles rbControlName.CheckedChanged
gbControlName.Enabled = rbControlName.Checked
gbControlPosition.Enabled = Not rbControlName.Checked
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles rbControlPosition.CheckedChanged
gbControlName.Enabled = Not rbControlPosition.Checked
gbControlPosition.Enabled = rbControlPosition.Checked
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtControlName.Text = String.Empty And txtControlBounds.Text = String.Empty Then
MsgBox("Kein Control gefunden!")
DialogResult = DialogResult.Cancel
End If
If rbControlPosition.Checked Then
ControlName = String.Empty
ElseIf rbControlName.Checked Then
TopLeft = New RectangleInfo()
TopRight = New RectangleInfo()
BottomLeft = New RectangleInfo()
BottomRight = New RectangleInfo()
End If
End Sub
End Class