khalidsuhail
asked on
How to use Internet Explorer shortcut keys through VB.Net application
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(100 0)
SendKeys.SendWait("^c")
' Threading.Thread.Sleep(100 0)
RichTextBox1.Focus()
SendKeys.SendWait("^v")
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(100
SendKeys.SendWait("^c")
' Threading.Thread.Sleep(100
RichTextBox1.Focus()
SendKeys.SendWait("^v")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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.Exe cCommand(" SelectAll" , True, Nothing)
WebBrowser1().Document.Exe cCommand(" 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(DataF ormats.Tex t)) Then
myLab = data.GetData(DataFormats.T ext).ToStr ing()
RichTextBox1.Text = data.GetData(DataFormats.T ext).ToStr ing()
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
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.Exe
WebBrowser1().Document.Exe
'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(DataF
myLab = data.GetData(DataFormats.T
RichTextBox1.Text = data.GetData(DataFormats.T
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.
'Writing to a text file
End Sub
ASKER
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().Docume
WebBrowser1.Focus()
WebBrowser1().Document.Exe
WebBrowser1().Document.Exe
RichTextBox1.Focus()
WebBrowser1().Document.Exe
End Sub
Thanks for help