Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

javaSpy

Browsing frmEditDialog.vb (6.90 KB)

Option Explicit On

Imports Microsoft.Win32

Public Class frmEditDialog

    Private Const WM_CUT = &H300
    Private Const WM_COPY = &H301
    Private Const WM_PASTE = &H302

    Private _objEditDialog As clsEditDialog = Nothing

    Public Sub New(ByVal objEditDialog As clsEditDialog, _
        Optional ByVal caption As String = Nothing)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        _objEditDialog = objEditDialog

        If Not (caption Is Nothing) Then Me.Text = caption
        If objEditDialog.ReadOnly Then btnSave.Enabled = False

    End Sub

    Private Sub _updateInfo()

        Dim lineIndex As Integer = txtEdit.GetLineFromCharIndex(txtEdit.SelectionStart) + 1
        Dim colIndex As Integer = (txtEdit.SelectionStart - txtEdit.GetFirstCharIndexFromLine(lineIndex - 1)) + 1

        lblInfo.Text = "   Ln " + lineIndex.ToString + ", Col " + colIndex.ToString

    End Sub

    Private Sub customBtnHandler(ByVal sender As System.Object, ByVal e As EventArgs)

        _objEditDialog.CustomButtonClicked = True
        btnSave.PerformClick()

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        Me.Close()

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        _objEditDialog.OutputText = txtEdit.Text
        _objEditDialog = Nothing

        Me.Close()

    End Sub

    Private Sub frmEditDialog_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        If e.CloseReason = CloseReason.UserClosing And _
            Not (_objEditDialog Is Nothing) Then _
            _objEditDialog.Aborted = True

        If Me.WindowState = FormWindowState.Normal Then

            Dim regParent As RegistryKey = Registry.CurrentUser
            Dim regSubKey As RegistryKey = regParent.OpenSubKey("Software\javaSpy\", True)

            If regSubKey Is Nothing Then _
                regSubKey = regParent.CreateSubKey("Software\javaSpy\", RegistryKeyPermissionCheck.ReadWriteSubTree)

            If Not (regSubKey Is Nothing) Then

                regSubKey.SetValue("EditX1", Me.Left)
                regSubKey.SetValue("EditX2", Me.Left + Me.Width)
                regSubKey.SetValue("EditY1", Me.Top)
                regSubKey.SetValue("EditY2", Me.Top + Me.Height)

            End If

        End If

    End Sub

    Private Sub frmEditDialog_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim regParent As RegistryKey = Registry.CurrentUser
        Dim regSubKey As RegistryKey = regParent.OpenSubKey("Software\javaSpy\", False)

        If Not (regSubKey Is Nothing) Then

            Dim x1 As Object = regSubKey.GetValue("EditX1", Me.Left)
            Dim x2 As Object = regSubKey.GetValue("EditX2", Me.Left + Me.Width)
            Dim y1 As Object = regSubKey.GetValue("EditY1", Me.Top)
            Dim y2 As Object = regSubKey.GetValue("EditY2", Me.Top + Me.Height)

            Dim newCoords As New Rectangle()

            If Not (x1 Is Nothing) Then newCoords.X = x1
            If Not (x1 Is Nothing) And Not (x2 Is Nothing) Then newCoords.Width = Math.Abs(x2 - x1)
            If Not (y1 Is Nothing) Then newCoords.Y = y1
            If Not (y1 Is Nothing) And Not (y2 Is Nothing) Then newCoords.Height = Math.Abs(y2 - y1)

            If Screen.FromControl(Me.Owner).WorkingArea.Contains(newCoords) Then

                Me.Left = newCoords.X
                Me.Top = newCoords.Y
                Me.Width = newCoords.Width
                Me.Height = newCoords.Height

            End If

        End If

        txtEdit.Text = _objEditDialog.InputText
        txtEdit.SelectionStart = 0
        txtEdit.ClearUndo()

        If _objEditDialog.ReadOnly Then txtEdit.ReadOnly = True

        If Not (_objEditDialog.CustomButtonImage Is Nothing) Then

            Dim customBtn As New ToolStripButton("", _
                _objEditDialog.CustomButtonImage, AddressOf customBtnHandler)

            customBtn.ToolTipText = _objEditDialog.CustomButtonToolTip
            toolEdit.Items.Insert(0, customBtn)

        End If

    End Sub

    Private Sub frmEditDialog_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        _updateInfo()

    End Sub

    Private Sub txtEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEdit.Click

        _updateInfo()

    End Sub

    Private Sub txtEdit_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEdit.KeyUp

        _updateInfo()

        If e.KeyCode = Keys.F3 Then btnFind_Click(sender, Nothing)

    End Sub

    Private Sub txtEdit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEdit.TextChanged

        _updateInfo()

    End Sub

    Private Sub btnCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCut.Click

        If Not _objEditDialog.ReadOnly Then

            With New clsWindowObject(txtEdit.Handle)
                .SendMsg(WM_CUT, 0, 0)
            End With

        End If

    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click

        With New clsWindowObject(txtEdit.Handle)
            .SendMsg(WM_COPY, 0, 0)
        End With

    End Sub

    Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaste.Click

        If Not _objEditDialog.ReadOnly Then

            With New clsWindowObject(txtEdit.Handle)
                .SendMsg(WM_PASTE, 0, 0)
            End With

        End If

    End Sub

    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click

        Static lastFindText As String = ""
        Dim findText As String = ""

        If e Is Nothing And lastFindText <> "" Then
            findText = lastFindText
        Else
            findText = InputBox("Enter the text to find:", Application.ProductName, lastFindText)
        End If

        If findText <> "" Then

            Dim findIndex As Integer = txtEdit.Text.IndexOf(findText, txtEdit.SelectionStart + txtEdit.SelectionLength)

            If findIndex >= 0 Then

                txtEdit.SelectionStart = findIndex
                txtEdit.SelectionLength = findText.Length

            Else

                MessageBox.Show("Cannot find """ + findText + """", Application.ProductName, _
                    MessageBoxButtons.OK, MessageBoxIcon.Information)

            End If

        End If

        lastFindText = findText

    End Sub

End Class

Download frmEditDialog.vb

Back to file list


Back to project page