PC Review


Reply
Thread Tools Rate Thread

Copying to the clipboard

 
 
Jeff
Guest
Posts: n/a
 
      14th Jan 2007

....working with visualweb.net 2005 and vb.

....trying to simply copy the contents from a textbox to the clipboard.

I've looked at a large number of places on line and they give me various
code, but it doesn't work. I'm apparently missing some type of declaration,
and the code is diffent in visualweb.net than elsewhere.
When I try the code below, it tells me that the "name clipboard is not
declared"

What am I missing?

Thanks

Jeff


Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnCopy.Click
Clipboard.SetDataObject(TextBox1.Text)
End Sub



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      14th Jan 2007
If it isn't recognizing the name Clipboard, then you haven't got the
namespace that contains the Clipboard class imported.


"Jeff" <(E-Mail Removed)> wrote in message
news:45aa7550$0$4845$(E-Mail Removed)...
>
> ...working with visualweb.net 2005 and vb.
>
> ...trying to simply copy the contents from a textbox to the clipboard.
>
> I've looked at a large number of places on line and they give me various
> code, but it doesn't work. I'm apparently missing some type of
> declaration, and the code is diffent in visualweb.net than elsewhere.
> When I try the code below, it tells me that the "name clipboard is not
> declared"
>
> What am I missing?
>
> Thanks
>
> Jeff
>
>
> Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles BtnCopy.Click
> Clipboard.SetDataObject(TextBox1.Text)
> End Sub
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      14th Jan 2007

"Scott M." <s-(E-Mail Removed)> wrote in message
news:eUSd$(E-Mail Removed)...
> If it isn't recognizing the name Clipboard, then you haven't got the
> namespace that contains the Clipboard class imported.


Thanks, but I'm still new at this. Could you please explain how to do that?

Jeff


--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Newbie Coder
Guest
Posts: n/a
 
      15th Jan 2007
Jeff,

See if you have a reference to the 'System.Windows.Forms' class for a start

Then you can use your code as normal to copy to the clipboard

If you then want to paste the clipboard data then use this code:

Dim iData As IDataObject = Clipboard.GetDataObject()
TextBox1.Text = CType(iData.GetData(DataFormats.Text), String)

I used TextBox1 to hold the pasted text

I hope this helps,

Newbie Coder


 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      15th Jan 2007
Hi Jeff,

To use the clipboard in a windows form app, you have to reference to the
System.Windows.Forms assembly. By default, when you create the project, it
was automatically added. If it isn't there, you can add it using Add
Referece.

Then all you need to do is to use SetDataObject method. If you didn't
import the namespace, you just need to add namespace before the class name,
like the following.

Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnCopy.Click
System.Windows.Forms.Clipboard.SetDataObject(TextBox1.Text)
End Sub

By the way, this can only be used in a windows form app. For web app, doing
clipboard operations at client side involves scripting.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      15th Jan 2007

"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> By the way, this can only be used in a windows form app. For web app,
> doing
> clipboard operations at client side involves scripting.
>
> Kevin Yu
> Microsoft Online Community Support



Okay, this must be the problem. I found similar instructions to what you and
the other poster provided, but I am attempting this on a web app.

Is there an easy way get the text from a dot.net text box in a web app into
the clipboard using javascript or similar script after clicking a dot.net or
html button?

Jeff



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      15th Jan 2007
Hi Jeff,

On the webpage, you have to achieve this with client side scripts. Here are
many examples for your refrence. If anything is unclear, please feel free
to let me know.

http://www.microsoft.com/technet/scr.../aug04/hey0813.
mspx

http://www.htmlgoodies.com/beyond/ja...le.php/3458851

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      15th Jan 2007
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

function ClipboardSend()
{
clipboardData.setData("text",txtTest.value)
}

</SCRIPT>
</HEAD>
<BODY>

<Input type="text" ID="txtTest">
<Input type="button" onClick="ClipboardSend()" Value="Copy To Clipboard">

</BODY>
<HTML>


"Jeff" <(E-Mail Removed)> wrote in message
news:45aaecaa$0$4801$(E-Mail Removed)...
>
> "Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> By the way, this can only be used in a windows form app. For web app,
>> doing
>> clipboard operations at client side involves scripting.
>>
>> Kevin Yu
>> Microsoft Online Community Support

>
>
> Okay, this must be the problem. I found similar instructions to what you
> and the other poster provided, but I am attempting this on a web app.
>
> Is there an easy way get the text from a dot.net text box in a web app
> into the clipboard using javascript or similar script after clicking a
> dot.net or html button?
>
> Jeff
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      15th Jan 2007

"Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
newsMy%(E-Mail Removed)...

> On the webpage, you have to achieve this with client side scripts. Here
> are
> many examples for your refrence. If anything is unclear, please feel free
> to let me know.
>
> http://www.microsoft.com/technet/scr.../aug04/hey0813.
> mspx
>
> http://www.htmlgoodies.com/beyond/ja...le.php/3458851
>
> Kevin Yu


I get the general idea, but I'm new to VB and even newer to scripting so I'm
missing one or two details.
The first page you pointed to above looks promising for my application. What
I'm doing is having the application produce text that is visible in a
textbox - that part's okay. I would then like the user to be able to click a
button and have that text copied to the clipboard. I tried the code below
that is similar to what was suggested on the first page. I get no warnings
during development, but when I attempt to run it, the client side browser
produces an error that the active-X component could not be created (IE7 on
vista rc1 - I haven't tested elsewhere).

What might I be still missing?
Jeff

Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnCopy.Click
Dim objIE
Dim strCopy As String

strCopy = "This text has been copied to the clipboard."

objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData("text", strCopy)
objIE.Quit()

End Sub



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      15th Jan 2007
I wouldn't try to solve this with server-side VB.NET code. As pointed out,
the clipboard is a client-side object and so the best place to put your code
is on the client (JavaScript).

Simply add the following JavaScript function to your HTML (in the <HEAD>
section):

<SCRIPT LANGUAGE="JavaScript">

function ClipboardSend()
{
clipboardData.setData("text",txtTest.value)
}

</SCRIPT>


Then, further down in your HTML (probably right after the code for your
textbox), add the following code to create the client-side button that takes
the text from your textbox and puts it on the clipboard:

<Input type="button" onClick="ClipboardSend()" Value="Copy To Clipboard">

That should do it.

Good luck,

-Scott


"Jeff" <(E-Mail Removed)> wrote in message
news:45abaaa1$0$4881$(E-Mail Removed)...
>
> "Kevin Yu [MSFT]" <v-(E-Mail Removed)> wrote in message
> newsMy%(E-Mail Removed)...
>
>> On the webpage, you have to achieve this with client side scripts. Here
>> are
>> many examples for your refrence. If anything is unclear, please feel free
>> to let me know.
>>
>> http://www.microsoft.com/technet/scr.../aug04/hey0813.
>> mspx
>>
>> http://www.htmlgoodies.com/beyond/ja...le.php/3458851
>>
>> Kevin Yu

>
> I get the general idea, but I'm new to VB and even newer to scripting so
> I'm missing one or two details.
> The first page you pointed to above looks promising for my application.
> What I'm doing is having the application produce text that is visible in a
> textbox - that part's okay. I would then like the user to be able to click
> a button and have that text copied to the clipboard. I tried the code
> below that is similar to what was suggested on the first page. I get no
> warnings during development, but when I attempt to run it, the client side
> browser produces an error that the active-X component could not be created
> (IE7 on vista rc1 - I haven't tested elsewhere).
>
> What might I be still missing?
> Jeff
>
> Protected Sub BtnCopy_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles BtnCopy.Click
> Dim objIE
> Dim strCopy As String
>
> strCopy = "This text has been copied to the clipboard."
>
> objIE = CreateObject("InternetExplorer.Application")
> objIE.Navigate("about:blank")
> objIE.document.parentwindow.clipboardData.SetData("text", strCopy)
> objIE.Quit()
>
> End Sub
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
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 not copying computerchallengedcc Windows XP General 2 20th Oct 2008 03:51 AM
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Microsoft Outlook 0 24th Aug 2006 03:44 PM
Copying to clipboard using Ctrl-C or Clipboard.SetText =?Utf-8?B?S2V2aW4gQnVydG9u?= Microsoft Dot NET Framework 0 28th Jul 2006 02:13 AM
Copying the filtered data to clipboard is copying non-visible rows =?Utf-8?B?U2VldGhhUmFtYW4=?= Microsoft Excel Crashes 10 12th Jul 2006 10:39 PM
Copying to clipboard Arun Microsoft C# .NET 3 17th Mar 2006 11:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 PM.