C#读取剪贴板内容并把内容记录在XML文件中

最近在做一个练习,就是用C# 2005写一个读取剪贴板的程序,并把读取的内容写进XML文件中!先和大家分享一下:
程序运界面如下:
%E6%9C%AA%E5%91%BD%E5%90%8D-1.jpg

xml文件如下:
None.gif <? xml version="1.0" encoding="utf-8"  ?>
None.gif
< monitor >
None.gif  
< state >
None.gif    
< time > 2006-02-27 17:00 </ time >
None.gif    
< result > 001 </ result >
None.gif  
</ state >
None.gif
</ monitor >

程序代码如下:
None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Text;
None.gif
using  System.Windows.Forms;
None.gif
using  System.Xml;
None.gif
None.gif
namespace  WindowsApplication1
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public partial class Form2 : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public Form2()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void timer1_Tick(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            XmlDocument xmlDoc 
= new XmlDocument();
InBlock.gif            xmlDoc.Load(
"Control.xml");
InBlock.gif            XmlNode root 
= xmlDoc.SelectSingleNode("monitor");
InBlock.gif            XmlElement xe1 
= xmlDoc.CreateElement("state");
InBlock.gif            XmlElement xesub1 
= xmlDoc.CreateElement("time");
InBlock.gif            xesub1.InnerText 
= DateTime.Now.ToString();
InBlock.gif            xe1.AppendChild(xesub1);
InBlock.gif            XmlElement xesub2 
= xmlDoc.CreateElement("result");
InBlock.gif            IDataObject iData 
= Clipboard.GetDataObject();
InBlock.gif            
if (iData.GetDataPresent(DataFormats.Text))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                xesub2.InnerText 
= (string)iData.GetData(DataFormats.Text);
InBlock.gif                xe1.AppendChild(xesub2);
InBlock.gif                root.AppendChild(xe1);
InBlock.gif                xmlDoc.Save(
"Control.xml");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"剪贴板数据不是文本格式,请检查!""错误");
InBlock.gif                
this.Close();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button2_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Close();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button1_Click_1(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (textBox1.Text != "" && int.Parse(textBox1.Text) != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.timer1.Interval = int.Parse(this.textBox1.Text);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"请输入数字格式!");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockEnd.gif            }

InBlock.gif           
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

因为是比较简单的代码,在这里就不做解释了!程序写得很烂,望高手们指点!

转载于:https://www.cnblogs.com/NicNet/archive/2006/02/28/339899.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值