<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_明年我18</title><subtitle type="text"/><id>http://feed.cnblogs.com/blog/u/64085/rss</id><updated>2012-05-08T02:53:55Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><generator>feed.cnblogs.com</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/64085/rss"/><entry><id>http://www.cnblogs.com/default/archive/2012/03/18/2404277.html</id><title type="text">使用HttpWebRequest post数据时要注意UrlEncode</title><summary type="text">今天在用HttpWebRequest类向一个远程页面post数据时，遇到了一个怪问题，总是出现500的内部服务器错误，通过查看远程服务器的log，发现报的是“无效的视图状态”错误： 通过对比自己post的__VIEWSTATE和服务器接收到的__VIEWSTATE的值（通过服务器的HttpApplication的BeginRequest事件可以取到Request里的值），发现__VIEWSTA...</summary><published>2012-03-17T19:17:00Z</published><updated>2012-03-17T19:17:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2012/03/18/2404277.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2012/03/18/2404277.html"/><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;今天在用&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 11pt"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;HttpWebRequest&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;类向一个远程页面&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;post&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;数据时，遇到了一个怪问题，总是出现&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;500&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的内部服务器错误，通过查看远程服务器的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;log&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;，发现报的是“无效的视图状态”错误：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="line-height: normal; mso-no-proof: yes" lang="EN-US"&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201203/201203180316585871.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image001[6]" border="0" alt="clip_image001[6]" src="http://images.cnblogs.com/cnblogs_com/default/201203/201203180316585032.png" width="395" height="252"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;通过对比自己&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 11pt"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;post&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;__VIEWSTATE&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;和服务器接收到的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;__VIEWSTATE&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的值（通过服务器的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;HttpApplication&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;BeginRequest&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;事件可以取到&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Request&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;里的值），发现&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;__VIEWSTATE&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;中的一个&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;+&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;号被替换成了空格。（由于&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;ViewState&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;太长，这个差异也是仔细观察了很久才看出来的）&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;造成这个错误的原因在于&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 11pt"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;+&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;号在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;url&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;中是特殊字符，远程服务器在接受&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;request&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的时候，把&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;+&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;转成了空格。同样的，如果想&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;post&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的数据中有&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&amp;amp;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;、&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;%&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;等等，也会被服务器转义，所以我们在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;post&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的数据的时候，需要先把数据&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;UrlEncode&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;一下。&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;url &lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;encode&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;bs&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;开发中本来是一个很常见的问题，但没想到还是在这里栽了跟头。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;修改后的&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 11pt"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;post&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 11pt"&gt;数据的示例代码如下，注意下面加粗的那句话：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;div style="border-bottom: #000066 1pt solid; border-left: #000066 1pt solid; padding-bottom: 6pt; line-height: normal; text-indent: 0pt; padding-left: 6pt; padding-right: 6pt; background: #fbfbfb; word-break: normal; border-top: #000066 1pt solid; border-right: #000066 1pt solid; padding-top: 6pt; mso-element: para-border-div; mso-border-alt: solid #000066 .75pt"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; HttpWebResponse GetResponse(&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; url)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var req = (HttpWebRequest)WebRequest.Create(url);&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;req.CookieContainer = CookieContainer;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (Parameters.Count &amp;gt; 0)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;req.UserAgent = "&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#8b0000"&gt;Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;";&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;req.ContentType = "&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#8b0000"&gt;application/x-www-form-urlencoded&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;";&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;req.Method = "&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#8b0000"&gt;POST&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;";&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt" color="#008000"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal"&gt;//data&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#008000"&gt;&lt;font style="font-size: 12pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-bidi-font-family: consolas"&gt;&lt;font face="宋体"&gt;要&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 12pt"&gt;UrlEncode&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var postData = &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;.Join("&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#8b0000"&gt;&amp;amp;&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;", Parameters.Select(&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;p =&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;.Format("&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#8b0000"&gt;{0}={1}&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;", p.Key,&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;System.Web.HttpUtility.UrlEncode(p.Value, Encoding))).ToArray());&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var data = Encoding.GetBytes(postData);&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;req.ContentLength = data.Length;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (var sw = req.GetRequestStream())&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;sw.Write(data, 0, data.Length);&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;req.Timeout = 40 * 1000;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var response = (HttpWebResponse)req.GetResponse();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; response;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;p class="MsoNormal"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 11pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 11pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/2404277.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2012/03/18/2404277.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2012/02/28/2370673.html</id><title type="text">安装JBpm</title><summary type="text">自动安装（ant start.demo）太慢，所以手动安装。下载jbpm-5.2.0.Final-installer-full.zip，解压到某个目录，例如d:\jbpm打开根目录下的install.html，找到Manually installing the different components这一节。下面的操作均参照这节的介绍。Getting JBoss AS。上面那个压缩包内已经包含了J...</summary><published>2012-02-27T16:42:00Z</published><updated>2012-02-27T16:42:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2012/02/28/2370673.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2012/02/28/2370673.html"/><content type="html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;自动安装（ant start.demo）太慢，所以手动安装&lt;/em&gt;&lt;/strong&gt;。&lt;/p&gt;&lt;ol&gt;&lt;li&gt;下载&lt;a href="http://sourceforge.net/projects/jbpm/files/"&gt;jbpm-5.2.0.Final-installer-full.zip&lt;/a&gt;，解压到某个目录，例如d:\jbpm&lt;/li&gt;&lt;li&gt;打开根目录下的install.html，找到Manually installing the different components这一节。下面的操作均参照这节的介绍。&lt;/li&gt;&lt;li&gt;Getting JBoss AS。上面那个压缩包内已经包含了JBoss AS 7.02。进到lib下，找到jboss-as-7.0.2.Final.zip，并把它解压到根目录（即和lib同级）。If you already have it installed somewhere else, in install/build.properties, change the jboss.home property to the location of your JBoss AS installation. &lt;/li&gt;&lt;li&gt;Getting Eclipse。修改build.properties中Eclipse的路径，例如eclipse.home=G:/eclipse。注意是/而不是\。&lt;/li&gt;&lt;li&gt;&lt;div&gt;在命令行里转到根目录，运行&lt;/div&gt;&lt;p&gt;ant install.guvnor.into.jboss&lt;/p&gt;&lt;p&gt;ant install.designer.into.jboss&lt;/p&gt;&lt;p&gt;ant install.jBPM-gwt-console.into.jboss&lt;/p&gt;&lt;p&gt;&lt;span style="color:red; text-decoration:line-through"&gt;ant install.jBPM-eclipse.into.eclipse&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:red; text-decoration:line-through"&gt;ant install.drools-eclipse.into.eclipse&lt;/span&gt;&lt;/p&gt;&lt;p&gt;但通过试验发现，后面两条命令运行失败。通过研究build.xml，我们需要把最后两条命令改成一条：ant install.droolsjbpm-eclipse.into.eclipse。也可以不运行这条命令，而是手动安装Eclipse的插件：进到lib文件夹下，把org.drools.updatesite-5.3.1.Final-assembly.zip包内的plugins和features复制到Eclipse目录下即可。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;启动&lt;/div&gt;&lt;p&gt;ant start.h2 &lt;/p&gt;&lt;p&gt;ant start.jboss &lt;/p&gt;&lt;p&gt;ant start.human.task &lt;/p&gt;&lt;p&gt;ant start.eclipse （当然可以自己去打开Eclipse）&lt;/p&gt;&lt;p&gt;测试是否启动成功，可以用浏览器打开:http://localhost:8080/jbpm-console，用"krisv" / "krisv"作为帐号密码，看能不能进去。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;停止&lt;/div&gt;&lt;p&gt;ant stop.h2 &lt;/p&gt;&lt;p&gt;ant stop.jboss &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;手动安装Eclipse插件&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;配置Eclipse插件&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;div&gt;启动Eclipse，进入菜单Window/Preferences，此时应能看到jBpm节点，展开它：&lt;/div&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306232527.png" alt=""/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;把在右边点击Add按钮，添加路径d:\jbpm\lib\jbpm-5.1.0.Final-bin，命名为jbpm-5.1，如下图：&lt;/div&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306234130.png" alt=""/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;在Eclipse中新建一个jbpm的项目，如下图：&lt;/div&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306239429.png" alt=""/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306249952.png" alt=""/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306244936.png" alt=""/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;div&gt;Run as java project，可以看到输出hello world&lt;/div&gt;&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/default/201202/201202282306249886.png" alt=""/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/2370673.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2012/02/28/2370673.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2012/01/09/2317506.html</id><title type="text">我在ZZ这八年</title><summary type="text">在传说中的2012到来的前一天晚上，我正在和曾经在ZZ干过很多年的一个老哥喝酒。相谈甚欢之间，就像庆祝新年的到来那般，那仿佛来自天籁的悦耳动听的短信铃声响了起来：根据XXX总裁指示，需要您写作十周年专题文章…。但酒终究还是要喝的，而且还要喝好。桌上摆了12支空的哈啤之后，我们俩心满意足的摸着肚子离开了酒桌。当我踉踉跄跄爬上一辆出租车后，模模糊糊的从车的倒后镜上看到我那位曾经在ZZ干过很多年的老哥拖...</summary><published>2012-01-09T12:56:00Z</published><updated>2012-01-09T12:56:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2012/01/09/2317506.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2012/01/09/2317506.html"/><content type="html">&lt;p&gt;&lt;span style="font-size:12pt"&gt;在传说中的2012到来的前一天晚上，我正在和曾经在ZZ干过很多年的一个老哥喝酒。相谈甚欢之间，就像庆祝新年的到来那般，那仿佛来自天籁的悦耳动听的短信铃声响了起来：根据XXX总裁指示，需要您写作十周年专题文章…。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;但酒终究还是要喝的，而且还要喝好。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;桌上摆了12支空的哈啤之后，我们俩心满意足的摸着肚子离开了酒桌。当我踉踉跄跄爬上一辆出租车后，模模糊糊的从车的倒后镜上看到我那位曾经在ZZ干过很多年的老哥拖着瘦长的身躯，对着马路牙子尽情的释放他那没被消化系统吸收掉的黄色的液体。他那身影在黄色路灯的衬托下，挺像那尊雕塑的。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;但文章还是要写的，而且还要写好。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;在很小的时候，我曾经以为写文章是最难的事情。记得有次老师布置的作文是写一篇《我的妈妈》，当时为了凑够字数，我不得不把我的妈妈那和普通人一样的两个鼻孔写了出来。然而，不记得从什么时候开始，我的语文成绩已经能和数学成绩相提并论了，尤其是在中学时期那数不清的摸底考试中，命题作文更是信手拈来，一气呵成。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;但文章能拿到高分，又能怎么样呢？我曾经声泪俱下的写过穷苦的家庭条件，但未曾申请到助学贷款；我曾经热情满怀的写过入党申请书，但在大学同宿舍的七个人中，我和另外一位入党积极分子依然属于广大的人民群众。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;巧合的是，我们这两位群众，现在都在为振兴民族软件而奋斗着。这位群众的名字叫做曹超。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;他这个名字叫的真够响亮。但我们私下里都叫他连毛，因为以前他总是在卧谈时给我们讲连毛的故事，如果你没听过这个故事，那就百度一下吧。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;算起来，我和连毛，这两个入党积极分子，是我们七个人中最后找到工作的两个人。我俩成绩不太好，平时在班级里也没什么表现，属于碌碌无为的那类人。但经过无数次的笔试面试之后，不看成绩单的话，我俨然已经是一位德才兼备的优等生了。直到过完那年春节回来，有个比我更落后的哥们还在找我去帮他笔试面试，不过我对不起他，没能帮他过了笔试这一关，还厚脸皮的蹭了他一顿阿慧的肘子。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;当时李总在我们班讲台上宣讲ZZ时到底说了什么，我已经记不清了，就像我记不清腾讯和网易的宣讲会一样。然后就是千篇一律的笔试题目，闭着眼睛胡乱勾了答案。连毛的笔试成绩竟然拿了第一名，真不枉费我发短信告诉了他几道题的答案，虽然他后来跟我说我那几个答案都是错的。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;笔试之后就是面试，面试过了之后的流程和之前应聘的企业就不大一样了：李总让我们用几天的时间自己动手做一个任务管理系统。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;用动手能力而不用成绩单来考验学生，这让我有了兴趣，我可是有好几次都是因为成绩单不漂亮才被刷下来的。不过其实也难为李总了，好学生已经被人家挑走了，剩下的那些成绩单根本没法看。李总，你来晚了，下次赶早。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;接下来的几天就忙起来了，你抄抄我的，我抄抄你的，终于把这课堂大作业给交了。然后我和连毛就从同学变成了同事。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;以学生身份在家过完最后一个春节之后，我们七八个同学浩浩荡荡的南下广州，来ZZ实习。我们被分配到不同的部门，拿着两百块一月的补贴，开始了职业生涯。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;接到的第一个工作是做一个SQL Server的数据库文档生成器，利用几段sql脚本，将SQL Server数据库中的表和字段的信息导出到word里。这个任务完成后，就参与了软件园项目的开发了。这项目的源代码很大，我每天到公司后的第一件事就是双击项目的sln文件，接下来开始吃早餐，然后去厕所撇条，回来再打开网页看会新闻。觉得差不多了，再切换到Visual Studio那里看看是不是已经加载完源代码了。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;这两个月的实习，最困难的莫过于生活了。用肥猪肉煮出来的粥是清淡的，炒个菜多放点酱油是油腻的。当时吃的最多的莫过于桂林米粉店的炒河粉加辣椒了，用陕西话说：美的很。当时广州的物价和西安没得比，200块钱一月的补贴很快就用完了。远在西安的父老乡亲们伸出了援手，一老家北京的哥们打电话说：给哥几个寄两袋大米过去吧。在短暂的学生生涯中，我错过了这美好的两个月。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;不过，通过实习，进一步加强了我之前就建立的对自己能力的自信，并且认识了我孩子他娘，这和本文无关，此处省略五千字。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;实习结束后，我们回到了校园，努力找回这两个月错过的时光。这和本文也无关，此处省略一万字。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;等再次踏入ZZ时，我们已经不再是学生。我还是在原来的部门工作，还是需要每天一早双击软件园项目的sln文件，然后去撇条，然后等待源代码加载完成。在每天的等待之中，我对开发也越来越熟练。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;由于我的工作上手很快，所以在一个月之后，我提前转正为正式员工。我心里在高兴的同时，也盼望我那几个同学能在第二个月的时候转正，但很不幸，我这些同学真的在干满三个月后才转正为正式的员工。这个事情让我一度很恼火，因为我一直认为既然三个月可以确定一个人是否符合公司的用人标准，那么就没有必要等到五个月。前几年我也听到过新入职的同事对我抱怨过这个事情，他实习了半年，但毕业后还要再来三个月试用期。最近两年没带过新毕业的了，所以不知道现在的制度是不是有所改善。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;工作虽然上手了，但在我入职之前，软件园项目毕竟已经做了很久了，我的工作也不过是在原来的基础上做些修补。随后的人事项目才让我第一次接触了整个项目的运作。崔X用Visio画出了系统的原型，我们一堆人用源代码来堆砌。投标那天，李总对着专家演说，我来操作原型系统。当得知我们中标时，我心里挺高兴的，多天来的努力有了成果。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;然后就开始了项目的开发，我负责开发外网人才招聘的模块。当时领导给我说一个月后要给用户用，所以我每天晚上自觉的干到十点多才回家，再晚了公交就没了。连毛后来对我说，我那段时间每晚回到家后，已经是两眼发直，目光呆滞了。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;经过我的努力，企业发布职位、个人用户填写简历、搜索职位等功能被我一点一点的堆砌了起来。当时我写代码的速度挺快的，现在没法和当时比，但写来写去还是觉得时间不够，一个月很快就过了，但我负责的那块东西还没开发完。不过没有人追究我的责任，因为一个月要给用户用的说法，不知道从什么时候开始，听不到了，而最终，这个人事项目做了一年多才算结束。现在想起来，或许我一开始就听错了,但这个事情让我意识到，期限即便是定了，也是可以根据实际情况做调整的，千万不要一声不吭的闷着头苦干。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;人事项目做的并不愉快，加班加点成了家常便饭，但最难受的并不是加班，而是我开始第一次面对反复改动的设计。有些改动是来自客户的，有些则来自项目组内部。开发人员难免会对不断的改动产生抵触，我也没能幸免。那段时间因为这个，没少和搞需求和产品设计的同事闹过矛盾，包括我的领导，也包括我孩子他娘。通过人事项目，也使我了解了ZZ的项目运作方式，即分开一个个的项目组分别负责不同项目的开发，彼此之间的支持和交流很少。我曾经想用数据中心组的数据抽取工具去实现人事项目的人才资源库，可最终不得不自己写sql语句去导不算海量的数据。最终这个人才资源库也没有实现，对我来说是不了了之了。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;当然，人事项目这一年也是我技术上飞速成长的一年，在项目中后期，我实际上已经是这个项目的程序经理了。在这一年里，我知道了在代码这个领域，还有架构和模式这些东西，通过一些技巧，可以把代码写的漂亮优雅。不过我现在也没搞清楚我的这种转变对于ZZ来说是好还是坏，因为我写代码的速度，越来越慢了。在人事项目的后期，我已经不能像以前那样，能够很快的完成布置给我的任务了，因为我总是会考虑很多才会下手：如何写才能有利于扩展，如何写代码才会更好看，如何写才会减少不必要的bug……以前的我是不会考虑这么多的，一旦想清楚怎么样才能实现功能之后，我就会毫不犹豫的敲出代码，而我现在连一个变量该如何命名都会考虑很久。其实对于这种项目来说，有些考虑确实是不必要的，程序设计的再好，再有利于扩展，也很有可能无法满足一次需求的变动。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;做完人事项目之后，我有大概一年半的时间没有做这种面向最终客户的项目。这期间主要做了公司的电子工作台产品和一个.net开发框架，并且负责过一段时间的中大实验室的培训工作。对于我来说，这一年半的时间相对轻松很多，尤其是那段在中大校园里上班的日子。早上8点钟起床，闲庭信步的走到中大里面上班，并时不时的接受几个学生崇拜的目光，舒服的紧。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;三年的合同很快就到期了，当时也萌生了换个工作的想法。找工作的经历也还算顺利，很快就有一家单位给我发出了录用通知，但后来还是因为某些原因留了下来。现在看来，当时或许是我增加社会阅历和工作经验的最好的一次机会，因为仅仅三年的工作经验并不会让我对新工作有过多的索求。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;续签了一年的合同之后，我来到了安监项目组，并且作为程序经理在那里待了一年。这一年过的也很舒服：在办公室里就可以抽烟，因为安监局信息办的XX一直在那抽，我如果每次抽烟都出去的话，会把他弄得不好意思的；项目经理万X很爱也很能喝酒，我们组的人经常出去，每次都喝的很爽，每次能听到喝完酒的万老师叫我孔哥；第一次也是唯一一次可以在技术上完全做主，虽然我下面只有一个开发人员。但安监项目做的也不成功，主要原因是我无法实现安监局长的安监综合库的设想。和人事项目的人才资源库一样，我又一次倒在了和数据中心类似的项目上。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;在安监做了一段时间之后，我开始考虑自己后面的生活。我一直认为最美味的早餐应该是胡辣汤、油条和鸡汤馄饨，所以我决定合同一到期就北上。当时的目的地主要是山东和北京，回山东可以与家人团聚，但山东的待遇不高，所以想先去北京干几年，有条件好的工作之后再回山东。所以在2008年9月底合同一到期，我就提出了离职申请，并且真的离职了。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;然而我北京那些同学的高薪，使我对自己有了过高的定位。北京11月的寒风已经足够刺透骨头，在2008年那场覆盖全球的金融危机下，在对陌生环境产生的孤独感下，在北京逛了一个月之后，我放弃了，并且回到了广州，回到了ZZ。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;回来以后，就开始了软件生产线的开发，一直到今天。不知不觉又过了三年多了，这三年多来，我们团队从最初的三个人，渐渐扩展到现在十个人，并且成立了新的公司：本体。每一年李总都要求我们尽快开发出软件生产线这个产品，每次和同事一起吃饭聊天时，也经常被问到我们的生产线开发的怎么样了，然而她却像一个羞见公婆的丑媳妇一样，直到今天才算像点样子。虽然迟迟没能拿出成绩，但这期间我们整个团队为此付出的努力和汗水，自不必说。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;软件生产线这个产品虽然很难开发，但它并不是难在技术，而是难在整个产品的设计上，就算很谨慎，也很容易做出很多虚的或者没什么用的功能出来。所以要在实际项目用的过程中慢慢完善。去年年会扔出来的四千万，至今还经常被别的组的同事提起，看来大家都对这个产品抱有很大的期望。但玩笑终归是玩笑，我能做的，也只不过是尽量的完善它，使它真正的能够做些事情。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:12pt"&gt;今年是ZZ成立的第十年，而我也在ZZ做了将近八年了。这八年里有苦闷也有欢笑，有老婆也有孩子。由衷的祝愿ZZ能够越走越好。&lt;/span&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/2317506.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2012/01/09/2317506.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2011/11/24/2261913.html</id><title type="text">(转)Getting rid of the DSL model explorer</title><summary type="text">http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/ Every DSL you create with DSL Tools has a model explorer. This model explorer is a tool window in Visual Studio display...</summary><published>2011-11-24T08:18:00Z</published><updated>2011-11-24T08:18:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2011/11/24/2261913.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2011/11/24/2261913.html"/><content type="html">&lt;p&gt;&lt;a href="http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/"&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#333333; font-family:Trebuchet MS; font-size:9pt"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:Trebuchet MS; font-size:9pt"&gt;Every DSL you create with DSL Tools has a model explorer. This model explorer is a tool window in Visual Studio displaying the elements of your model in a hierarchical way. This is often a nice feature but sometimes a hierarchical view of your data is not appropriate. So I came to the question: &lt;em&gt;How to remove the explorer from the generated code?&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333"&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;I could not find any option in the DSL design to remove the model explorer, but if you look at some of the .tt files you will find somewhere a query for &lt;/span&gt;&lt;span style="font-family:宋体"&gt;this.Dsl.Explorer != null&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;. For example in the &lt;/span&gt;&lt;span style="font-family:宋体"&gt;package.tt&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; file that generates the &lt;/span&gt;&lt;span style="font-family:宋体"&gt;package.cs&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; which is responsible for registering the tool window for the model explorer:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:宋体; background-color:gold"&gt;&amp;lt;#&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:midnightblue; font-family:宋体; background-color:aliceblue"&gt;    if(this.Dsl.Explorer != null)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:midnightblue; font-family:宋体; background-color:aliceblue"&gt;    {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:宋体; background-color:gold"&gt;#&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:red; font-family:宋体"&gt;&lt;span style="color:gray"&gt;[VSShell::ProvideToolWindow(         typeof(&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color:midnightblue"&gt;&lt;span style="background-color:aliceblue"&gt; dslName &lt;/span&gt;&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;#&amp;gt;&lt;/span&gt;&lt;span style="color:gray"&gt;ExplorerToolWindow),          MultiInstances = false,          Style = VSShell::VsDockStyle.Tabbed,          Orientation = VSShell::ToolWindowOrientation.Right,          Window = "{3AE79031-E1BC-11D0-8F78-00A0C9110057}")]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:gray; font-family:宋体"&gt;    [VSShell::ProvideToolWindowVisibility(         typeof(&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color:midnightblue"&gt;&lt;span style="background-color:aliceblue"&gt; dslName &lt;/span&gt;&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;#&amp;gt;&lt;/span&gt;&lt;span style="color:gray"&gt;ExplorerToolWindow),          Constants.&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;&amp;lt;#=&lt;/span&gt;&lt;span style="color:midnightblue"&gt;&lt;span style="background-color:aliceblue"&gt; dslName &lt;/span&gt;&lt;span style="color:#333333"&gt;&lt;span style="background-color:gold"&gt;#&amp;gt;&lt;/span&gt;&lt;span style="color:gray"&gt;EditorFactoryId)]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:宋体; background-color:gold"&gt;&amp;lt;#&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:midnightblue; font-family:宋体; background-color:aliceblue"&gt;    }&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:宋体"&gt;&lt;span style="background-color:gold"&gt;#&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333"&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;Even if I did not find any option to set the &lt;/span&gt;&lt;span style="font-family:宋体"&gt;Dsl.Explorer&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; property of the model to &lt;/span&gt;&lt;span style="font-family:宋体"&gt;null&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; (you did not see the Explorer property anywhere in the DSL diagram) it seems that the developers of the DSL Tools had this use case in mind.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333"&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;To remove the &lt;/span&gt;&lt;span style="font-family:宋体"&gt;Dsl.Explorer&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; from your DSL model open the &lt;/span&gt;&lt;span style="font-family:宋体"&gt;.dsl&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; file with a text editor and go to the end. There you will find some XML tags like the following:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:blue; font-family:宋体"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Explorer &lt;span style="color:red"&gt;ExplorerGuid&lt;span style="color:blue"&gt;=&lt;span style="color:#333333"&gt;"&lt;span style="color:blue"&gt;6c276297-6acd-4e9a-8740-b61ba834004b&lt;span style="color:#333333"&gt;"  &lt;span style="color:red"&gt;Title&lt;span style="color:blue"&gt;=&lt;span style="color:#333333"&gt;"&lt;span style="color:blue"&gt;HardwareDescription Explorer&lt;span style="color:#333333"&gt;"&lt;span style="color:blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:blue; font-family:宋体"&gt;    &amp;lt;&lt;span style="color:#a31515"&gt;ExplorerBehaviorMoniker      &lt;span style="color:red"&gt;Name&lt;span style="color:blue"&gt;=&lt;span style="color:#333333"&gt;"&lt;span style="color:blue"&gt;HardwareDescription/HardwareDescriptionExplorer&lt;span style="color:#333333"&gt;" &lt;span style="color:blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:blue; font-family:宋体"&gt;&amp;lt;/&lt;span style="color:#a31515"&gt;Explorer&lt;span style="color:blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:Trebuchet MS; font-size:9pt"&gt;Just delete these three lines and generate your code once again. Maybe you should reset your Experimental Hive, too.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333"&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt;I tested a DSL with a removed Model Explorer without any problems. It seems the developers of the DSL Tools did a very good job on the code generation templates . The generated &lt;/span&gt;&lt;span style="font-family:宋体"&gt;ModelExplorer.cs&lt;/span&gt;&lt;span style="font-family:Trebuchet MS; font-size:9pt"&gt; file contains only a single line:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:green; font-family:宋体"&gt;// This source file is empty because    this DSL does not define a model explorer.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#333333; font-family:Trebuchet MS; font-size:9pt"&gt;That should be a good proof that a DSL can run without the model explorer even if it might be not supported by the DSL Tools. &lt;img src="http://images.cnblogs.com/cnblogs_com/default/201111/201111241617515143.gif" alt=""/&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/2261913.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2011/11/24/2261913.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2011/06/19/2084869.html</id><title type="text">开发一个Word的代码高亮插件</title><summary type="text">在用Word写技术文档的时候，免不了要在文档中插入一些源代码。为了使插入进来的源代码更可读，就需要使这些代码的关键字高亮显示。所以在写这些文档的时候，我经常需要再开一个Visual Studio，在Visual Studio里编辑好代码之后，复制到Word里面，Word会帮助我们保留代码的格式，达到关键字高亮的效果。 但这样做难免有些不方便，如果能在word中装一个支持代码高亮的插件就好了。在网上搜索无果之后，自己做了一个。 如何开发Word的外接程序是需要解决的第一个问题，可以参考博客园的一个系列：我的VSTO之路，我就是参考着他这个系列做的这个插件，不过目前这个插件只支持Word 201.</summary><published>2011-06-19T15:21:00Z</published><updated>2011-06-19T15:21:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2011/06/19/2084869.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2011/06/19/2084869.html"/><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;在用&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;写技术文档的时候，免不了要在文档中插入一些源代码。为了使插入进来的源代码更可读，就需要使这些代码的关键字高亮显示。所以在写这些文档的时候，我经常需要再开一个&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Visual Studio&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;，在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Visual Studio&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;里编辑好代码之后，复制到&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;里面，&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;会帮助我们保留代码的格式，达到关键字高亮的效果。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;但这样做难免有些不方便，如果能在&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;word&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;中装一个支持代码高亮的插件就好了。在网上搜索无果之后，自己做了一个。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;如何开发&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的外接程序是需要解决的第一个问题，可以参考博客园的一个系列：&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;a href="http://www.cnblogs.com/izualx/tag/VSTO/" target="_blank"&gt;&lt;font color="#800080"&gt;&lt;u&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin" lang="EN-US"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="宋体"&gt;我的&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Calibri"&gt;VSTO&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin" lang="EN-US"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="宋体"&gt;之路&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/u&gt;&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;，我就是参考着他这个系列做的这个插件，不过目前这个插件只支持&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word 2010&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;接下来，怎样实现代码高亮？幸好，有一个开源的项目&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Wilco.SyntaxHighlighting&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;可以解决我的问题。它支持多种语言的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Highlighter&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;，并提供&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Html&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;和&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Rtf&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;两种格式的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;parser&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;把&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Highlighter&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;code&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;转换为&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;html&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;或&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;rtf&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;的格式。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;最后，怎样把高亮后的代码插入到&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;中？由于&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;的插件开发不是我研究的重点，所以想了一个比较懒的做法，即把&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;html&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;格式或&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;rtf&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;格式的高亮代码复制到剪贴板上，然后利用&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;_Application.Selection.Paste&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;方法粘帖进来，代码如下：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;div style="border-bottom: #000066 1pt solid; border-left: #000066 1pt solid; padding-bottom: 6pt; line-height: normal; text-indent: 0pt; padding-left: 6pt; padding-right: 6pt; background: #fbfbfb; word-break: normal; border-top: #000066 1pt solid; border-right: #000066 1pt solid; padding-top: 6pt; mso-element: para-border-div; mso-border-alt: solid #000066 .75pt"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 12pt"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font style="font-size: 12pt"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; button1_Click(&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; sender, RibbonControlEventArgs e)&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var dialog = &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; MainForm();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(dialog.ShowDialog() == DialogResult.OK)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;dialog.CopyToClipboard();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;Globals.ThisAddIn.Application.Selection.Paste();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;插件的效果如下。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 10.5pt"&gt;Word&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;功能区：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321007086.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321049434.png" width="513" height="282"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; mso-no-proof: yes" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;点设置按钮弹出设置界面，支持&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Rtf&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;和&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Html&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;两种格式，还可以设置边框、背景、交替行等样式，不过我比较懒，没去研究怎么在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Rtf&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;格式下设置边框、背景，所以在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Rtf&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;格式下是不支持边框颜色、背景颜色和交替行的。所以建议大家选择&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Html&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;格式。设置界面如下图：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321052074.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321082928.png" width="284" height="340"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; mso-no-proof: yes" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;点击插入代码按钮，会弹出插入代码的界面，如下图：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321093408.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/20110619232112816.png" width="417" height="314"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; mso-no-proof: yes" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;可以选择&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;C#&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;、&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Java&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;、&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Xml&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;、&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Javascript&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;等多种语言。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;一些效果如下：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 12pt" color="#008000"&gt;//no style&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;font face="宋体"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 12pt"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font style="font-size: 12pt"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; button1_Click(&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; sender, RibbonControlEventArgs e)&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;var dialog = &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; MainForm();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font color="#000000"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(dialog.ShowDialog() == DialogResult.OK)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;dialog.CopyToClipboard();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;Globals.ThisAddIn.Application.Selection.Paste();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="border-bottom: #000066 1pt solid; border-left: #000066 1pt solid; padding-bottom: 6pt; line-height: normal; text-indent: 0pt; padding-left: 6pt; padding-right: 6pt; background: #f0f0f0; word-break: normal; border-top: #000066 1pt solid; border-right: #000066 1pt solid; padding-top: 6pt; mso-element: para-border-div; mso-border-alt: solid #000066 .75pt"&gt;&lt;font face="宋体"&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;1: &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt" color="#008000"&gt;&lt;span style="line-height: normal"&gt;//&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal"&gt;&lt;font style="font-size: 12pt" color="#008000"&gt;框&lt;span style="line-height: normal" lang="EN-US"&gt; + &lt;/span&gt;行号&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;2: &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; button1_Click(&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; sender, RibbonControlEventArgs e)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;3: {&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;4:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;var dialog = &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; MainForm();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;5:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(dialog.ShowDialog() == DialogResult.OK)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;6:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;7:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;dialog.CopyToClipboard();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;8:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Globals.ThisAddIn.Application.Selection.Paste();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;9:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt; 10: }&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="border-bottom: #000066 1pt solid; border-left: #000066 1pt solid; padding-bottom: 6pt; line-height: normal; text-indent: 0pt; padding-left: 6pt; padding-right: 6pt; background: #fbfbfb; word-break: normal; border-top: #000066 1pt solid; border-right: #000066 1pt solid; padding-top: 6pt; mso-element: para-border-div; mso-border-alt: solid #000066 .75pt"&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;1: &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt" color="#008000"&gt;&lt;span style="line-height: normal"&gt;//&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font color="#008000"&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-bidi-font-family: consolas"&gt;&lt;font face="宋体"&gt;框&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt; + &lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-bidi-font-family: consolas"&gt;&lt;font face="宋体"&gt;行号&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt; + &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-bidi-font-family: consolas"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 12pt"&gt;交替行&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;2: &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; button1_Click(&lt;/font&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; sender, RibbonControlEventArgs e)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;3: {&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;4:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;var dialog = &lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; MainForm();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;5:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 12pt"&gt;&lt;span style="line-height: normal"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(dialog.ShowDialog() == DialogResult.OK)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;6:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;7:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;dialog.CopyToClipboard();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;8:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Globals.ThisAddIn.Application.Selection.Paste();&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&lt;font style="font-size: 12pt"&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 12pt"&gt;9:&lt;span style="line-height: normal; mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: normal; font-family: " lang="EN-US"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 12pt" color="#000000"&gt; 10: }&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;&lt;font style="font-size: 10.5pt" color="#000000"&gt;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;我这篇文章就是用&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;写的，上面这些代码也是用我做的这个插件插进来的。但就当我兴高采烈的用&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;把这篇文章发布到博客园之后，才发现发布后的上述代码段出现了不同程度的变形，而且是无法接受的变形，如下图：&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321152051.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/201106192321184300.png" width="465" height="342"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt; mso-no-proof: yes" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;可以看到，边框没了，&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;和&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;之间空格很大，而且还换行了。这个问题研究了很久和不知道该如何解决，可能&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;在发布博文的时候对格式的改变太大，导致了变形。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;font color="#000000"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;那如果想把&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10.5pt"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;写的文章发布到博客上怎么办呢？建议在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Word&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;里写好的文章后，把内容复制下来，然后在&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;Windows live writer&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&amp;#8220;选择性粘帖&amp;#8221;进去，利用&lt;/font&gt;&lt;/span&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="Calibri"&gt;windows live writer&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt"&gt;来发布博客。&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" align="justify"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;a href="http://files.cnblogs.com/default/SyntaxHighlighter4Word.rar"&gt;&lt;span style="line-height: 12pt; font-family: ; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin" lang="EN-US"&gt;&lt;span style="line-height: 12pt" lang="EN-US"&gt;&lt;font face="宋体"&gt;&lt;font style="font-size: 10.5pt" color="#0000ff"&gt;&lt;u&gt;源代码下载&lt;/u&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;img src="http://www.cnblogs.com/default/aggbug/2084869.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2011/06/19/2084869.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2011/06/11/2078501.html</id><title type="text">（翻译）LearnVSXNow! #16- 创建简单的编辑器-2</title><summary type="text">(LearnVSXNow又开始继续翻译了，为了提高翻译速度，不再对每句话进行翻译，并且会用自己的理解来代替不好翻译的句子。理解不一定正确，见谅。) 前面那篇文章介绍了Visual Studio的自定义编辑器的基本概念，并用一个例子来说明如何创建自定义编辑器，今天我们继续这个例子。 1. 注册Editor Editor需要注册到Visual Studio中才能使用。通常会注册下面三个东西： Editor Factory：告诉Visual Studio我们的package可以提供哪些Editor Factory。 Editor支持的文件扩展名：告诉Visual Studio哪种扩展名的文件会关联.</summary><published>2011-06-11T10:23:00Z</published><updated>2011-06-11T10:23:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2011/06/11/2078501.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2011/06/11/2078501.html"/><content type="html">&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (LearnVSXNow又开始继续翻译了，为了提高翻译速度，不再对每句话进行翻译，并且会用自己的理解来代替不好翻译的句子。理解不一定正确，见谅。)&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://www.cnblogs.com/default/archive/2010/07/17/1779563.html" target="_blank"&gt;前面那篇文章&lt;/a&gt;介绍了Visual Studio的自定义编辑器的基本概念，并用一个例子来说明如何创建自定义编辑器，今天我们继续这个例子。  &lt;p&gt;&lt;strong&gt;&lt;font color="#1a8bc8"&gt;1. 注册Editor&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editor需要注册到Visual Studio中才能使用。通常会注册下面三个东西：  &lt;blockquote style='border:2px solid #EFEFEF;color:#333333;padding:5px 10px;'&gt; &lt;p&gt;Editor Factory：告诉Visual Studio我们的package可以提供哪些Editor Factory。  &lt;p&gt;Editor支持的文件扩展名：告诉Visual Studio哪种扩展名的文件会关联到我们的Editor。  &lt;p&gt;Editor的逻辑视图（Logic View）：下面的段落中会提到什么是Logic View&lt;/p&gt;&lt;/blockquote&gt; &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt; &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// --- Other attributes have been omitted&lt;/span&gt;&lt;!--CRLF--&gt;[ProvideEditorFactory(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(BlogItemEditorFactory), 200, &lt;!--CRLF--&gt;  TrustLevel = __VSEDITORTRUSTLEVEL.ETL_AlwaysTrusted)]&lt;!--CRLF--&gt;[ProvideEditorExtension(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(BlogItemEditorFactory), &lt;!--CRLF--&gt;  HowToPackage.BlogFileExtension,&lt;!--CRLF--&gt;  32,&lt;!--CRLF--&gt;  ProjectGuid = &lt;span style="color: #006080"&gt;"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"&lt;/span&gt;,&lt;!--CRLF--&gt;  TemplateDir = &lt;span style="color: #006080"&gt;@"..\..\BlogItemEditor\Templates"&lt;/span&gt;,&lt;!--CRLF--&gt;  NameResourceID = 200)]&lt;!--CRLF--&gt;[ProvideEditorLogicalView(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(BlogItemEditorFactory), &lt;!--CRLF--&gt;  GuidList.GuidBlogItemEditorLogicalView)]&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HowToPackage : Package&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; BlogFileExtension = &lt;span style="color: #006080"&gt;".blit"&lt;/span&gt;;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Initialize()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Initialize();&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- Other initialization code  &lt;/span&gt;&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- Register the blog item editor&lt;/span&gt;&lt;!--CRLF--&gt;    RegisterEditorFactory(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; BlogItemEditorFactory());&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- Other initialization code&lt;/span&gt;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProvideEditorFactory&lt;/strong&gt;表示我们的Package会提供什么Editor Factory。参数200是资源的ID，表示EditorFactory的名字（在VSPackage.resx文件中定义）。&lt;strong&gt;TrustLevel&lt;/strong&gt; 用来设置Editor的信任级别。不懂什么叫&amp;#8220;信任级别&amp;#8221;没关系，我也不懂，但不影响使用，至少目前是这样。 &lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProvideLogicalView&lt;/strong&gt; 表示我们的的Editor Factory可以提供一个逻辑视图。第二个参数是逻辑视图的guid。暂时弄不清楚这个逻辑视图是干嘛的也没关系，至少这篇文章的例子不太需要它。 &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 在上面的代码里最长的是&lt;strong&gt;ProvideEditorExtension&lt;/strong&gt; ，我用到了6个参数： &lt;blockquote style='border:2px solid #EFEFEF;color:#333333;padding:5px 10px;'&gt;&lt;p&gt;第一个参数用来指定Editor Factory。 &lt;p&gt;第二个参数指定对应文件的扩展名，在这个例子里是&amp;#8220;.blit&amp;#8221;。 &lt;p&gt;第三个参数设置Editor的优先级。 &lt;p&gt;ProjectGuid属性指定一个项目类型的GUID，比如我们这个例子里指定了C#项目的GUID，这样在C#项目里&amp;#8220;添加新项&amp;#8221;时，可以在&amp;#8220;添加新项&amp;#8221;对话框里看到.blit文件。 &lt;p&gt;TemplateDir属性指定添加新项对话框从哪个文件夹里寻找模版。它是一个相对路径，相对于当前Package编译出来的dll所在的目录。 &lt;p&gt;NameResourceID属性设置在添加新项对话框里，我们的文件类型显示的名字，它是一个在VSPackage.resx中定义的资源ID。&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 在目录TemplateDir里需要放一些文件，用来说明该目录下的模版的名称、描述等信息。在这里我使用".vsdir"这种格式的文件：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;BlogItem.blit|{0380775d-5735-43ed-8c23-c1fda451e1c8}|#200|32|#202|{0380775d-5735-43ed-8c23-c1fda451e1c8}|400|0|#203&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 请注意，不管在你的浏览器上看到上面这段代码显示为几行，它实际上应该是一行才对。这行文本由&amp;#8220;|&amp;#8221;号隔开了下面几个内容： &lt;blockquote style='border:2px solid #EFEFEF;color:#333333;padding:5px 10px;'&gt;&lt;p&gt;— &lt;strong&gt;BlogItem.blit&lt;/strong&gt;: 模版文件的文件名，该文件也存放在TemplateDir文件夹下面。 &lt;p&gt;— &lt;strong&gt;GUID&lt;/strong&gt;: 我们的Package的GUID。 &lt;p&gt;— &lt;strong&gt;#200&lt;/strong&gt;: 模版的名称，是一个定义在VSPackage.resx中的资源ID。应该是和上面提到的NameResourceID同一个东西。 &lt;p&gt;— &lt;strong&gt;32&lt;/strong&gt;: 模版显示在添加新项对话框中的顺序。 &lt;p&gt;— &lt;strong&gt;#202&lt;/strong&gt;: 模版的描述，是一个定义在VSPackage.resx中的资源ID。 &lt;p&gt;— &lt;strong&gt;GUID&lt;/strong&gt;: 定义资源的dll的GUID。在这里我们用Package的GUID。 &lt;p&gt;— &lt;strong&gt;400&lt;/strong&gt;: 在添加新项对话框中，模版的图标的资源ID. &lt;p&gt;— &lt;strong&gt;0&lt;/strong&gt;: 貌似是一些标记，我也弄不清楚。 &lt;p&gt;— &lt;strong&gt;#203&lt;/strong&gt;: 在添加新项对话框中的默认文件名资源ID。&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 需要说明一下，&lt;strong&gt;ProvideEditorExtension&lt;/strong&gt; 后面的三个参数以及这个vsdir文件可以不设置，它和Editor没什么关系，是属于Project的ItemTemplate的相关内容，但既然作者写了它们，那我也就照着把它们翻译过来了。 &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 仅仅在Package上面加上这几个Attribute是不够的，我们还必须在Package初始化的时候，创建我们的Editor Factory的实例：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Initialize()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Initialize();&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Other initialization code  &lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Register the blog item editor&lt;/span&gt;&lt;!--CRLF--&gt;  RegisterEditorFactory(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; BlogItemEditorFactory());&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Other initialization code&lt;/span&gt;&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&amp;nbsp;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;&lt;font color="#1a8bc8"&gt;2 Editor Factory&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 在第15章中可以看到，&lt;strong&gt;BlogItemEditorFactory&lt;/strong&gt; 继承自&lt;strong&gt;SimpleEditorFactory&amp;lt;&amp;gt;&lt;/strong&gt; 泛型类，并指定了Guid：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[Guid(GuidList.GuidBlogEditorFactoryString)]&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BlogItemEditorFactory: &lt;!--CRLF--&gt;  SimpleEditorFactory&amp;lt;BlogItemEditorPane&amp;gt;&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- That is the full code of this class! Nothing is omitted.&lt;/span&gt;&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 基类&lt;strong&gt;SimpleEditorFactory&lt;/strong&gt;的代码如下：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SimpleEditorFactory&amp;lt;TEditorPane&amp;gt; : &lt;!--CRLF--&gt;  IVsEditorFactory, &lt;!--CRLF--&gt;  IDisposable&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; TEditorPane: &lt;!--CRLF--&gt;    WindowPane, IOleCommandTarget, IVsPersistDocData, IPersistFileFormat, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt;()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ServiceProvider _ServiceProvider;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; SimpleEditorFactory() { ... }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- IDisposable pattern implementation&lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose() { ... }&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; disposing) { ... }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- IVsEditorFactory implementation&lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; SetSite(IOleServiceProvider serviceProvide) { ... }&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MapLogicalView(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; Guid logicalView, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; physicalView)&lt;!--CRLF--&gt;  { ... }&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Close() { ... }&lt;!--CRLF--&gt;  [EnvironmentPermission(SecurityAction.Demand, Unrestricted = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CreateEditorInstance(&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; grfCreateDoc,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pszMkDocument,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pszPhysicalView,&lt;!--CRLF--&gt;      IVsHierarchy pvHier,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; itemid,&lt;!--CRLF--&gt;      IntPtr punkDocDataExisting,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; IntPtr ppunkDocView,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; IntPtr ppunkDocData,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pbstrEditorCaption,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; Guid pguidCmdUI,&lt;!--CRLF--&gt;      &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; pgrfCDW)&lt;!--CRLF--&gt;    { ... }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Helper methods   &lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; GetService(Type serviceType) { ... }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SimpleEditorFactory&lt;/strong&gt;泛型类接受一个类型参数&lt;strong&gt;TEditorPane&lt;/strong&gt;，这个类型参数继承自&lt;strong&gt;WindowPane&lt;/strong&gt;，而且要实现&lt;strong&gt;IOleCommandTarget&lt;/strong&gt;, &lt;strong&gt;IVsPersistDocData&lt;/strong&gt;和&lt;strong&gt;IPersistFileFormat&lt;/strong&gt;接口。&lt;strong&gt;SimpleEditorFactory&lt;/strong&gt;类还实现了&lt;strong&gt;IVsEditorFactory&lt;/strong&gt;和&lt;strong&gt;IDisposable&lt;/strong&gt;接口。为了方便子类override，我把这个基类里和IVsEditorFactory相关的所有方法都弄成了虚方法。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Visual Studio会调用SetSite方法把Service Provider传递进来：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; SetSite(IOleServiceProvider serviceProvider)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  _ServiceProvider = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ServiceProvider(serviceProvider);&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.S_OK;&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Service Provider传递进来之后，我们就可以利用下面的GetService方法它来访问VS中的服务了：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; GetService(Type serviceType)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _ServiceProvider.GetService(serviceType);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 不过BlogItemEditor这个例子并没有用到GetService这个方法。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dispose方法负责销毁不再用到的资源：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  Dispose(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; disposing)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (disposing)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- Here we dispose all managed and unmanaged resources&lt;/span&gt;&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_ServiceProvider != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;!--CRLF--&gt;    {&lt;!--CRLF--&gt;      _ServiceProvider.Dispose();&lt;!--CRLF--&gt;      _ServiceProvider = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;!--CRLF--&gt;    }&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 除了Dispose之外，我们还需要实现IVsEditorFactory的方法Close方法，在EditorFactory关闭时执行一些清理工作，不过也没什么好清理的：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Close()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.S_OK;&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 下面来说一下Editor的Logic View和Physical View。一个Editor有可能有多个视图，在CreateEditorInstance方法里有一个参数，叫做pszPhysicalView，如果我们的Editor有多个视图的话，我们就应该在根据pszPhysicalView参数的不同，来创建不同的Editor Instance。&lt;strong&gt;MapLogicalView&lt;/strong&gt; 方法的功能就是根据传进来的Logic View的GUID，返回代表Physical View的字符串，这个字符串会被VS当成参数传递到CreateEditorInstance方法中。如果你的Editor有多个逻辑视图，那就可以在&lt;strong&gt;MapLogicalView&lt;/strong&gt; 方法中根据不同的Logic View来返回不同的Physical View，然后在CreateEditorInstance方法中，根据不同的Physical View来创建不同的Editor Instance。由于我到目前还没用到过多视图的Editor，所以对原文作者的这段话理解上有些困难，所以这段英文就不翻译了，原文内容如下：&lt;blockquote style='border:2px solid #EFEFEF;color:#333333;padding:5px 10px;'&gt;&lt;p&gt;&lt;em&gt;Now we arrived to the part of the &lt;strong&gt;IVsEditorFactory&lt;/strong&gt; that does the real work. Before going on, I have to explain ideas not treated yet: the concept of logical view and physical view. When interacting with an editor (or better to imagine a designer) we use concrete instance of a view called physical view. If our designer supports more than one view, those can be grouped into logical categories. For example, our designer could have a view to see the information as text or as code; it may provide a different view while we are debugging. When creating a physical view, the shell offers the possibility to map it to a logical view and retrieve a name for the physical view that can be used as a parameter when creating the physical view instance. This is the role of the &lt;strong&gt;MapLogicalView&lt;/strong&gt; method.&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp; &lt;p&gt;&amp;nbsp;&amp;nbsp; 幸亏这个&lt;strong&gt;BlogItemEditor&lt;/strong&gt;例子只有一个视图，所以暂时不理解也无所谓。SimpleEditorFactory的&lt;strong&gt;MapLogicalView&lt;/strong&gt; 方法如下:&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MapLogicalView(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; Guid logicalView, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; physicalView)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  physicalView = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;; &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (VSConstants.LOGVIEWID_Primary == logicalView)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- Primary view uses null as physicalView&lt;/span&gt;&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.S_OK;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #008000"&gt;// --- You must return E_NOTIMPL for any unrecognized logicalView values&lt;/span&gt;&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.E_NOTIMPL;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 如果参数logicView等于VSConstants.LOGVIEWID_Primary，那就返回&lt;strong&gt;VSConstants.S_OK&lt;/strong&gt;，表示能够识别这个logicView，并且对应的physicalView设置为null，否则返回&lt;strong&gt;E_NOTIMPL&lt;/strong&gt;，表示我们不支持这个logicView。上面这段代码只适用于单视图的Editor，如果Editor有多个视图，那这段代码就得做些调整了。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; physicalView的值会作为参数传递给&lt;strong&gt;CreateEditorInstance&lt;/strong&gt; 方法，该方法的定义如下：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CreateEditorInstance(&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; grfCreateDoc,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pszMkDocument,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pszPhysicalView,&lt;!--CRLF--&gt;  IVsHierarchy pvHier,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;uint&lt;/span&gt; itemid,&lt;!--CRLF--&gt;  IntPtr punkDocDataExisting,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; IntPtr ppunkDocView,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; IntPtr ppunkDocData,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pbstrEditorCaption,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; Guid pguidCmdUI,&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; pgrfCDW)&lt;!--CRLF--&gt;{ ... }&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 各参数的含义如下：&lt;/p&gt;&lt;table style="color: #000000" border="1" cellspacing="0" cellpadding="2" width="831"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;b&gt;参数&lt;/b&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;b&gt;说明&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;grfCreateDoc&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;这个参数表示VS在什么情况下调用的这个方法。&lt;strong&gt;VSConstants&lt;/strong&gt;类中以CEF_打头的字段表示了这个参数值的可能范围。只有&lt;strong&gt;CEF_OPENFILE&lt;/strong&gt; and &lt;strong&gt;CEF_SILENT&lt;/strong&gt;这两个值是合法的。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pszMkDocument&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;表示正在打开的文件的全路径&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pszPhysicalView&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;physical view的名字，它的值是由&lt;strong&gt;MapLogicalView&lt;/strong&gt; 决定的。在我们的例子里，它的值为null。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pvHier&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;&lt;strong&gt;IVsHierarchy&lt;/strong&gt; 对象。例如，它表示我们要打开的文件在solution explorer中对应的节点。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;itemid&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;&lt;strong&gt;IVsHierarchy&lt;/strong&gt; 对象在solution explorer中的id&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;punkDocDataExisting&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;判断DocData是否已经存在。在多视图的Editor中，多个Editor的实例会处理同一个document data。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;ppunkDocView&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;返回创建的document view的指针。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;ppunkDocData&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;返回创建的document data的指针。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pbstrEditorCaption&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;返回创建的document window的标题&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pguidCmdUI&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;返回创建的Editor对应的Command group的GUID。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="115"&gt;&lt;strong&gt;pgrfCWD&lt;/strong&gt;&lt;/td&gt;&lt;td valign="top" width="714"&gt;&lt;p&gt;Flags for CreateDocumentWindow. 不太清楚具体含义，反正这个例子没用到它。&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;CreateEditorInstance&lt;/strong&gt; 方法的实现如下（我省略掉了参数）：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CreateEditorInstance&lt;!--CRLF--&gt;( &lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// ...  &lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- See arguments in the code above&lt;/span&gt;&lt;!--CRLF--&gt;)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Initialize to null&lt;/span&gt;&lt;!--CRLF--&gt;  ppunkDocView = IntPtr.Zero;&lt;!--CRLF--&gt;  ppunkDocData = IntPtr.Zero;&lt;!--CRLF--&gt;  pguidCmdUI = GetType().GUID;&lt;!--CRLF--&gt;  pgrfCDW = 0;&lt;!--CRLF--&gt;  pbstrEditorCaption = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Validate inputs&lt;/span&gt;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((grfCreateDoc &amp;amp; (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.E_INVALIDARG;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (punkDocDataExisting != IntPtr.Zero)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.VS_E_INCOMPATIBLEDOCDATA;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Create the Document (editor)&lt;/span&gt;&lt;!--CRLF--&gt;  TEditorPane newEditor = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TEditorPane();&lt;!--CRLF--&gt;  ppunkDocView = Marshal.GetIUnknownForObject(newEditor);&lt;!--CRLF--&gt;  ppunkDocData = Marshal.GetIUnknownForObject(newEditor);&lt;!--CRLF--&gt;  pbstrEditorCaption = &lt;span style="color: #006080"&gt;""&lt;/span&gt;;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; VSConstants.S_OK;&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 在这个方法的一开始，所有的参数都被初始化成空或者0，除了&lt;strong&gt;pguidCmdUI&lt;/strong&gt;。它的值是&lt;strong&gt;SimpleEditorFactory&lt;/strong&gt; 的子类的GUID，在我们的例子里是&lt;strong&gt;BlogItemEditorFactory&lt;/strong&gt;的GUID。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 然后我们检查&lt;strong&gt;grfCreateDoc&lt;/strong&gt; 参数是不是有效，如果是无效的值，我们就返回&lt;strong&gt;E_INVALIDARG&lt;/strong&gt;。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 同时我们也不接受document data已存在的情况，如果document data不为空，我们就返回&lt;strong&gt;VS_E_INCOMPATIBLEDOCDATA&lt;/strong&gt;。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 最后我们创建了一个TEditorPane类型的实例，由于TEditorPane类型即实现了WindowPane，又实现了IVsPersistDocData，所以它既是document view，又是document data，然后我们用&lt;strong&gt;Marshal.GetIUnknownForObject&lt;/strong&gt; 方法取出它的IUnknow接口，并赋值给参数ppunkDocView和ppunkDocData。&lt;p&gt;&lt;strong&gt;&lt;font color="#1a8bc8"&gt;3 BlogItemEditorData&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 在继续之前，来看一下BlogItemEditor要编辑的数据是什么样子的：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BlogItemEditorData : IXmlPersistable&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _Title;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _Categories;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _Body;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; BlogItemNamespace = &lt;!--CRLF--&gt;    &lt;span style="color: #006080"&gt;"http://www.codeplex.com/LearnVSXNow/BlogItemv1.0"&lt;/span&gt;;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; BlogItemLiteral = &lt;span style="color: #006080"&gt;"BlogItem"&lt;/span&gt;;&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Other contant values used for XMLpersistence&lt;/span&gt;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; XName BlogItemXName = XName.Get(BlogItemLiteral,  &lt;!--CRLF--&gt;    BlogItemNamespace);&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Other readonly fields representing XML elements of the .blit file&lt;/span&gt;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BlogItemEditorData()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;  } &lt;!--CRLF--&gt;    &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BlogItemEditorData(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; categories, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; body)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    _Title = title;&lt;!--CRLF--&gt;    _Categories = categories;&lt;!--CRLF--&gt;    _Body = body;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  // --- Read-write properties omitted&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 读写文件的代码如下：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SaveTo(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Create the root document element&lt;/span&gt;&lt;!--CRLF--&gt;  XElement root = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XElement(BlogItemXName);&lt;!--CRLF--&gt;  XDocument objectDoc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XDocument(root);&lt;!--CRLF--&gt;&amp;nbsp;&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Save document data to XElement and then tofile&lt;/span&gt;&lt;!--CRLF--&gt;  SaveTo(root);&lt;!--CRLF--&gt;  objectDoc.Save(fileName);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&amp;nbsp;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ReadFrom(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileContent = File.ReadAllText(fileName);&lt;!--CRLF--&gt;  XDocument objectDoc = XDocument.Parse(fileContent, &lt;!--CRLF--&gt;    LoadOptions.PreserveWhitespace);&lt;!--CRLF--&gt;&amp;nbsp;&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Check the document element&lt;/span&gt;&lt;!--CRLF--&gt;  XElement root = objectDoc.Element(BlogItemXName);&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (root == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException(&lt;!--CRLF--&gt;      &lt;span style="color: #006080"&gt;"Root '"&lt;/span&gt; + BlogItemLiteral + &lt;span style="color: #006080"&gt;"' element cannot be found."&lt;/span&gt;);&lt;!--CRLF--&gt;   &lt;span style="color: #008000"&gt;// --- Read the document&lt;/span&gt;&lt;!--CRLF--&gt;  ReadFrom(root);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 多亏有&lt;strong&gt;System.XML.Linq&lt;/strong&gt; 命名空间下的新的xml类型&lt;strong&gt;XElement&lt;/strong&gt;，这样代码比用以前的XmlDocument简洁多了：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SaveTo(XElement targetElement)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Create title&lt;/span&gt;&lt;!--CRLF--&gt;  targetElement.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XElement(TitleXName, _Title));&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Create category hierarchy&lt;/span&gt;&lt;!--CRLF--&gt;  XElement categories = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XElement(CategoriesXName);&lt;!--CRLF--&gt;  targetElement.Add(categories);&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] categoryList = _Categories.Split(&lt;span style="color: #006080"&gt;';'&lt;/span&gt;);&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; category &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; categoryList)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; trimmed = category.Trim();&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (trimmed.Length &amp;gt; 0)&lt;!--CRLF--&gt;    {&lt;!--CRLF--&gt;      categories.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XElement(CategoryXName, trimmed));&lt;!--CRLF--&gt;    }&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;span style="color: #008000"&gt;// --- Create the body&lt;/span&gt;&lt;!--CRLF--&gt;  targetElement.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XElement(BodyXName, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XCData(_Body)));&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 同样的，&lt;strong&gt;ReadFrom(XElement)&lt;/strong&gt;方法也很简单，我就不贴它的代码了。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;font color="#1a8bc8"&gt;4 Editor界面：BlogItemEditorControl&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editor的界面是一个UserControl，叫做BlogItemEditorControl，它的样子如下图：&lt;/p&gt;&lt;p&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/20110611182232520.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/201106111822345984.png" width="434" height="288"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BlogItemEditorControl 实现了&lt;strong&gt;ICommonCommandSupport&lt;/strong&gt;：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BlogItemEditorControl : &lt;!--CRLF--&gt;  UserControl, ICommonCommandSupport { ... }&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 不要去google这个&lt;strong&gt;ICommonCommandSupport&lt;/strong&gt;接口，它不是Microsoft的，是我们自己定义的。它包含若干个以&lt;strong&gt;Supports&lt;/strong&gt;开头的bool类型的属性，以及对应的以&lt;strong&gt;Do&lt;/strong&gt;开头的方法，表示是否支持xxx命令，以及在支持的情况下，执行xxx命令。例如我不打算支持&lt;strong&gt;SelectAll&lt;/strong&gt;, &lt;strong&gt;Redo&lt;/strong&gt;和&lt;strong&gt;Undo&lt;/strong&gt;命令：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// --- ICommonCommandSupport implementation&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ICommonCommandSupport.SupportsSelectAll&lt;!--CRLF--&gt;{ get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; } }&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ICommonCommandSupport.SupportsRedo&lt;!--CRLF--&gt;{ get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; } }&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ICommonCommandSupport.SupportsUndo&lt;!--CRLF--&gt;{ get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; } }&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 当控件有选中的文本时，支持Copy和Cut命令：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// --- ICommonCommandSupport implementation&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ICommonCommandSupport.SupportsCopy&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ActiveControlHasSelection; }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;span style="color: #008000"&gt;// ...&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ActiveControlHasSelection&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  get&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    TextBox active = ActiveControl &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TextBox;&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; active == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ? &lt;span style="color: #0000ff"&gt;false&lt;/span&gt; : active.SelectionLength &amp;gt; 0;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 当剪贴板上有文本数据时，支持&lt;strong&gt;Paste&lt;/strong&gt;命令：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// --- ICommonCommandSupport implementation&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ICommonCommandSupport.SupportsPaste&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ActiveCanPasteFromClipboard; }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;span style="color: #008000"&gt;// ...&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ActiveCanPasteFromClipboard&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  get&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    TextBox active = ActiveControl &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TextBox;&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (active != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; Clipboard.ContainsText());&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 下面是执行Copy、Cut、Paste命令的代码：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// --- ICommonCommandSupport implementation&lt;/span&gt;&lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ICommonCommandSupport.DoCopy()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  TextBox active = ActiveControl &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TextBox;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (active != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) active.Copy();&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ICommonCommandSupport.DoCut()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  TextBox active = ActiveControl &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TextBox;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (active != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) active.Cut();&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ICommonCommandSupport.DoPaste()&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  TextBox active = ActiveControl &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TextBox;&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (active != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) active.Paste();&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BlogItemEditorControl中还定义了在BlogItemEditorData和界面控件之间同步的方法：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BlogItemEditorControl : &lt;!--CRLF--&gt;  UserControl,&lt;!--CRLF--&gt;  ICommonCommandSupport&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BlogItemEditorControl()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    InitializeComponent();&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RefreshView(BlogItemEditorData data)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    TitleEdit.Text = data.Title ?? &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty;&lt;!--CRLF--&gt;    CategoriesEdit.Text = data.Categories ?? String.Empty;&lt;!--CRLF--&gt;    BodyEdit.Text = data.Body ?? String.Empty;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RefreshData(BlogItemEditorData data)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    data.Title = TitleEdit.Text;&lt;!--CRLF--&gt;    data.Categories = CategoriesEdit.Text;&lt;!--CRLF--&gt;    data.Body = BodyEdit.Text;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BlogItemEditorControl还剩下一个重要的工作要做：在文本框里改变blog的标题或内容之后，要告诉VS，这个blog数据&amp;#8220;dirty&amp;#8221;了，这样vs才会在Editor窗口上显示一个&amp;#8220;*&amp;#8221;的标记。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 其实告诉vs我们的数据dirty了并不是这个BlogItemEditorControl要负责的事情，但是它需要公开一个事件，并且当blog内容发生改变的时候，触发这个事件。这样使用到这个控件的地方就可以通过这个事件来通知vs了。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 事件定义如下：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler ContentChanged;&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RaiseContentChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ContentChanged != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) ContentChanged.Invoke(sender, e);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ControlContentChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  RaiseContentChanged(sender, e);&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ControlContentChanged&lt;/strong&gt;方法关联到了所有文本框的&lt;strong&gt;TextChanged&lt;/strong&gt;事件，当文本框的内容发生改变时，就会触发这个方法，并进一步触发公开的ContentChanged事件。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;font color="#1a8bc8"&gt;5 BlogItemEditorPane&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 回顾一下上一章中的一张图：&lt;/p&gt;&lt;p&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201106/201106111822379903.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201106/201106111822409709.png" width="498" height="216"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 从上图可以看出，&lt;strong&gt;BlogItemEditorPane&lt;/strong&gt; 既是document data，又是document view。虽然我们分别用&lt;strong&gt;BlogItemEditorData&lt;/strong&gt;和&lt;strong&gt;BlogItemEditorControl&lt;/strong&gt; 类来表示blog的数据和Editor的界面，但&lt;strong&gt;BlogItemEditorPane&lt;/strong&gt;才是能被vs接受的document data和document view，因为它实现了IVsPersistDocData和WindowPane。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 我抽取了一些通用的方法，做了一个基类SimpleEditorPane，并使BlogItemEditorPane继承它，这样BlogItemEditorPane的代码就非常简洁。它的全部代码如下：&lt;/p&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BlogItemEditorPane: &lt;!--CRLF--&gt;  SimpleEditorPane&amp;lt;BlogItemEditorFactory, BlogItemEditorControl&amp;gt;&lt;!--CRLF--&gt;{&lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; BlogItemEditorData _EditorData = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; BlogItemEditorData();&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BlogItemEditorPane()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    UIControl.ContentChanged += DataChangedInView;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetFileExtension()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; HowToPackage.BlogFileExtension; &lt;span style="color: #008000"&gt;// --- &amp;#8220;.blit&amp;#8221;&lt;/span&gt;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; Guid GetCommandSetGuid()&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GuidList.GuidBlogEditorCmdSet;&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadFile(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    _EditorData.ReadFrom(fileName);&lt;!--CRLF--&gt;    UIControl.RefreshView(_EditorData);&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SaveFile(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    UIControl.RefreshData(_EditorData);&lt;!--CRLF--&gt;    _EditorData.SaveTo(fileName);&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;  &lt;!--CRLF--&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DataChangedInView(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;!--CRLF--&gt;  {&lt;!--CRLF--&gt;    OnContentChanged();&lt;!--CRLF--&gt;  }&lt;!--CRLF--&gt;}&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetFileExtension返回我们的Editor支持的文件扩展名".blit".&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetCommandSetGuid返回Editor支持的Command group的GUID。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LoadFile从文件中加载BlogItemEditorData的实例，并显示在BlogItemEditorControl上。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SaveFile从BlogItemEditorControl上取出BlogItemEditorData实例，并保存到文件中。&lt;p&gt;&amp;nbsp; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 下一篇文章我们继续完成这个的编辑器的例子。&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 作者这个&amp;#8220;简单的编辑器&amp;#8221;例子搞的有点复杂了，他抽象出了一个开发自定义编辑器的类库，虽然使用这个类库可以更简单的创建编辑器，但对于我们刚刚开始学习如何创建编辑器的同学们来说，容易被他的类库影响注意力，还不如不要这个类库，直接拿最直接的代码作文示例。 建议把源代码下载下来，结合源代码来理解这个编辑器的系列。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;源码下载： &lt;p&gt;&lt;a href="http://files.cnblogs.com/default/LearnVSXNow-8528.zip" target="_blank"&gt;http://files.cnblogs.com/default/LearnVSXNow-8528.zip&lt;/a&gt;&lt;p&gt;原文链接：&lt;/p&gt;&lt;p&gt;&lt;a title="http://dotneteers.net/blogs/divedeeper/archive/2008/03/14/LearnVSXNowPart16.aspx" href="http://dotneteers.net/blogs/divedeeper/archive/2008/03/14/LearnVSXNowPart16.aspx" target="_blank"&gt;http://dotneteers.net/blogs/divedeeper/archive/2008/03/14/LearnVSXNowPart16.aspx&lt;/a&gt;&lt;/p&gt; &lt;img src="http://www.cnblogs.com/default/aggbug/2078501.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2011/06/11/2078501.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2011/03/15/1985391.html</id><title type="text">对 COM 组件的调用返回了错误 HRESULT E_FAIL。</title><summary type="text">win7系统，用c#调用Interop.SHDocVw.dll时，报了个对“ COM 组件的调用返回了错误 HRESULT E_FAIL”的错误。网上有人说要开启dtc服务，然后去组件服务里把本地DTC设置成开启网络DTC服务，并允许入站和允许出站，并且设置成不要求进行验证，如下图： 但我设置完之后还是不行，后来看到组件服务里的COM+应用程序点开报错，所以又开启了System Event No...</summary><published>2011-03-15T14:01:00Z</published><updated>2011-03-15T14:01:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2011/03/15/1985391.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2011/03/15/1985391.html"/><content type="html">&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; win7系统，用c#调用Interop.SHDocVw.dll时，报了个对“ COM 组件的调用返回了错误 HRESULT E_FAIL”的错误。网上有人说要开启dtc服务，然后去组件服务里把本地DTC设置成开启网络DTC服务，并允许入站和允许出站，并且设置成不要求进行验证，如下图：&lt;/p&gt; &lt;p&gt;&lt;a href="http://images.cnblogs.com/cnblogs_com/default/201103/20110315220052803.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://images.cnblogs.com/cnblogs_com/default/201103/201103152200588017.png" width="627" height="354"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 但我设置完之后还是不行，后来看到组件服务里的COM+应用程序点开报错，所以又开启了System Event Notification Service服务，结果还是不行。&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 无奈之下重启电脑反而好了，又去禁用了DTC，并把DTC的开启网络DTC服务勾掉，又禁用了System Event Notification Service服务，但再也不报错了。&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 时间有限，没去深究，只是记录下来，免得下次再遇到这个问题。&lt;/p&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/1985391.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2011/03/15/1985391.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2011/01/25/1944328.html</id><title type="text">（转）WPF Custom Control Dependency Property Gotcha</title><summary type="text">原文地址：http://geekswithblogs.net/thibbard/archive/2008/04/22/wpf-custom-control-dependency-property-gotcha.aspx Let's say you have a custom WPF control called SearchTextBox. It has a textbox and a butt...</summary><published>2011-01-25T02:23:00Z</published><updated>2011-01-25T02:23:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2011/01/25/1944328.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2011/01/25/1944328.html"/><content type="html">&lt;p&gt;原文地址：&lt;a title="http://geekswithblogs.net/thibbard/archive/2008/04/22/wpf-custom-control-dependency-property-gotcha.aspx" href="http://geekswithblogs.net/thibbard/archive/2008/04/22/wpf-custom-control-dependency-property-gotcha.aspx" target="_blank"&gt;http://geekswithblogs.net/thibbard/archive/2008/04/22/wpf-custom-control-dependency-property-gotcha.aspx&lt;/a&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;Let's say you have a custom WPF control called SearchTextBox.&amp;nbsp; It has a textbox and a button labeled "search".&amp;nbsp; Simple enough, you reuse it in your application when you want to provide search.&amp;nbsp; &lt;p&gt;Then one day, you decide you need this control needs to be bindable.&amp;nbsp; So you expose a public property Text and map it to textSearch just like you would in WinForms. &lt;p&gt;Well, that doesn't work, so you google around and stumble upon Dependency Properties and learn how to create your own (VS snippet shortcut propdb) and create a Text DP. &lt;p&gt;Now you spend 30 minutes trying to map your Text DP to your textSearch.Text until you finally figure out that your DP snippet lead you astray and there is one more step that didn't get included in the shortcut.&amp;nbsp; In the UIPropertyMetaData, you need to specify a function to call when the property changes - so you can set textSearch.Text. &lt;p&gt;The function looks like this: &lt;p&gt;static void textChangedCallBack(DependencyObject property, &lt;br/&gt;   DependencyPropertyChangedEventArgs args)&lt;br/&gt;{&lt;br/&gt;   SearchTextBox searchTextBox = (SearchTextBox)property;&lt;br/&gt;   searchTextBox.textSearch.Text= (string)args.NewValue;&lt;br/&gt;}&lt;/p&gt;&lt;p&gt;And the rest of the DP looks like this:&lt;p&gt;public string Text&lt;br/&gt;{&lt;br/&gt;   get { return (string)GetValue(TextProperty); }&lt;br/&gt;   set { SetValue(TextProperty, value);  }&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;public static readonly DependencyProperty TextProperty =&lt;br/&gt;   DependencyProperty.Register(&lt;br/&gt;   "Text", &lt;br/&gt;   typeof(string), &lt;br/&gt;   typeof(SearchTextBox), &lt;br/&gt;   new UIPropertyMetadata(string.Empty, new PropertyChangedCallback(textChangedCallBack)));&lt;br/&gt;&lt;/p&gt;&lt;p&gt;The important part here is what wasn't created by the VS snippet :&lt;p&gt;new UIPropertyMetadata(string.Empty&lt;strong&gt;, new PropertyChangedCallback(textChangedCallBack)&lt;/strong&gt;)&lt;p&gt;Now you are binding to your custom control and all is good.&lt;/p&gt;&lt;img src="http://www.cnblogs.com/default/aggbug/1944328.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2011/01/25/1944328.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2010/12/12/1903697.html</id><title type="text">.NET应用程序调试总结系列视频（三）：Sysinternals Suite and other tools</title><summary type="text">Sysinternals Suite是微软技术团队开发的一套功能强大的免费工具程序集，包括几十个相互独立的工具，这些工具囊括了文件、进程、磁盘、网络、安全等系统管理的方方面面，而Sysinternals Suite中的工具比系统中集成的类似工具功能更为强大，针对系统的可操作性更灵活。不管是对Windows用户，还是对Windows平台的软件开发者来说，这套工具都能给我们带来极大的帮助。 这次课程的内容如下： Process Explorer ►View -&gt; Lower Pane(DLL, Handles) ►Refresh Rate, Also Press F5 ►Opacity ►</summary><published>2010-12-12T05:56:00Z</published><updated>2010-12-12T05:56:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2010/12/12/1903697.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2010/12/12/1903697.html"/><content type="html">&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sysinternals Suite是微软技术团队开发的一套功能强大的免费工具程序集，包括几十个相互独立的工具，这些工具囊括了文件、进程、磁盘、网络、安全等系统管理的方方面面，而Sysinternals Suite中的工具比系统中集成的类似工具功能更为强大，针对系统的可操作性更灵活。不管是对Windows用户，还是对Windows平台的软件开发者来说，这套工具都能给我们带来极大的帮助。  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 这次课程的内容如下：  &lt;ol&gt; &lt;li&gt;Process Explorer  &lt;p&gt;►View -&amp;gt; Lower Pane(DLL, Handles)  &lt;p&gt;►Refresh Rate, Also Press F5  &lt;p&gt;►Opacity  &lt;p&gt;►Saving  &lt;p&gt;►Shutting Down or logoff  &lt;p&gt;►Run  &lt;p&gt;►Runas  &lt;p&gt;►Run as limited user  &lt;p&gt;►Always on top  &lt;p&gt;►Replace task manager  &lt;p&gt;►Hide when minimized  &lt;p&gt;►Verify Image sigatures  &lt;p&gt;►Config symbols, (Debugging tools)  &lt;p&gt;►System information  &lt;p&gt;►Sorting and Process Tree  &lt;p&gt;►DPCs and Interrupts  &lt;p&gt;►Find Window&amp;#8217;s process  &lt;p&gt;►Process View Options  &lt;p&gt;►Process Context Menu  &lt;p&gt;►Kill  &lt;p&gt;►Kill Process Tree  &lt;p&gt;►Performance  &lt;p&gt;►Performance Graph  &lt;p&gt;►Threads  &lt;p&gt;►Tcp/IP  &lt;p&gt;►Security  &lt;p&gt;►.Net(.net Performance counters)  &lt;p&gt;►Services  &lt;p&gt;►Enviroment  &lt;p&gt;►DLLs  &lt;p&gt;►Handle View  &lt;p&gt;►Searching &lt;/p&gt; &lt;li&gt;Process Monitor  &lt;p&gt;►File, Reg, Process  &lt;p&gt;►Filter  &lt;p&gt;►Find window by process &lt;/p&gt; &lt;li&gt;TcpView  &lt;p&gt;►谁用了我的网络？ &lt;/p&gt; &lt;li&gt;Autoruns  &lt;p&gt;►谁偷摸在我机器上跑了？ &lt;/p&gt; &lt;li&gt;ZoomIt  &lt;p&gt;►幻灯片演示好帮手 &lt;/p&gt; &lt;li&gt;DbgView  &lt;p&gt;►上次讲过。。。 &lt;/p&gt; &lt;li&gt;Performance Monitor  &lt;p&gt;►http://dotnetdebug.net/2005/06/30/perfmon-your-debugging-buddy/ &lt;/p&gt; &lt;li&gt;Snoop  &lt;p&gt;►WPF调试好帮手 &lt;/p&gt; &lt;li&gt;Reflector  &lt;p&gt;►You must know  &lt;p&gt;►IL Code  &lt;p&gt;►Export&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;本次课程下载地址：  &lt;p&gt;视频：&lt;a href="http://public.blu.livefilestore.com/y1pAtX7VUPZVaAH_shiPg_0jIft_fQe17_QNTPz8hjVVFDgFa-2OI_LKenUE8k1QSMiEJ1ICAz6xgo2hSuO8Fgkzg/03%20Sysinternals%20Suite.7z?download&amp;amp;psid=1" target="_blank"&gt;03 Sysinternals Suite.7z&lt;/a&gt;  &lt;p&gt;ppt：&lt;a href="http://public.blu.livefilestore.com/y1pH80Y5cko-4uFkSKXbtLu1XCuQGDn18L4HjYiDgfXADwfuBC4uez83xSHeW0WyrP6eatEXpSXDk3vV1SQ7ByTSw/03%20Sysinternals%20Suite.ppt?download&amp;amp;psid=1" target="_blank"&gt;03 Sysinternals Suite.ppt&lt;/a&gt;  &lt;p&gt;本系列课程：&lt;a href="http://cid-2cd0144b16b3ba5c.office.live.com/browse.aspx/Public/DotNet%20Debugging%20Series" target="_blank"&gt;http://cid-2cd0144b16b3ba5c.office.live.com/browse.aspx/Public/DotNet%20Debugging%20Series&lt;/a&gt;  &lt;p&gt;陈锋博客：&lt;a href="http://fengchen.wordpress.com.cn/2010/11/17/netappdbgsumup/" target="_blank"&gt;http://fengchen.wordpress.com.cn/2010/11/17/netappdbgsumup/&lt;/a&gt;&lt;/p&gt; &lt;img src="http://www.cnblogs.com/default/aggbug/1903697.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2010/12/12/1903697.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/default/archive/2010/11/25/1887339.html</id><title type="text">.NET应用程序调试总结系列视频（二）：VS Debugger Basics</title><summary type="text">锋哥的调试系列视频终于更新了，这一次他给我们介绍了VS调试器最常用的基本功能，并演示了如何使用这些功能。有一部分是C#专用的，但是很多对与C++也非常管用。这次课程的内容如下：DebugViewTracepointsUsing JIT DebuggingBreakpointsWatch WindowImmediate WindowExceptionDebugger Attachvshost.exe...</summary><published>2010-11-25T02:09:00Z</published><updated>2010-11-25T02:09:00Z</updated><author><name>明年我18</name><uri>http://www.cnblogs.com/default/</uri></author><link rel="alternate" href="http://www.cnblogs.com/default/archive/2010/11/25/1887339.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/default/archive/2010/11/25/1887339.html"/><content type="html">&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 锋哥的调试系列视频终于更新了，这一次他给我们介绍了VS调试器最常用的基本功能，并演示了如何使用这些功能。有一部分是C#专用的，但是很多对与C++也非常管用。这次课程的内容如下：&lt;/p&gt;&lt;ol&gt;&lt;li&gt;DebugView&lt;/li&gt;&lt;li&gt;Tracepoints&lt;/li&gt;&lt;li&gt;Using JIT Debugging&lt;/li&gt;&lt;li&gt;Breakpoints&lt;/li&gt;&lt;li&gt;Watch Window&lt;/li&gt;&lt;li&gt;Immediate Window&lt;/li&gt;&lt;li&gt;Exception&lt;/li&gt;&lt;li&gt;Debugger Attach&lt;/li&gt;&lt;li&gt;vshost.exe process(.net dev only)&lt;/li&gt;&lt;li&gt;Debugger Class usage&lt;/li&gt;&lt;li&gt;Debugger attribute(.net only)&lt;/li&gt;&lt;li&gt;Write a Custom Visualizer&lt;/li&gt;&lt;li&gt;*.suo&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;本次课程下载地址：&lt;/p&gt;&lt;p&gt;视频：&lt;a title="http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.7z" href="http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.7z"&gt;http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.7z&lt;/a&gt;&lt;/p&gt;&lt;p&gt;ppt：&lt;a title="http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.ppt" href="http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.ppt"&gt;http://cid-2cd0144b16b3ba5c.office.live.com/self.aspx/Public/DotNet%20Debugging%20Series/02%20VS%20Debugger.ppt&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;系列课程：&lt;a title="http://cid-2cd0144b16b3ba5c.office.live.com/browse.aspx/Public/DotNet%20Debugging%20Series" href="http://cid-2cd0144b16b3ba5c.office.live.com/browse.aspx/Public/DotNet%20Debugging%20Series"&gt;http://cid-2cd0144b16b3ba5c.office.live.com/browse.aspx/Public/DotNet%20Debugging%20Series&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;陈锋博客：&lt;a title="http://fengchen.wordpress.com.cn/2010/11/17/netappdbgsumup/" href="http://fengchen.wordpress.com.cn/2010/11/17/netappdbgsumup/"&gt;http://fengchen.wordpress.com.cn/2010/11/17/netappdbgsumup/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;img src="http://www.cnblogs.com/default/aggbug/1887339.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/default/archive/2010/11/25/1887339.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry></feed>
