namespace Clipz { using System.Drawing; using System.Windows; public class TextClipboardItem : ClipboardItem { protected string _formattedString; public string OriginalString { get; set; } public override Bitmap Thumbnail { get { return CreateImage(false); } } public override void Copy() { Clipboard.SetText(OriginalString); } protected Bitmap CreateImage(bool richText) { var bitmap = new Bitmap(150, 150); using(var graphics = Graphics.FromImage(bitmap)) { graphics.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 150, 150)); var textHost = new RichTextHost { Width = 150, Height = 150 }; if (richText) { textHost.Rtf = OriginalString; } else { textHost.Text = OriginalString; } _formattedString = textHost.Text; textHost.Print(0, OriginalString.Length, graphics, new Rectangle(0, 0, 150, 150)); } return bitmap; } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Skills that self-taught computer programmers lack