Rich-Text Paste : Clipboard « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » ClipboardScreenshots 
Rich-Text Paste




using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
   
class RichTextPaste: Form
{
     string   strPastedText = "";
     MenuItem miPastePlain, miPasteRTF, miPasteHTML, miPasteCSV;
   
     public static void Main()
     {
          Application.Run(new RichTextPaste());
     }
     public RichTextPaste()
     {
          ResizeRedraw = true;
   
          Menu = new MainMenu();
   
          MenuItem mi = new MenuItem("&Edit");
          mi.Popup += new EventHandler(MenuEditOnPopup);
          Menu.MenuItems.Add(mi);
   
          miPastePlain = new MenuItem("Paste &Plain Text");
          miPastePlain.Click += new EventHandler(MenuEditPastePlainOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPastePlain);
   
          miPasteRTF = new MenuItem("Paste &Rich Text Format");
          miPasteRTF.Click += new EventHandler(MenuEditPasteRTFOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteRTF);
   
          miPasteHTML = new MenuItem("Paste &HTML");
          miPasteHTML.Click += new EventHandler(MenuEditPasteHTMLOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteHTML);
   
          miPasteCSV = new MenuItem("Paste &Comma-Separated Values");
          miPasteCSV.Click += new EventHandler(MenuEditPasteCSVOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteCSV);
     }
     void MenuEditOnPopup(object obj, EventArgs ea)
     {
          miPastePlain.Enabled = Clipboard.GetDataObject().GetDataPresent(typeof(string));
          miPasteRTF.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Rtf);
          miPasteHTML.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Html);
          miPasteCSV.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.CommaSeparatedValue);
     }
     void MenuEditPastePlainOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(typeof(string)))
          {
               strPastedText = (stringdata.GetData(typeof(string));
               Invalidate();
          }
     }
     void MenuEditPasteRTFOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.Rtf))
          {
               strPastedText = (stringdata.GetData(DataFormats.Rtf);
               Invalidate();
          }
     }
     void MenuEditPasteHTMLOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.Html))
          {
               strPastedText = (stringdata.GetData(DataFormats.Html);
               Invalidate();
          }
     }
     void MenuEditPasteCSVOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.CommaSeparatedValue))
          {
               MemoryStream memstr = (MemoryStreamdata.GetData("Csv");
               StreamReader streamreader = new StreamReader(memstr);
               strPastedText = streamreader.ReadToEnd();
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          pea.Graphics.DrawString(strPastedText, Font, new SolidBrush(ForeColor),
                          ClientRectangle);
     }
}
           
       
Related examples in the same category
1.Copying to the Clipboard.
2.Copying from the Clipboard.
3.Clip Text
4.Image Clip
5.Clipboard Viewer (All Formats)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.