Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

capture selected or highlighted text in c#.net windows application

Posted on 2009-05-19
5
1,816 Views
Last Modified: 2013-12-17
Hi,
i am developing windows application in c#.net.
I need to be able to copy the text from any application or document where text can be highlighted or selected(.txt, .doc, .pdf, html, .chm, .hlp, ppt, xls).

I think it is possible. but how it is possible?

appreciate any help.
Thanks in advance
0
Comment
Question by:nissiinfotechpvtltd
  • 3
5 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24421375
You mean, I think, you need to be able to paste the text, is that correct? You can do so by using the clipboard functions:

// get text from clipboard, which a user copied in another app
string clipBoardText = "";
if(Clipboard.ContainsText())
    clipBoardText = Clipboard.GetText();

Open in new window

0
 

Author Comment

by:nissiinfotechpvtltd
ID: 24430961
Hi,
i am developing windows application in c#.net.
how to capture selected or hightlighted text from other applications such as pdf, chm,hlp etc..
It is possible. there are many softwares to do it.
how to do it?

pls help me
0
 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24431121
I believe I just explained that. Or I don't understand you correctly. If you want to do the copy from your application, you can use a SendKeys("^{C}"), which will send the Ctrl-C (copy) to the other application, if it has the focus.

Other methods may exist, but they can become extremely complex, as it highly depends on what kind of application, what kind of windows / edit classes (window-classes, not object-classes) they use and whether they are accessible from another thread. If the behave neatly, you can try sending messages to the window that is a textbox, the easy thing would be to use a WM_COPY message, but that may not be enough. If SendKeys does not work, you can use this post: http://bytes.com/groups/net-c/255335-get-selected-text-other-process (see below). It will work on the majority of cases, but not all.
0
 
LVL 39

Expert Comment

by:abel
ID: 25218425
Use want to copy text by sending keys. First answer shows how to do it without, second shows how to do it with and gives other methods as well. Suggestion: points split between http:24431121 and http:24421375
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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