Hi dennist,
The .NET framework didn't provide such method, so you must use the
Platform Invoke to do this,
the API you need is OpenClipboard, EmptyClipboard and CloseClipboard,
you may declare these functions like,
Public Declare Function OpenClipboard Lib "user32" Alias "OpenClipboard"
(ByVal hwnd As Long) As Long
for more usage information, you may refer to the MSDN page
ms-help://MS.MSDNQTR.2003FEB.1033/winui/winui/windowsuserinterface/dataexcha
nge/
clipboard/clipboardreference/clipboardfunctions/openclipboard.htm
thanks, if you still have problem, please let me know.
Kind regards,
Ying-Shen Yu [MS]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "dennist" <(E-Mail Removed)>
| Sender: "dennist" <(E-Mail Removed)>
| Subject: can't clear clipboard
| Date: Tue, 2 Sep 2003 19:28:06 -0700
| Lines: 65
| Message-ID: <003401c371c3$02168ea0$(E-Mail Removed)>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNxwwIW3y2/YXyJSY6/VsEsLgLmfQ==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51520
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I'm opening up a file and putting it's contents into a
| textbox. I want to clear the clipboard before setting the
| focus to the textbox, but apparently there's no such
| animal in vb.net.
|
| Private Sub btnOpenFile_Click(ByVal sender As
| System.Object, ByVal e As System.EventArgs) Handles
| btnOpenFile.Click
|
| Dim StreamR1 As System.IO.StreamReader
| OFD1.Filter = ("text files(*.txt)|*.txt|(Word
| files(*.doc)|*.doc")
| OFD1.ShowDialog()
| If OFD1.FileName <> "" Then
| Try 'open file and trap any erros using
| handler
| StreamR1 = New StreamReader(OFD1.FileName)
| txtTextGeneral.Text = StreamR1.ReadToEnd
| StreamR1.Close()
| txtTextGeneral.Select(0, 0)
| Catch
| MsgBox("Error opening file." & vbCr
| & "Perhaps bad file name", , "Error!")
| Finally
| txtTextGeneral.Focus()
| 'MsgBox(txtTextGeneral.SelectedText)
| End Try
| End If
| End Sub
|
| don't mind my debugging message box.
|
| Then, when I leave or lose focus of the text box, I want
| to set the clipboard to whatever text is selected in the
| textbox. There's lot's of funny debugging statements,
| please don't laugh too loudly.
|
| Private Sub txtTextGeneral_LostFocus(ByVal sender As
| Object, ByVal e As System.EventArgs) Handles
| txtTextGeneral.LostFocus
|
| '' Takes the selected text from a text box and
| puts it on the clipboard.
| 'txtTopicTitle.Text = "Leave" 'see leave
| 'MsgBox("Leave")
| 'If txtTextGeneral.SelectedText <> "" Then
| ' Clipboard.SetDataObject
| (txtTextGeneral.SelectedText, True)
| 'Else
| ' MsgBox("No text selected", , "Warning")
| ' txtTitle.Text = ""
| 'End If
|
| End Sub
|
| what I find is that if I click on a control that can
| accept text, I get a 'leave' in the topictext box.
| Otherwise, nothing happens. No messagebox, no leave, no
| nothing. Why can't I do something in vb.net that's as
| simple as pie in vb6. Why can't I clear the clipboard.
|
| In the end, everything works out - I think. I'm sure a
| user will find differently.
|
| dennist
|
|