Clip Text : 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 
Clip Text




using System;
using System.Drawing;
using System.Windows.Forms;
   
class ClipText: Form
{
     string   strText = "Sample text";
     MenuItem miCut, miCopy, miPaste;
   
     public static void Main()
     {
          Application.Run(new ClipText());
     }
     public ClipText()
     {
          ResizeRedraw = true;
   
          Menu = new MainMenu();
          MenuItem mi = new MenuItem("&Edit");
          mi.Popup += new EventHandler(MenuEditOnPopup);
          Menu.MenuItems.Add(mi);
          miCut = new MenuItem("Cu&t");
          miCut.Click += new EventHandler(MenuEditCutOnClick);
          miCut.Shortcut = Shortcut.CtrlX;
          Menu.MenuItems[0].MenuItems.Add(miCut);
   
          miCopy = new MenuItem("&Copy");
          miCopy.Click += new EventHandler(MenuEditCopyOnClick);
          miCopy.Shortcut = Shortcut.CtrlC;
          Menu.MenuItems[0].MenuItems.Add(miCopy);
   
          miPaste = new MenuItem("&Paste");
          miPaste.Click += new EventHandler(MenuEditPasteOnClick);
          miPaste.Shortcut = Shortcut.CtrlV;
          Menu.MenuItems[0].MenuItems.Add(miPaste);
     }
     void MenuEditOnPopup(object obj, EventArgs ea)
     {
          miCut.Enabled = miCopy.Enabled = strText.Length > 0;
          miPaste.Enabled = Clipboard.GetDataObject().GetDataPresent(typeof(string));
     }
     void MenuEditCutOnClick(object obj, EventArgs ea)
     {
          MenuEditCopyOnClick(obj, ea);
          strText = "";
          Invalidate();
     }
     void MenuEditCopyOnClick(object obj, EventArgs ea)
     {
          Clipboard.SetDataObject(strText, true);
     }
     void MenuEditPasteOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(typeof(string)))
               strText = (stringdata.GetData(typeof(string));
   
          Invalidate();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
          StringFormat strfmt = new StringFormat();
          strfmt.Alignment = strfmt.LineAlignment = StringAlignment.Center;
   
          grfx.DrawString(strText, Font, new SolidBrush(ForeColor),
                          ClientRectangle, strfmt);
     }
}

           
       
Related examples in the same category
1.Copying to the Clipboard.
2.Copying from the Clipboard.
3.Image Clip
4.Rich-Text Paste
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.