dcsimg
Results 1 to 4 of 4

Thread: How can I do this?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    How can I do this?

    1.

    2.

    Thank a lot.

  2. #2
    Lively Member
    Join Date
    Aug 2007
    Posts
    66

    Re: How can I do this?

    It would be easier to read the info in notepad from a text file if you have it. If you don't then try this. I can't guarantee this will always work though.

    You will need 2 buttons a textbox and a listbox for this to work. Oh and a open notepad window of course
    Code:
    Public Class Form1
        Private Declare Auto Function FindWindow Lib "user32" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        Private Declare Auto Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim NotepadWindow As IntPtr = FindWindow("Notepad", Nothing) 'get handle to a notepad window
            Dim ClipboardList As New List(Of String) 'List of string to store the clipboard contents
            If NotepadWindow.ToInt32 > 0 Then 'Make sure you found a notepad window
                SetForegroundWindow(NotepadWindow) 'Bring the notepad window to the foreground
                SendKeys.SendWait("^a") 'Send CTRL + a to select all text
                SendKeys.SendWait("^c") 'Send CTRL + c to copy text to clipboard
                ClipboardList.AddRange(My.Computer.Clipboard.GetText(TextDataFormat.Text).Split(Environment.NewLine)) 'Copy the clipboard contents to the list
                For Each item As String In ClipboardList 'Loop thru the list
                    ListBox1.Items.Add(item.Trim) 'Add each item to a listbox and trim off empty characters
                Next
                SetForegroundWindow(Me.Handle) 'Set your program back to the foreground
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If ListBox1.SelectedItems.Count > 0 Then 'Check that a listbox item is selected
                TextBox1.Text = ListBox1.SelectedItems(0) 'Copy the selected items text to textbox'
                'If you want the copied text to actually be in the clipbaord for pasting somewhere eles then use this
                'My.Computer.Clipboard.SetText(ListBox1.SelectedItems(0).ToString, TextDataFormat.Text)
                'Then you can paste into the textbox
            End If
        End Sub
    End Class

  3. #3
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: How can I do this?

    The second one has already been answered. Please don't double post.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How can I do this?

    oh... I see^^
    (Sorry, I forgot the "Read TXT" in the second one..)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width