剪贴板应用程序

  1 using  System;
  2 using  System.Drawing;
  3 using  System.Collections;
  4 using  System.ComponentModel;
  5 using  System.Windows.Forms;
  6 using  System.Data;
  7
  8 namespace  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#region Windows Form Designer generated code
 51        /**//// <summary>
 52        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 53        /// 此方法的内容。
 54        /// </summary>

 55        private void InitializeComponent()
 56        {
 57            this.button1 = new System.Windows.Forms.Button();
 58            this.button2 = new System.Windows.Forms.Button();
 59            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
 60            this.SuspendLayout();
 61            // 
 62            // button1
 63            // 
 64            this.button1.Location = new System.Drawing.Point(80280);
 65            this.button1.Name = "button1";
 66            this.button1.Size = new System.Drawing.Size(10523);
 67            this.button1.TabIndex = 0;
 68            this.button1.Text = "查看剪贴板";
 69            this.button1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
 70            this.button1.Click += new System.EventHandler(this.button1_Click);
 71            // 
 72            // button2
 73            // 
 74            this.button2.Location = new System.Drawing.Point(231280);
 75            this.button2.Name = "button2";
 76            this.button2.Size = new System.Drawing.Size(10523);
 77            this.button2.TabIndex = 1;
 78            this.button2.Text = "粘贴剪贴板";
 79            this.button2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
 80            this.button2.Click += new System.EventHandler(this.button2_Click);
 81            // 
 82            // richTextBox1
 83            // 
 84            this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
 85            this.richTextBox1.Name = "richTextBox1";
 86            this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedBoth;
 87            this.richTextBox1.Size = new System.Drawing.Size(416272);
 88            this.richTextBox1.TabIndex = 2;
 89            this.richTextBox1.Text = "";
 90            this.richTextBox1.WordWrap = false;
 91            // 
 92            // Form1
 93            // 
 94            this.AutoScaleBaseSize = new System.Drawing.Size(818);
 95            this.ClientSize = new System.Drawing.Size(416306);
 96            this.Controls.AddRange(new System.Windows.Forms.Control[] {
 97                                                                          this.richTextBox1,
 98                                                                          this.button2,
 99                                                                          this.button1}
);
100            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
101            this.MaximizeBox = false;
102            this.Name = "Form1";
103            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
104            this.Text = "剪贴板应用程序";
105            this.ResumeLayout(false);
106
107        }

108        #endregion

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

转载于:https://www.cnblogs.com/gofficer/archive/2007/08/23/866733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值