Solved

How to use Internet Explorer shortcut keys through VB.Net application

Posted on 2012-03-18
4
1,271 Views
Last Modified: 2012-03-19
Hi Experts,

I want to use internet explorer shortcut keys in my vb.net application. Basically I want to use CTRL+A, CTRL+C and CTRL+V for copy and paste purpose. I am using WebBrowser control in my vb form and have button and text box on it. What I want is when I press the button, It should select All the web content and copy the text in clipboard and paste it back on my textbox. I have tried sendkey with differently but nothing is workout.
Any help will be appreicated. Thanks

 I have used the follwoing code

        WebBrowser1.Focus()
        SendKeys.SendWait("^a")
        '  Threading.Thread.Sleep(1000)

        SendKeys.SendWait("^c")
        '   Threading.Thread.Sleep(1000)
        RichTextBox1.Focus()
        SendKeys.SendWait("^v")
0
Comment
Question by:khalidsuhail
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 37737271
If you are using the WebBrowser control, there are a wide variety of ways to extend and customize the control, which are usually pretty complicated.

Cut, Copy, and Paste operations, though are easy.

Web Browser in C#
http://www.codeproject.com/Articles/60179/Web-Browser-in-C

'cut
Private Sub cutToolStripMenuItem_Click(sender As Object, e As EventArgs)
	getCurrentBrowser().Document.ExecCommand("Cut", False, Nothing)

End Sub
'copy
Private Sub copyToolStripMenuItem_Click(sender As Object, e As EventArgs)
	getCurrentBrowser().Document.ExecCommand("Copy", False, Nothing)

End Sub
'paste
Private Sub pasteToolStripMenuItem_Click(sender As Object, e As EventArgs)
	getCurrentBrowser().Document.ExecCommand("Paste", False, Nothing)
End Sub
'select all
Private Sub selectAllToolStripMenuItem_Click(sender As Object, e As EventArgs)
	getCurrentBrowser().Document.ExecCommand("SelectAll", True, Nothing)
End Sub

Open in new window

0
 

Author Comment

by:khalidsuhail
ID: 37738438
Hi TheLearnedOne,
Thanks for reply.
I have modified your code little bit as follows. What I see the its copying the content but not pasting in my textbox automatically. If I press CTRL+V in my textbox I get the content copied in my textbox. Is there any workarround for it.


  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '        getCurrentBrowser().Document.ExecCommand("SelectAll", True, Nothing)
        WebBrowser1.Focus()
        WebBrowser1().Document.ExecCommand("SelectAll", True, Nothing)
        WebBrowser1().Document.ExecCommand("Copy", True, Nothing)
        RichTextBox1.Focus()

        WebBrowser1().Document.ExecCommand("Paste", True, Nothing)

    End Sub

Thanks for help
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37739109
The ExecCommand works on the WebBrowser control, so Copy would copy from the control, and Paste would paste to the control.  If you want to copy from the clipboard to the TextBox control, then you would need to use the TextBox.Paste method.
0
 

Author Comment

by:khalidsuhail
ID: 37740566
Thanks a lot. Its working

my coding is as follows.

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Focus()
        WebBrowser1().Document.ExecCommand("SelectAll", True, Nothing)
        WebBrowser1().Document.ExecCommand("Copy", True, Nothing)
        'RichTextBox1.Text = Clipboard.GetText
        Dim oFile As File
        Dim oWrite As System.IO.StreamWriter
        Dim fname As String = "Lab"
        Dim mPath As String = "C:\Temp\"
        Dim mExt As String = ".txt"
        Dim myLab As String = ""
        Dim mFile As String
        Dim mVer As Integer = 1
        mFile = mPath + fname + mVer.ToString + mExt

        For i As Integer = 1 To 10
            If oFile.Exists(mFile) Then
                mFile = mPath + fname + i.ToString + mExt
            Else
                Exit For
            End If


        Next

        oWrite = oFile.CreateText(mFile)
        '  oFile.OpenText()
        Dim data As IDataObject = Clipboard.GetDataObject()
        'If the data is text, then set the text of the
        'TextBox to the text in the Clipboard.
        If (data.GetDataPresent(DataFormats.Text)) Then
            myLab = data.GetData(DataFormats.Text).ToString()
            RichTextBox1.Text = data.GetData(DataFormats.Text).ToString()
        End If
        oWrite.Write(myLab)
        oWrite.Close()
        oWrite.Dispose()
        '        'The OpenText method opens an existing text file for reading and returns a System.IO.StreamReader object. With the StreamReader object, you can then read the file. Let’s see how to open a text file for reading:
        '        Dim oFile As System.IO.File
        '        Dim oRead As System.IO.StreamReader
        '        oRead = oFile.OpenText("C:\sample.txt")
        'Writing to a text file


    End Sub
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now