剪贴板应用程序

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7
  8namespace ClipBoard
  9{
 10    /// <summary>
 11    /// 剪贴板应用程序。
 12    /// </summary>

 13    public class Form1 : System.Windows.Forms.Form
 14    {
 15        private System.Windows.Forms.Button button1;
 16        private System.Windows.Forms.Button button2;
 17        private System.Windows.Forms.RichTextBox richTextBox1;
 18        /// <summary>
 19        /// 必需的设计器变量。
 20        /// </summary>

 21        private System.ComponentModel.Container components = null;
 22
 23        public Form1()
 24        {
 25            //
 26            // Windows 窗体设计器支持所必需的
 27            //
 28            InitializeComponent();
 29
 30            //
 31            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 32            //
 33        }

 34
 35        /// <summary>
 36        /// 清理所有正在使用的资源。
 37        /// </summary>

 38        protected override void Dispose( bool disposing )
 39        {
 40            if( disposing )
 41            {
 42                if (components != null
 43                {
 44                    components.Dispose();
 45                }

 46            }

 47            base.Dispose( disposing );
 48        }

 49
 50        Windows Form Designer generated code
109
110        /// <summary>
111        /// 应用程序的主入口点。
112        /// </summary>

113        [STAThread]
114        static void Main() 
115        {
116            Application.Run(new Form1());
117        }

118        // 查看剪贴板内容。
119        private void button1_Click(object sender, System.EventArgs e)
120        {
121            IDataObject iData = Clipboard.GetDataObject();
122            if(iData.GetDataPresent(DataFormats.Text)) 
123            {
124                // 格式正确,写入文本框中显示。.
125                richTextBox1.Text = (String)iData.GetData(DataFormats.Text); 
126            }

127            else 
128            {
129                // 数据格式不正确。
130                MessageBox.Show("剪贴板数据格式不正确。");
131            }

132        }

133        // 粘贴内容到剪贴板。
134        private void button2_Click(object sender, System.EventArgs e)
135        {
136            if(richTextBox1.Text.Length != 0)
137            {
138                Clipboard.SetDataObject(richTextBox1.Text, false);
139            }

140        }

141    }

142}

143
posted on 2007-08-23 13:51  Gofficer  阅读(308)  评论(0编辑  收藏  举报