剪贴板应用程序
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
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![]()
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 ClipBoard9
{10
/// <summary>11
/// 剪贴板应用程序。12
/// </summary>13
public class Form1 : System.Windows.Forms.Form14
{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 code109

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



浙公网安备 33010602011771号