现在的位置: 首页 > 综合 > 正文

整理一些小东西,留个备份

2011年03月10日 ⁄ 综合 ⁄ 共 885字 ⁄ 字号 评论关闭

1.在winform中使用IE:
在工具箱里右击,选添加/删除选项,在弹出的对话框里选Com组件选项卡,找到Microsof Web浏览器组件,确定,
在工具箱里选择WebBrowser控件,拖放到窗体上,然后写代码:
private void button1_Click(object sender, System.EventArgs e)
{
 string str="";
 System.Object nullObject=0;
 System.Object nullObjStr=str;
 this.axWebBrowser1.Navigate("www.csdn.net",ref nullObject,ref nullObjStr,ref nullObjStr,ref nullObjStr);
   
}

2.修改xml节点值:
设xml文档为:
<test>
<name>server</name>
</test>

XmlDocument doc = new XmlDocument();
doc.Load("sample.xml");
XmlNodeList nodes = doc.GetElementsByTagName("name");
nodes[0].InnerText = "NewValue";
doc.Save("sample.xml");

3.在类被析构时向log文件中写内容:
using System;
using System.IO;
using System.Data;
namespace finalize
{
 class test
 {
  string s = "aaa";
  ~test()
  {
   StreamWriter lastGasp;
   lastGasp = File.CreateText("yourLog.log");
   lastGasp.WriteLine("it's a log" + s);
   lastGasp.Flush();
   lastGasp.Close();
  }

  [STAThread]
  static void Main(string[] args)
  {
   test t = new test();
  }
 }
}

抱歉!评论已关闭.