Codegod - The page for .NET-developers
Winforms Grid TreeList Control .NET 2.0/3.5

Get ClipBoard Text with .NET (C#)
Section: SystemRating: Not rated yet!

Add to YiGGAdd to google-bookmarksAdd to linkarenaAdd to redditAdd to del.icio.usAdd to misterwongAdd to digg




Introduction

This helper-class can be used to get the text in the ClipBoard. It return an empty string if no text can be found.

using System; using System.Text; using System.Windows.Forms; namespace System { public class ClipBoardHelper { /// <summary> /// Get Text in ClipBoard /// </summary> /// <returns>text in ClipBoard, /// empty String if no text is in it</returns> /// <example> /// string text = ClipBoardHelper.GetText(); /// </example> public static string GetText() { IDataObject dataObj = Clipboard.GetDataObject(); if( !dataObj.GetDataPresent(DataFormats.Text) ) return ""; return dataObj.GetData(DataFormats.Text).ToString(); } } }




 Reader-Comments: