| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1561 人关注过本帖
标题:c#中剪切板的应用
只看楼主 加入收藏
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
结帖率:25%
收藏
 问题点数:0 回复次数:2 
c#中剪切板的应用

using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data;
public class Form1 : Form
{
private RichTextBox richTextBox1 ;
private Button button1 ;
private System.ComponentModel.Container components = null ;
public Form1()
{
//初始化窗体中的各个组件
InitializeComponent ( ) ;
}
//清除程序中使用过的资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing );
}
private void InitializeComponent ( )
{
this.richTextBox1 = new RichTextBox ( ) ;
this.button1 = new Button ( ) ;
this.SuspendLayout ( ) ;

this.richTextBox1.Location = new System.Drawing.Point ( 40 , 16 ) ;
this.richTextBox1.Name = "richTextBox1" ;
this.richTextBox1.Size = new System.Drawing.Size ( 336 , 264 ) ;
this.richTextBox1.TabIndex = 0 ;
this.richTextBox1.Text = "" ;

this.button1.Location = new System.Drawing.Point ( 128 , 304 ) ;
this.button1.Name = "button1" ;
this.button1.Size = new System.Drawing.Size ( 128 , 24 ) ;
this.button1.TabIndex = 1 ;
this.button1.Text = "获得剪切板中的数据" ;
this.button1.Click += new System.EventHandler ( this.button1_Click ) ;

this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 408 , 357 ) ;
this.Controls.Add ( button1 );
this.Controls.Add ( richTextBox1 );
this.Name = "Form1";
this.Text = "用Visual C#来保存剪切板中的数据!";
this.ResumeLayout(false);

}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{ //定义一个IDataObject接口
IDataObject d = Clipboard.GetDataObject ( ) ;
//如果剪切板中数据是位图,则另存为F盘的my.bmp文件
if ( d.GetDataPresent ( DataFormats.Bitmap ) )
{
//出箱
Bitmap b = ( Bitmap ) d.GetData ( DataFormats.Bitmap ) ;
b.Save ( @"F:\my.bmp" ) ;
MessageBox.Show ("当前剪切板内容是位图,已经保存到MY.BMP文件中!" ) ;
} //如果是文本,则用窗体中的RichText组件显示文本内容。
else if ( d.GetDataPresent ( DataFormats.Text ) )
{
//出箱
String c = ( String ) d.GetData ( DataFormats.Text ) ;
richTextBox1.Text = c ;
}
else
{
MessageBox.Show ( "剪切板中是其他类型的数据!" ) ;
}
}
}

搜索更多相关主题的帖子: using System 剪切 应用 private 
2005-12-01 14:51
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
不错啊~~~原创吗?可以自己加精
2005-12-02 15:40
houyunqing
Rank: 1
等 级:新手上路
帖 子:476
专家分:0
注 册:2005-4-1
收藏
得分:0 
抗议
强烈抗议
极度抗议!

应该用Console程序配合Sleep()来做,你这样做会让新手无从下手!
还有,猫猫写注释的水平还不够呀!

原文:
//定义一个IDataObject接口
IDataObject d = Clipboard.GetDataObject ( ) ;
//如果剪切板中数据是位图,则另存为F盘的my.bmp文件
if ( d.GetDataPresent ( DataFormats.Bitmap ) )
{
//出箱
Bitmap b = ( Bitmap ) d.GetData ( DataFormats.Bitmap ) ;
b.Save ( @"F:\my.bmp" ) ;
MessageBox.Show ("当前剪切板内容是位图,已经保存到MY.BMP文件中!" ) ;
}

改:
IDataObject d = Clipboard.GetDataObject ( ) ;//IDataObject是用来存放剪贴板内容的东西
if ( d.GetDataPresent ( DataFormats.Bitmap ) ) //使用IDataObject的GetDataPresent方法来判断这个IDataObject存放的内容是什么类型的,这里是判断是否是Bitmap类型(即DataFormats.Bitmap)
{
Bitmap b = ( Bitmap ) d.GetData ( DataFormats.Bitmap ) ;//获取存放的内容
b.Save ( @"F:\my.bmp" ) ;//将Bitmap保存
MessageBox.Show ("当前剪切板内容是位图,已经保存到MY.BMP文件中!" ) ;
}


论坛里新手很多的,得关注关注他们啊!

寻求挑战,追求完美 Oh,my god!
2005-12-03 11:23
快速回复:c#中剪切板的应用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014119 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved