Solved

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

Posted on 2003-11-19
6
5,366 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:nvms
Comment Utility
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
Comment Utility
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
Comment Utility
look at this page:

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now