Solved

TextBox.Copy() to Clipboard in C# Compact Framework ?

Posted on 2003-11-19
6
5,374 Views
Last Modified: 2012-08-13
Hi

I am finding more and more aspects of the .NET Compact Framework lacking the full framework. From what I can see I cannot copy text selections to the clipboard ? Does anyone know if this is just a "wait for Service Pack 2" issue or if I am not Using xxxx; the right resources.

Thanks

Stu
0
Comment
Question by:nvms
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:DaniPro
ID: 9777470
You can use the Clipboard class:

private void button1_Click(object sender, System.EventArgs e) {
    // Takes the selected text from a text box and puts it on the clipboard.
    if(textBox1.SelectedText != "")
       Clipboard.SetDataObject(textBox1.SelectedText, true);
    else
       textBox2.Text = "No text selected in textBox1";
 }
0
 

Author Comment

by:nvms
ID: 9784490
Hi thanks for the comments, this of course works fine in a Windows project but in a Mobile Device project (using the Compact .NET Framework) the following error is generated on deployment:

C:\Documents and Settings\My Documents\Files\CODE\C#.NET Examples\Clipboard Handling\Copy\Form1.cs(93): The type or namespace name 'Clipboard' could not be found (are you missing a using directive or an assembly reference?)

Code is OK from your example with the following references:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;

My problem remains, the CF does not support the clipboard
0
 
LVL 6

Accepted Solution

by:
DaniPro earned 50 total points
ID: 9785315
You have right !!!! Then try this code:

public void CopyAllMyText()
 {
    // Determine if any text is selected in the TextBox control.
    if(textBox1.SelectionLength == 0)
       // Select all text in the text box.
       textBox1.SelectAll();
   
    // Copy the contents of the control to the Clipboard.
    textBox1.Copy();
 }
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:nvms
ID: 9785835
Already tried as have all the other standard clipboard commands, retults in:

C:\Documents and Settings\Files\CODE\C#.NET Examples\Clipboard Handling\Copy\Form1.cs(98): 'System.Windows.Forms.TextBox' does not contain a definition for 'Copy'

If you start a new .NET project and choose a Smart Device Application using the Emulator you will see the problem
0
 

Author Comment

by:nvms
ID: 10079190
Please note THERE IS NO SOLUTION ON THIS PAGE !!! I have awarded the points as thanks for contributing but as you know having found this, the .NET Compact Framework is rather 'cut-down'. The functions suggested will not work. Open to further discussion on this topic.
0
 
LVL 2

Expert Comment

by:krikkit
ID: 10396948
look at this page:

http://www.opennetcf.org/forms.asp  this is an open source libary which provides the needed feature
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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