PC Review


Reply
Thread Tools Rate Thread

can't clear clipboard

 
 
dennist
Guest
Posts: n/a
 
      3rd Sep 2003
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
 
Reply With Quote
 
 
 
 
Ying-Shen Yu[MS]
Guest
Posts: n/a
 
      3rd Sep 2003
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
|

 
Reply With Quote
 
dennist
Guest
Posts: n/a
 
      4th Sep 2003
I can see by your answer that I can solve the clear
clipboard problem, although it is certainly more
difficult than in visual basic 6. In some regards I
think MS took a wrong turn in vb.net. They were catering
to the elite programmers and not the average vb
programmer. Easy things become complicated.

However your answer didn't indicate my problem with
leaving or losingfocus of the textbox. It seems to me no
matter what I click outside the textbox should
create "leave" in the txtTopicTitle control. Don't tell
me we've lost something so fundamental and simple and
that, as well?

dennist
 
Reply With Quote
 
100
Guest
Posts: n/a
 
      4th Sep 2003
Hi dennist,
> 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.

What do you mean *control that can accept focus*?
If you click on any control that can get the input focus the textbox will
receive LostFocus event.
If you click on a control like panel, which obviously cannot be focused the
text boxt won't lose the focus and won't get the LostFocus event.

B\rgds
100


 
Reply With Quote
 
dennist
Guest
Posts: n/a
 
      5th Sep 2003
oops. If I click text boxes or comboboxes, which can
certainly accept focus, the leave or lostfocus events of
the txttextgeneral do not fire.

dennist
>-----Original Message-----
>Hi dennist,
>> 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.

>What do you mean *control that can accept focus*?
>If you click on any control that can get the input focus

the textbox will
>receive LostFocus event.
>If you click on a control like panel, which obviously

cannot be focused the
>text boxt won't lose the focus and won't get the

LostFocus event.
>
>B\rgds
>100
>
>
>.
>

 
Reply With Quote
 
Ying-Shen Yu[MS]
Guest
Posts: n/a
 
      5th Sep 2003
Hi Dennis,
Clicking on controls that can receive focus should change the focus to it,
It's strange that the event handlers don't fire, I think there might be
somthing wrong in your code. Have you tried this it a new VB Application
Project? Just Add a TextBox and a Button on it, then handle the GotFocus
and LostFocus event of the TextBox, and set the different values to the
TextProperty, then run it for test.
If the LostFocus event still not fired ,please sent that project to me.
Thanks!


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)>
| References: <003401c371c3$02168ea0$(E-Mail Removed)>
<#gPm7#(E-Mail Removed)>
| Subject: Re: can't clear clipboard
| Date: Thu, 4 Sep 2003 23:32:26 -0700
| Lines: 27
| Message-ID: <284501c37377$793d2a60$(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: AcNzd3k98uXnImREQ6+ynz6PLyK+/w==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51691
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| oops. If I click text boxes or comboboxes, which can
| certainly accept focus, the leave or lostfocus events of
| the txttextgeneral do not fire.
|
| dennist
| >-----Original Message-----
| >Hi dennist,
| >> 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.
| >What do you mean *control that can accept focus*?
| >If you click on any control that can get the input focus
| the textbox will
| >receive LostFocus event.
| >If you click on a control like panel, which obviously
| cannot be focused the
| >text boxt won't lose the focus and won't get the
| LostFocus event.
| >
| >B\rgds
| >100
| >
| >
| >.
| >
|

 
Reply With Quote
 
100
Guest
Posts: n/a
 
      5th Sep 2003
Hi dennist,
I tried your code and everything works just fine. It looks like the problems
is somewhere else. If you can post a working code which, demostrates the
problem we might be able help you better.

B\rgds
100
"dennist" <(E-Mail Removed)> wrote in message
news:284501c37377$793d2a60$(E-Mail Removed)...
> oops. If I click text boxes or comboboxes, which can
> certainly accept focus, the leave or lostfocus events of
> the txttextgeneral do not fire.
>
> dennist
> >-----Original Message-----
> >Hi dennist,
> >> 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.

> >What do you mean *control that can accept focus*?
> >If you click on any control that can get the input focus

> the textbox will
> >receive LostFocus event.
> >If you click on a control like panel, which obviously

> cannot be focused the
> >text boxt won't lose the focus and won't get the

> LostFocus event.
> >
> >B\rgds
> >100
> >
> >
> >.
> >



 
Reply With Quote
 
dennist
Guest
Posts: n/a
 
      8th Sep 2003
I've fixed this as well as I'm going to. I just hope in
the next version of vb.net they return clipboard.clear
and a more robust lostfocus event to us. It'll do for
now.

Thank you both for your work and suggestions.

dennist

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clipboard won't clear joefox Microsoft Outlook Discussion 0 9th Apr 2010 03:52 PM
How do I clear the clipboard? Radycal Microsoft Access 8 8th Sep 2009 08:11 PM
Clear Clipboard =?Utf-8?B?QmVhY2h5bW9t?= Windows XP Basics 5 24th Nov 2007 06:05 PM
I am asked to clear clipboard,yet there is no data to clear-help! =?Utf-8?B?UEogTycgTGVhcnk=?= Microsoft Excel Crashes 1 15th Apr 2006 12:30 PM
cannot clear clipboard when clipboard appears empty =?Utf-8?B?U2hhbmk=?= Microsoft Excel Misc 1 4th Nov 2004 02:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:00 PM.