﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-ChengKing-文章分类-C#专栏</title><link>http://www.cnitblog.com/ChengKing/category/1234.html</link><description>ChengKing</description><language>zh-cn</language><lastBuildDate>Tue, 04 Oct 2011 21:46:25 GMT</lastBuildDate><pubDate>Tue, 04 Oct 2011 21:46:25 GMT</pubDate><ttl>60</ttl><item><title>生成/读写 Excel文件 </title><link>http://www.cnitblog.com/ChengKing/articles/5012.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:26:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5012.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5012.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5012.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5012.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5012.html</trackback:ping><description><![CDATA[<P>(一).内容</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>&nbsp;&nbsp; 在操作Excel的过程中遇到了一些问题. 比如： 访问Com组件权限，无法读取Excel等<BR>&nbsp;&nbsp; 文章描述了怎样双向操作(读取和生成)Excel文件，以及怎样解决遇到的问题!</P></BLOCKQUOTE>
<P>(二).代码<BR>&nbsp;&nbsp; 开始时用了下面两个方法进行生成和读取 Excel:<BR>&nbsp;&nbsp; 1.生成Excel文件方法一:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' &lt;summary&gt;<BR>&nbsp;&nbsp;&nbsp; '&nbsp; 下载Excel方法1(用流实现)<BR>&nbsp;&nbsp;&nbsp; ' &lt;/summary&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="dt"&gt;要转换为Excel文件的表&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="page"&gt;页面Page对象,用法: 将me.Page传递过来即可&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; Public Sub DownLoadExcelToClient1(ByVal dt As DataTable, ByVal FileName As String)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim resp As HttpResponse<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp = Page.Response<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp.ContentEncoding = System.Text.Encoding.Default </P>
<P>'System.Text.Encoding.GetEncoding("GB2312")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim colHeaders As String = "", ls_item = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Int16 = 0</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '取得数据表各列标题，各标题之间以\t分割，最后一个列标题后加回车符 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To dt.Columns.Count - 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colHeaders += dt.Columns(i).Caption.ToString() &amp; Chr(9)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colHeaders += dt.Columns(i).Caption.ToString() &amp; Chr(13)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '向HTTP输出流中写入取得的数据信息 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp.Write(colHeaders)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim row As DataRow<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '逐行处理数据&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each row In dt.Rows<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '在当前行中，逐列获得数据，数据之间以\t分割，结束时加回车符\n <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To dt.Columns.Count - 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ls_item &amp;= row(i).ToString() &amp; Chr(9)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ls_item &amp;= row(i).ToString() &amp; Chr(13)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '当前行数据写入HTTP输出流，并且置空ls_item以便下行数据&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp.Write(ls_item)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ls_item = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '写缓冲区中的数据到HTTP头文件中 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resp.End()<BR>&nbsp;&nbsp;&nbsp; End Sub<BR>&nbsp;&nbsp; 2.读取Excel文件<BR>&nbsp;&nbsp;&nbsp;&nbsp; ' &lt;summary&gt;<BR>&nbsp;&nbsp;&nbsp; '&nbsp; 读取Excel文件<BR>&nbsp;&nbsp;&nbsp; ' &lt;/summary&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="dt"&gt;要转换为Excel文件的表&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="page"&gt;页面Page对象,用法: 将me.Page传递过来即可&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;return&gt;数据集DataSet&lt;/return&gt;<BR>&nbsp;&nbsp;&nbsp; Public Function ReadExcelFileToDataSet(ByVal strFileName As String) As DataSet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '建立一个专门存放Excel文件的目录<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Directory.Exists(Page.Server.MapPath("ExcelFolder")) = False Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Directory.CreateDirectory(Page.Server.MapPath("ExcelFolder"))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim strConn As String<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" &amp; "Data Source=" &amp; </P>
<P>Page.Server.MapPath(".") &amp; "\ExcelFolder\" &amp; strFileName &amp; ";" &amp; "Extended </P>
<P>Properties=Excel 8.0;"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strConn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim strExcel As String = "select * from [sheet1$]"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ds As DataSet = New DataSet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(strExcel, strConn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adapter.Fill(ds)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return ds<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Throw ex<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try<BR>&nbsp;&nbsp;&nbsp; End Function</P>
<P>&nbsp;&nbsp; 生成是成功的，但读取不成功，提示:"数据源格式有误!" <BR>&nbsp;&nbsp; 一直是认为:ReadExcelFileToDataSet方法有误,调试了半天，找了N多资料也不能成功!<BR>&nbsp;&nbsp; 后来经过"时间的流逝",终久确认第二个方法没有错误，是完全正确的，是第一个方法<BR>&nbsp;&nbsp; 生成格式的问题. 于是我将第一个方法换为下面的方法,读取和写入就OK了.<BR>&nbsp; <BR>&nbsp;3.生成Excel文件方法二: <BR>&nbsp;&nbsp;&nbsp;&nbsp; ' &lt;summary&gt;<BR>&nbsp;&nbsp;&nbsp; '&nbsp; 下载Excel方法2(用office-Excel-Com组件对象实现)<BR>&nbsp;&nbsp;&nbsp; ' &lt;/summary&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="dt"&gt;要转换为Excel文件的表&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; ' &lt;param name="page"&gt;页面Page对象,用法: 将me.Page传递过来即可&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; Public Sub DownLoadExcelToClient2(ByVal dt As DataTable)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '生成Excel操作相关对象<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim xlApp As Excel.Application<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim xlBook As Excel.Workbook<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim xlSheet As Excel.Worksheet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlApp = CType(CreateObject("Excel.Application"), Excel.Application)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'xlSheet.Range("A1:B1").Merge(0) '合并单元格<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'xlSheet.Cells(1, 1) = "员工资料信息:"</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '赋标题(Excel文件中的标题)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim rowIndex As Integer = 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim colIndex As Integer = 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Col As DataColumn<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Row As DataRow<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each Col In dt.Columns<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colIndex = colIndex + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlApp.Cells(rowIndex, colIndex) = Col.ColumnName<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '将表dt的所有行写入xlApp对象(Excel文件中的内容)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each Row In dt.Rows<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rowIndex = rowIndex + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colIndex = 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each Col In dt.Columns<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colIndex = colIndex + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet.Application.Visible = True&nbsp;&nbsp; '置为可见</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '建立一个专门存放Excel文件的目录<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Directory.Exists(Page.Server.MapPath("ExcelFolder")) = False Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Directory.CreateDirectory(Page.Server.MapPath("ExcelFolder"))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '删除服务端临时文件: download.xls<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If File.Exists(Page.Server.MapPath(".") &amp; "\ExcelFolder\download.xls") = True Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File.Delete(Page.Server.MapPath(".") &amp; "\ExcelFolder\download.xls")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '在服务端保存download.xls<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet.SaveAs(Page.Server.MapPath(".") &amp; "\ExcelFolder\download.xls")</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '杀死Excel进程<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myproc As System.Diagnostics.Process = New System.Diagnostics.Process<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim proc As Process<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim procs() As Process = Process.GetProcessesByName("excel")&nbsp;&nbsp; '得到所有打开的进程<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each proc In procs<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not proc.CloseMainWindow() Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proc.Kill()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '这里用到个goto语句,是因为: 线程是异步执行的,下面的代码要访问download.xls文件,但有</P>
<P>少数情况下上面的线程<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '未能及时释放download.xls文件的指针,那么下面代码执行语句时会抛出异常, 当发生异常时</P>
<P>需要等待资源释放后,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '再重新访问该文件, 保证下载文件能够正确下载<BR>again:&nbsp; Try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '输出到客户端()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If File.Exists(Page.Server.MapPath(".") &amp; "\ExcelFolder\download.xls") Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim TargetFile As FileInfo = New FileInfo(Page.Server.MapPath(".") &amp; </P>
<P>"\ExcelFolder\download.xls")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '清除缓冲区流中的所有内容输出.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.Clear()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '向输出流添加HTTP头 [指定下载/保存 对话框的文件名]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" </P>
<P>+ Page.Server.UrlEncode(TargetFile.Name))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '向输出流添加HTTP头 [指定文件的长度,这样下载文件就会显示正确的进度<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.AppendHeader("Content-Length", TargetFile.Length.ToString())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '表明输出的HTTP为流[stream],因此客户端只能下载.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.ContentType = "application/octet-stream"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '发送文件流到客户端.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.WriteFile(TargetFile.FullName)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '停止执行当前页<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page.Response.End()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(10)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GoTo again<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try<BR>&nbsp;&nbsp;&nbsp; End Sub<BR>这说明：<BR>&nbsp;&nbsp;&nbsp; a. 生成Excel文件后，用户经过修改，还要反向读取此Excel文件(比如:反向更新到数据库中)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 就只能用: 3 和 2方法结合使用.&nbsp; <BR>&nbsp;&nbsp;&nbsp; b. 如果只是单向输出Excel文件，用1和2方法都可以. 不过用2的话还要安装Office-Excel,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般还要设置一下Com组件访问权限</P>
<P>(三).不能读取的原因 以及 权限问题解决</P>
<P>&nbsp; a. 原因是:&nbsp; 方法 1 是用流的格式实现的,简单的说它不是真正的Excel格式，而 3 是调用的<BR>&nbsp;&nbsp;&nbsp;&nbsp; Excel Com组件，生成的是真正的Excel文档,所以能读取(1也可以读取，但也要用Stream类读取， </P>
<P>&nbsp;&nbsp;&nbsp; 如果数据有些复杂的话，会很麻烦).&nbsp; 用1和3方法生成的文件及文件图标一模一样，并且用Excel&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp; 应用程序打开后显示效果也是一样的.&nbsp; 但当用记事本分别打开1和3生成的*.xls文件时，就明<BR>&nbsp;&nbsp;&nbsp;&nbsp; 显看到它们的不同了.(您可以下载一下本示例代码程序，分别生成两个文件，对比一下)</P>
<P>&nbsp; b.在使用Excel com组件时除了装Office-Excel以外，一般还要设置一下Com的访问权限，步骤如下:&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; I.如果是Window2003 -&gt;控制面版 -&gt; 管理工具 -&gt; 组件服务 -&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开树级目录找到子目录DCOM配置 -&gt; Microsoft Excel 应用程序 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; 右击选“属性” -&gt; 在弹出对话窗口中选“安全”选项卡-&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; 将启动和激活权限设为自定义-&gt;点击编辑按钮-&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;在新窗口中将Everyone用户加入,选中复选框"启动权限",给予启动权限</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; II.如果是WindowXP -&gt;控制面版 -&gt; 管理工具 -&gt; 组件服务(繁体为"元件服务") -&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开树级目录找到子目录DCOM配置 -&gt; Microsoft Excel 应用程序 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; 右击选“属性” -&gt; 在弹出对话窗口中选“安全”选项卡-&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; 将启动和激活权限设为自定义-&gt;点击编辑按钮-&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;在新窗口中将Everyone用户加入,选中复选框"远程启动",给予远程启动权限<BR>(四).使用Excel模板<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 虽然Com组件功能已经比较全面，可以对任意一个单元格设置和赋值.但是如果数据集DataSet比 </P>
<P>&nbsp;&nbsp; 较复杂的话，全部用Com提供的方法实现就很麻烦了. 尤其是文档头和尾最难处理.<BR>&nbsp;&nbsp;&nbsp; 这时可以这样处理:<BR>&nbsp;&nbsp;&nbsp; a.先用Excel应用程序建立一个Excel文件，设置好头/尾样式和以及所有单元格的布局和格式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (这里就是作用office 家簇的 excel进行表格布局，可以任意操作)&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; b.将此文件保存到工程的一个文夹下面即可.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用法: <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只需将2中的:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 改为:&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlBook = xlApp.Workbooks.Add(page.MapPath(".") + "ExcelTemplate.xls")'使用現有模板<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 即可。 这样xlBook实际上是基于自己创建的模板的.<BR>&nbsp;&nbsp;&nbsp; 这样操作，一般表头和标题列，表尾列一般不用设置，只显示DataSet中的主要数据(甚至也不用显 </P>
<P>&nbsp;&nbsp; 示DataSet列名)</P>
<P>&nbsp;&nbsp;&nbsp; 最近给客户做一些Excel报表,我们是这样做的，直接把客户给的Excel需求文件作为了模板.<BR>&nbsp;&nbsp;&nbsp; 非常简便，更爽的是这样做报表跟客户要求的完全相同。</P>
<P>(五).代码示例下载</P>
<P>&nbsp;&nbsp; <A href="http://www.cnblogs.com/Files/ChengKing/OPExcel.rar"><FONT color=#002c99>http://www.cnblogs.com/Files/ChengKing/OPExcel.rar</FONT></A></P>
<P>&nbsp;此示例在配置环境:&nbsp;&nbsp; WinXP(繁体) VS.net 2002&nbsp;&nbsp;&nbsp;&nbsp;WinXP(简体) Vs.net 2003&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Win2003 VS.net 2003&nbsp; 测试能够正确运行!</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:26 <a href="http://www.cnitblog.com/ChengKing/articles/5012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 主表和子表数据同时在绑定控件显示 </title><link>http://www.cnitblog.com/ChengKing/articles/5011.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:25:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5011.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5011.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5011.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5011.html</trackback:ping><description><![CDATA[<P>(一).显示效果图<BR></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;<A href="http://blog.csdn.net/ChengKing/archive/2005/11/27/538128.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/27/538128.aspx</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>(二)代码</P>
<P>&nbsp;&nbsp; 1.前台界面代码:</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="数据绑定控件同时显示主表和子表数据.WebForm1" %&gt;<BR>&lt;%@ Import Namespace="System.Data" %&gt;<BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" &gt;<BR>&lt;HTML&gt;<BR>&nbsp;&lt;HEAD&gt;<BR>&nbsp;&nbsp;&lt;title&gt;WebForm1&lt;/title&gt;<BR>&nbsp;&nbsp;&lt;meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"&gt;<BR>&nbsp;&nbsp;&lt;meta name="CODE_LANGUAGE" Content="C#"&gt;<BR>&nbsp;&nbsp;&lt;meta name="vs_defaultClientScript" content="JavaScript"&gt;<BR>&nbsp;&nbsp;&lt;meta name="vs_targetSchema" content="<A href="http://schemas.microsoft.com/intellisense/ie5"><FONT color=#002c99>http://schemas.microsoft.com/intellisense/ie5</FONT></A>"&gt;<BR>&nbsp;&lt;/HEAD&gt;<BR>&nbsp;&lt;body MS_POSITIONING="GridLayout"&gt;<BR>&nbsp;&nbsp;&lt;form id="Form1" method="post" runat="server"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;!-- 绑定主表数据 --&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:repeater id="myRepeater" runat="server"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;HeaderTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;table border="0" bgcolor="lightblue"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/HeaderTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ItemTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td style="background-color: lightgray"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;b&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%# DataBinder.Eval(Container.DataItem,"TypeID") %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%# DataBinder.Eval(Container.DataItem,"TypeName") %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/b&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- 绑定子表数据 --&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:repeater id="childRepeater" datasource='&lt;%# ((DataRowView)Container.DataItem)<BR>&nbsp;&nbsp;&nbsp;.Row.GetChildRows("TypeRelation") %&gt;' runat="server"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;itemtemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;table border="0" bgcolor="#ffcc33"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;&amp;nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%# DataBinder.Eval(Container.DataItem,"[\"TypeID\"]") %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%# DataBinder.Eval(Container.DataItem, "[\"TypeDetail\"]")%&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/itemtemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/asp:repeater&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ItemTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;FooterTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/FooterTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/asp:repeater&gt;</P>
<P>&nbsp;&nbsp;&lt;/form&gt;<BR>&nbsp;&lt;/body&gt;<BR>&lt;/HTML&gt;</P></BLOCKQUOTE>
<P dir=ltr>&nbsp; 2. 后代代码</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>&nbsp;using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;</P>
<P>namespace 数据绑定控件同时显示主表和子表数据<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// 数据绑定控件同时显示主表和子表数据<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class WebForm1 : System.Web.UI.Page<BR>&nbsp;{<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Repeater myRepeater;<BR>&nbsp;&nbsp;private void Page_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;DataSet ds = new DataSet();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//1.构造主表<BR>&nbsp;&nbsp;&nbsp;DataTable dtTypeParent=new DataTable();<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.Columns.Add(new DataColumn("TypeID",typeof(int)));<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.Columns.Add(new DataColumn("TypeName",typeof(string)));<BR>&nbsp;&nbsp;&nbsp;//给主表添加两条记录<BR>&nbsp;&nbsp;&nbsp;DataRow drParent1 = dtTypeParent.NewRow();<BR>&nbsp;&nbsp;&nbsp;drParent1["TypeID"] = 1;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drParent1["TypeName"] = "水果";&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.Rows.Add(drParent1);<BR>&nbsp;&nbsp;&nbsp;DataRow drParent2 = dtTypeParent.NewRow();<BR>&nbsp;&nbsp;&nbsp;drParent2["TypeID"] = 2;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drParent2["TypeName"] = "玩具";<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.Rows.Add(drParent2);<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.TableName="TypeParent";&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;dtTypeParent.PrimaryKey = new DataColumn[] {dtTypeParent.Columns["TypeID"]};<BR>&nbsp;&nbsp;&nbsp;ds.Tables.Add(dtTypeParent);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//2.构造子表<BR>&nbsp;&nbsp;&nbsp;DataTable dtTypeChild=new DataTable();<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Columns.Add(new DataColumn("TypeID",typeof(int)));<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Columns.Add(new DataColumn("TypeDetail",typeof(string)));<BR>&nbsp;&nbsp;&nbsp;//给子表添加五条记录<BR>&nbsp;&nbsp;&nbsp;DataRow drChild1 = dtTypeChild.NewRow();<BR>&nbsp;&nbsp;&nbsp;drChild1["TypeID"] = 1;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drChild1["TypeDetail"] = "苹果";&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Rows.Add(drChild1);<BR>&nbsp;&nbsp;&nbsp;DataRow drChild2 = dtTypeChild.NewRow();<BR>&nbsp;&nbsp;&nbsp;drChild2["TypeID"] = 1;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drChild2["TypeDetail"] = "桔子";&nbsp;<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Rows.Add(drChild2);<BR>&nbsp;&nbsp;&nbsp;DataRow drChild3 = dtTypeChild.NewRow();<BR>&nbsp;&nbsp;&nbsp;drChild3["TypeID"] = 1;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drChild3["TypeDetail"] = "香蕉";<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Rows.Add(drChild3);<BR>&nbsp;&nbsp;&nbsp;DataRow drChild4 = dtTypeChild.NewRow();<BR>&nbsp;&nbsp;&nbsp;drChild4["TypeID"] = 2;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drChild4["TypeDetail"] = "机器人";<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Rows.Add(drChild4);<BR>&nbsp;&nbsp;&nbsp;DataRow drChild5 = dtTypeChild.NewRow();<BR>&nbsp;&nbsp;&nbsp;drChild5["TypeID"] = 2;&nbsp; <BR>&nbsp;&nbsp;&nbsp;drChild5["TypeDetail"] = "小汽车";<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.Rows.Add(drChild5);<BR>&nbsp;&nbsp;&nbsp;dtTypeChild.TableName="TypeChild";&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;ds.Tables.Add(dtTypeChild);</P>
<P>&nbsp;&nbsp;&nbsp;ds.Relations.Add("TypeRelation",<BR>&nbsp;&nbsp;&nbsp;&nbsp;ds.Tables["TypeParent"].Columns["TypeID"],<BR>&nbsp;&nbsp;&nbsp;&nbsp;ds.Tables["TypeChild"].Columns["TypeID"]);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;myRepeater.DataSource = ds.Tables["TypeParent"];<BR>&nbsp;&nbsp;&nbsp;Page.DataBind();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P><BR>&nbsp;&nbsp;#region Web 窗体设计器生成的代码<BR>&nbsp;&nbsp;override protected void OnInit(EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();<BR>&nbsp;&nbsp;&nbsp;base.OnInit(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Page_Load);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion<BR>&nbsp;}<BR>}<BR></P></BLOCKQUOTE>
<P dir=ltr>(三).示例下载</P>
<P dir=ltr>&nbsp;&nbsp;&nbsp; <A href="http://www.cnblogs.com/Files/ChengKing/DataRalationDisplay.rar"><FONT color=#002c99>http://www.cnblogs.com/Files/ChengKing/DataRalationDisplay.rar</FONT></A></P>
<P>&nbsp;&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:25 <a href="http://www.cnitblog.com/ChengKing/articles/5011.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 自定义DataGrid翻页按钮</title><link>http://www.cnitblog.com/ChengKing/articles/5010.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:23:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5010.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5010.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5010.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5010.html</trackback:ping><description><![CDATA[<P>(一).显示截图效果</P>
<P>&nbsp;&nbsp; <A href="http://blog.csdn.net/ChengKing/archive/2005/11/20/533551.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/20/533551.aspx</A></P>
<P>(二).代码</P>
<P>&nbsp;&nbsp; 1. *.aspx文件代码</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="New_DataGrid自定义分页按钮.WebForm1" %&gt;<BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" &gt;<BR>&lt;HTML&gt;<BR>&nbsp;&lt;HEAD&gt;<BR>&nbsp;&nbsp;&lt;title&gt;WebForm1&lt;/title&gt;<BR>&nbsp;&nbsp;&lt;meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"&gt;<BR>&nbsp;&nbsp;&lt;meta name="CODE_LANGUAGE" Content="C#"&gt;<BR>&nbsp;&nbsp;&lt;meta name="vs_defaultClientScript" content="JavaScript"&gt;<BR>&nbsp;&nbsp;&lt;meta name="vs_targetSchema" content="<A href="http://schemas.microsoft.com/intellisense/ie5"><FONT color=#002c99>http://schemas.microsoft.com/intellisense/ie5</FONT></A>"&gt;<BR>&nbsp;&lt;/HEAD&gt;<BR>&nbsp;&lt;body MS_POSITIONING="GridLayout"&gt;<BR>&nbsp;&nbsp;&lt;form id="Form1" method="post" runat="server"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;FONT face="宋体"&gt;&lt;/FONT&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 160px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Width="768px" AllowPaging="True"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;HeaderStyle BackColor="#999900"&gt;&lt;/HeaderStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;PagerStyle NextPageText="下一页" PrevPageText="上一页" Mode="NumericPages"&gt;&lt;/PagerStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/asp:datagrid&gt;<BR>&nbsp;&nbsp;&lt;/form&gt;<BR>&nbsp;&lt;/body&gt;<BR>&lt;/HTML&gt;</P>
<P>&nbsp;2. *.cs代码文件</P>
<P>&nbsp;&nbsp;&nbsp; using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;</P>
<P>namespace New_DataGrid自定义分页按钮<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// DataGrid自定义分页按钮<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class WebForm1 : System.Web.UI.Page<BR>&nbsp;{<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.DataGrid DataGrid1;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;private void Page_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;if(!Page.IsPostBack)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;GetData();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 生成数据<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.BindData();&nbsp; // 绑定数据到DataGrid&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 生成数据<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void GetData()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;DataTable table = new DataTable();<BR>&nbsp;&nbsp;&nbsp;DataColumnCollection columns = table.Columns;</P>
<P>&nbsp;&nbsp;&nbsp;//定义结构<BR>&nbsp;&nbsp;&nbsp;columns.Add("学号",typeof(System.Int32));<BR>&nbsp;&nbsp;&nbsp;columns.Add("分数",typeof(System.Int32));&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;Random myRandom = new Random();<BR>&nbsp;&nbsp;&nbsp;int intScore = 0;<BR>&nbsp;&nbsp;&nbsp;for(int i = 1;i &lt; 101; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;intScore = myRandom.Next(100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;DataRow drNew = table.NewRow();<BR>&nbsp;&nbsp;&nbsp;&nbsp;drNew[0] = i.ToString();<BR>&nbsp;&nbsp;&nbsp;&nbsp;drNew[1] = intScore.ToString();<BR>&nbsp;&nbsp;&nbsp;&nbsp;table.Rows.Add(drNew);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;this.ViewState.Add("table",table);&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 绑定DataGrid<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void BindData()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;DataTable table = (DataTable)this.ViewState["table"];<BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.DataSource = table;<BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.DataBind();<BR>&nbsp;&nbsp;}&nbsp;&nbsp;<BR>&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;#region Web 窗体设计器生成的代码<BR>&nbsp;&nbsp;override protected void OnInit(EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();<BR>&nbsp;&nbsp;&nbsp;base.OnInit(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Page_Load);<BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.ItemCreated +=new DataGridItemEventHandler(DataGrid1_ItemCreated);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = e.NewPageIndex;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = 0;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;this.BindData();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;System.Web.UI.WebControls.ListItemType elemType = e.Item.ItemType;<BR>&nbsp;&nbsp;&nbsp;if (elemType == System.Web.UI.WebControls.ListItemType.Pager) <BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;TableCell pager = (TableCell) e.Item.Controls[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (int i=0; i&lt;pager.Controls.Count; i+=2) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object o = pager.Controls[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (o is LinkButton) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LinkButton h = (LinkButton) o;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h.Text = " " + h.Text + " "; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Label l = (Label) o;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l.Text = String.Format("&lt;font color='red'&gt;[第{0}页]&lt;/font&gt;", l.Text); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;&nbsp;<BR>}<BR></P>
<P>(三).源代码下载(创建虚拟目录后就可以直接运行)</P>
<P><A href="http://www.cnblogs.com/Files/ChengKing/自定义分页example.rar"><FONT color=#002c99>&nbsp;&nbsp;&nbsp; http://www.cnblogs.com/Files/ChengKing/自定义分页example.rar</FONT></A></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:23 <a href="http://www.cnitblog.com/ChengKing/articles/5010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浅谈 接口(Interface)的作用</title><link>http://www.cnitblog.com/ChengKing/articles/5008.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:22:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5008.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5008.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5008.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5008.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5008.html</trackback:ping><description><![CDATA[<P>&nbsp;继承"基类"跟继承"接口"都能实现某些相同的功能，但有些接口能够完成的功能是只用基类无法实现的<BR>&nbsp;<BR>1.接口用于描述一组类的公共方法/公共属性. 它不实现任何的方法或属性，只是告诉继承它的类<BR>《至少》要实现哪些功能,继承它的类可以增加自己的方法. </P>
<P>2.使用接口可以使继承它的类: 命名统一/规范,易于维护.比如:&nbsp; 两个类 "狗"和"猫",如果它<BR>们都继承了接口"动物",其中动物里面有个方法Behavior(),那么狗和猫必须得实现Behavior()方法，<BR>并且都命名为Behavior这样就不会出现命名太杂乱的现象.如果命名不是Behavior()，接口会约束<BR>即不按接口约束命名编译不会通过.</P>
<P>3.提供永远的接口。 当类增加时，现有接口方法能够满足继承类中的大多数方法，没必要<BR>&nbsp; 重新给新类设计一组方法，也节省了代码，提高了开发效率.<BR>&nbsp; 举个代码示例:<BR>&nbsp; <BR>&nbsp; //公共接口: "动物"<BR>&nbsp; public Interface IAnimal<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int EyeNumber;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Behavior();&nbsp; //行为方法，描述各种动物的特性<BR>&nbsp; }</P>
<P>&nbsp; //类: 狗<BR>&nbsp; public Dog : IAnimal<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ActiveTime = "白天";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Behavior()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write("我晚上睡觉,白天活动");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; //类: 猫<BR>&nbsp; public Cat: IAnimal<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ActiveTime = "夜晚";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Behavior()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write("我白天睡觉,晚上活动");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P><BR>&nbsp; //简单的应用:<BR>&nbsp; public static Main()<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dog myDog = new Dog();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDog.Behavior();&nbsp;&nbsp; //输出: "我晚上睡觉,白天活动"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cat myCat = new Cat();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myCat.Behavior();&nbsp;&nbsp; //输出: "我白天睡觉,晚上活动"<BR>&nbsp; }<BR>&nbsp; 以上调用不同的类的相同名方法，会输出不同的东东，也就是说每个类里面的同名方法完成的<BR>&nbsp; 功能可以是完全不同的.</P>
<P> </P>
<P>&nbsp; 更进一步，不是用上面Main方法这样一个一个调用类的方法，用多态性实现其调用.<BR>&nbsp; 看一下下面这个方法:<BR>&nbsp; public Behavior(IAnimal myIanimal)<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myIanimal.Behavior();<BR>&nbsp; }</P>
<P>&nbsp; 其参数是&lt;&lt;接口类型&gt;&gt;，任何继承它的类都可以调用此方法，此方法能根据类的不同调用不同的类<BR>&nbsp; 中的方法. 也即能够自己根据不同的类，完成不同的类的功能.<BR>&nbsp; 多态性代码示例:&nbsp; <BR>&nbsp; Dog myDog = new Dog();<BR>&nbsp; Cat myCat = new Cat();<BR>&nbsp; Behavior(myDog);&nbsp; //Behavior接受“狗”类实例<BR>&nbsp; Behavior(myCat);&nbsp; //Behavior接受“狗”类实例</P>
<P>&nbsp; 这样Behavior方法写一次就能完成所有继承它的类中的相同名方法的不同功能. 非常方便，</P>
<P>&nbsp; 同样，由于“动物软件”功能需求，需要再增加一个"龟"类:<BR>&nbsp; //类: 龟<BR>&nbsp; public Tortoise: IAnimal<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ActiveTime = "很难说";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Behavior()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write("我可以不活动，一睡就睡五千年!");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }<BR>&nbsp; 那么也可以调用上面多态方法，所以说接口使方法具有较好扩展性.<BR>&nbsp; 如果继承它的类很多的话，有多少好处是可想而知的!</P>
<P><BR>&nbsp; 上面是个人对接口某些方面的一些认识,当然接口的作用不只是这些.<BR>&nbsp; 不对的地方请读者批评指正!<BR>&nbsp; <BR>&nbsp; </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5008.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:22 <a href="http://www.cnitblog.com/ChengKing/articles/5008.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study-&gt;自定义DataGrid翻页控件</title><link>http://www.cnitblog.com/ChengKing/articles/5009.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:22:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5009.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5009.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5009.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5009.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5009.html</trackback:ping><description><![CDATA[<P>(一)说明</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般情况下,使用DataGrid自带的翻页按钮就能够实现所有翻页操作了，但有时候想定制自己的翻页样式</P>
<P>&nbsp;&nbsp;&nbsp; 或美化其显示效果，这时可以自已写个翻页用户控件.</P>
<P>(二).显示效果载图</P>
<P>&nbsp;&nbsp;&nbsp; <A href="http://blog.csdn.net/ChengKing/archive/2005/11/20/533539.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/20/533539.aspx</A></P>
<P>&nbsp;&nbsp;(三)代码</P>
<P>&nbsp;&nbsp; 1.*.aspx代码文件:</P>
<P>&nbsp;&nbsp;&nbsp; &lt;%@ Page language="c#" Codebehind="DGCustomerPagination.aspx.cs" AutoEventWireup="false" Inherits="New_DataGrid自定义分页事件.WebForm1" %&gt;<BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" &gt;<BR>&lt;HTML&gt;<BR>&nbsp; &lt;HEAD&gt;<BR>&nbsp;&nbsp;&lt;title&gt;WebForm1&lt;/title&gt;<BR>&nbsp;&nbsp;&lt;meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"&gt;<BR>&nbsp;&nbsp;&lt;meta content="C#" name="CODE_LANGUAGE"&gt;<BR>&nbsp;&nbsp;&lt;meta content="JavaScript" name="vs_defaultClientScript"&gt;<BR>&nbsp;&nbsp;&lt;meta content="<A href="http://schemas.microsoft.com/intellisense/ie5"><FONT color=#002c99>http://schemas.microsoft.com/intellisense/ie5</FONT></A>" name="vs_targetSchema"&gt;<BR>&nbsp; &lt;/HEAD&gt;<BR>&nbsp;&lt;body MS_POSITIONING="GridLayout"&gt;<BR>&nbsp;&nbsp;&lt;form id="Form1" method="post" runat="server"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 160px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Width="768px" AllowPaging="True"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;HeaderStyle BackColor="#999900"&gt;&lt;/HeaderStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;PagerStyle NextPageText="下一页" PrevPageText="上一页" Mode="NumericPages"&gt;&lt;/PagerStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/asp:datagrid&gt;&lt;asp:linkbutton id="lbLastPage" style="Z-INDEX: 105; LEFT: 808px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;onclick="ChangePageClick" runat="server" CommandArgument="last"&gt;最后页&lt;/asp:linkbutton&gt;&lt;asp:linkbutton id="lbNextPage" style="Z-INDEX: 104; LEFT: 744px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;onclick="ChangePageClick" runat="server" CommandArgument="next"&gt;下一页&lt;/asp:linkbutton&gt;&lt;asp:linkbutton id="lbPrevPage" style="Z-INDEX: 103; LEFT: 680px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;onclick="ChangePageClick" runat="server" CommandArgument="prev"&gt;上一页&lt;/asp:linkbutton&gt;&lt;asp:linkbutton id="lbFirstPage" style="Z-INDEX: 102; LEFT: 616px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;onclick="ChangePageClick" runat="server" CommandArgument="first"&gt;最前页&lt;/asp:linkbutton&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:Label id="lblDisplayPosition" style="Z-INDEX: 106; LEFT: 240px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Width="64px"&gt;&lt;/asp:Label&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:TextBox id="txtSelectPage" style="Z-INDEX: 107; LEFT: 360px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Width="104px"&gt;&lt;/asp:TextBox&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:Button id="btnSelectPage" style="Z-INDEX: 108; LEFT: 472px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Text="确定"&gt;&lt;/asp:Button&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:Label id="lblError" style="Z-INDEX: 109; LEFT: 520px; POSITION: absolute; TOP: 120px"<BR>&nbsp;&nbsp;&nbsp;&nbsp;runat="server" Width="88px"&gt;Label&lt;/asp:Label&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;asp:Label id="lbTotal" style="Z-INDEX: 110; LEFT: 104px; POSITION: absolute; TOP: 120px" runat="server"<BR>&nbsp;&nbsp;&nbsp;&nbsp;Width="136px"&gt;&lt;/asp:Label&gt;&lt;/form&gt;<BR>&nbsp;&lt;/body&gt;<BR>&lt;/HTML&gt;</P>
<P></P>
<P>&nbsp; 2.*.aspx.cs代码文件</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR>using System.Data.SqlClient;</P>
<P>namespace New_DataGrid自定义分页事件<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// DataGrid自定义分页<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class WebForm1 : System.Web.UI.Page<BR>&nbsp;{<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.DataGrid DataGrid1;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.LinkButton lbLastPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.LinkButton lbNextPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.LinkButton lbPrevPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.LinkButton lbFirstPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Label lblDisplayPosition;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Button btnSelectPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.TextBox txtSelectPage;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Label lblError;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Button Button1;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;protected System.Web.UI.WebControls.Label lbTotal;&nbsp; //显示记录总数<BR>&nbsp;&nbsp;private static int intRecord = 0;&nbsp;&nbsp; //显示总记录数<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;private void Page_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.lblError.Text = "";&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;if(!Page.IsPostBack)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;GetData();&nbsp; // 生成数据<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.BindData();&nbsp; //绑定数据到DataGrid<BR>&nbsp;&nbsp;&nbsp;&nbsp;DisPlayStats();&nbsp;&nbsp; //显示这样的表示: 2/100&nbsp; 意思是:共100页，当前为第二页<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 生成数据<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void GetData()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;DataTable table = new DataTable();<BR>&nbsp;&nbsp;&nbsp;DataColumnCollection columns = table.Columns;</P>
<P>&nbsp;&nbsp;&nbsp;//定义结构<BR>&nbsp;&nbsp;&nbsp;columns.Add("学号",typeof(System.Int32));<BR>&nbsp;&nbsp;&nbsp;columns.Add("分数",typeof(System.Int32));&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;Random myRandom = new Random();<BR>&nbsp;&nbsp;&nbsp;int intScore = 0;<BR>&nbsp;&nbsp;&nbsp;for(int i = 1;i &lt; 101; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;intScore = myRandom.Next(100);<BR>&nbsp;&nbsp;&nbsp;&nbsp;DataRow drNew = table.NewRow();<BR>&nbsp;&nbsp;&nbsp;&nbsp;drNew[0] = i.ToString();<BR>&nbsp;&nbsp;&nbsp;&nbsp;drNew[1] = intScore.ToString();<BR>&nbsp;&nbsp;&nbsp;&nbsp;table.Rows.Add(drNew);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;this.ViewState.Add("table",table);</P>
<P>&nbsp;&nbsp;&nbsp;intRecord = table.Rows.Count;<BR>&nbsp;&nbsp;&nbsp;this.lbTotal.Text = "总共:"+intRecord.ToString()+"条记录";<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 绑定DataGrid<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void BindData()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;DataTable table = (DataTable)this.ViewState["table"];<BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.DataSource = table;<BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.DataBind();</P>
<P>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 自定义控件按钮事件<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;/// &lt;param name="sender"&gt;&lt;/param&gt;<BR>&nbsp;&nbsp;/// &lt;param name="e"&gt;&lt;/param&gt;<BR>&nbsp;&nbsp;public void ChangePageClick(object sender, EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;string CommandName = ((LinkButton)sender).CommandArgument.ToString();<BR>&nbsp;&nbsp;&nbsp;switch(CommandName)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "next":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (DataGrid1.CurrentPageIndex &lt; DataGrid1.PageCount - 1 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataGrid1.CurrentPageIndex += 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "prev":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (DataGrid1.CurrentPageIndex &gt; 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataGrid1.CurrentPageIndex -= 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "last":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataGrid1.CurrentPageIndex = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;DisPlayStats();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;public void DisPlayStats()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.lblDisplayPosition.Text = (DataGrid1.CurrentPageIndex + 1).ToString() + "/";<BR>&nbsp;&nbsp;&nbsp;this.lblDisplayPosition.Text += DataGrid1.PageCount.ToString();<BR>&nbsp;&nbsp;&nbsp;this.txtSelectPage.Text = (DataGrid1.CurrentPageIndex + 1).ToString();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Web 窗体设计器生成的代码<BR>&nbsp;&nbsp;override protected void OnInit(EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();<BR>&nbsp;&nbsp;&nbsp;base.OnInit(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);<BR>&nbsp;&nbsp;&nbsp;this.btnSelectPage.Click += new System.EventHandler(this.btnSelectPage_Click);<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Page_Load);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = e.NewPageIndex;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = 0;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;this.BindData();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void btnSelectPage_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;int intPage = 0;<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;intPage = int.Parse(this.txtSelectPage.Text);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.lblError.Text = "只能输入数字!";&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = intPage-1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.BindData();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.DataGrid1.CurrentPageIndex = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.BindData();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.lblError.Text = "超出页码范围!";&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;DisPlayStats();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}<BR></P>
<P>(四).示例源代码下载(可以直接运行)</P>
<P>&nbsp;&nbsp;&nbsp;<A href="http://www.cnblogs.com/Files/ChengKing/自定义分页example.rar"><FONT color=#002c99>&nbsp;</FONT><FONT color=#000080>http://www.cnblogs.com/Files/ChengKing/<STRONG><FONT color=#002c99>自定义分页example.rar</FONT></STRONG></FONT></A></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5009.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:22 <a href="http://www.cnitblog.com/ChengKing/articles/5009.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(三)ComponentOne之WebChart(折线图) </title><link>http://www.cnitblog.com/ChengKing/articles/5006.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:21:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5006.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5006.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5006.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5006.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5006.html</trackback:ping><description><![CDATA[<P>&nbsp;折线图<BR>（一）.配置</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.安装好ComponentOne软件.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.建立一个WEB应用程序项目，名称为: 饼图示例</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.将ComponentOne软件自带的控件集DLL文件(不一定全部，只把需要的一部分)拷贝到自己刚建的</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项目TextChart的Bin目录下面 (这里要手动放的原因是ComponentOne有时会找不到Dll)&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.双击项目里任何一个*.aspx文件，打开设计界面。 打开工具栏，在工具栏空白处右击，选“添加/删除”</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项,打开自定义控件窗口，在.net frame 组件选项卡下选择ComponentOne相应的组件，如果有清楚，</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 就将所有的C1开头的全部勾选，点“确定按钮".&nbsp; 则ComponentOne的控件就显示在工具箱里面了&nbsp; :)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5. 到了这一步，就可以将ComponentOne控件像一般控件一样直接拖动使用了. 拖C1WebChart控件到</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 窗体页面上.&nbsp; 然后右击控件，选 "Chart wizard..."就可以为其设置显示的样式(饼图/柱状图/折线图等)和</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 属性了，用法跟一般控件差不多。(除了用设计器设置外，请看下面（二）</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 还可以代码用代码设置)</P>
<P>(二) . 代码部分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 折线图的实现方法<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChart;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //命名空间，必需加入,否则找不到里面的类和方法等<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChartBase;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Win.C1Chart;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected C1.Web.C1WebChart.C1WebChart C1WebChart1;&nbsp;&nbsp; // 控件声明</P>
<P></P>
<P></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 主要属性</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Header.Text="Chart 头";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表头标题<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Footer.Text="Chart 尾";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表尾文本<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.BackColor = Color.LightSteelBlue;&nbsp;&nbsp;&nbsp;&nbsp; //背景色<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;&nbsp; //图像存储格式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.XYPlot;&nbsp;&nbsp; //图表</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 类型,Chart2DTypeEnum枚举下有所有的图表样式，如饼图/柱状图等</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Width=800;&nbsp;&nbsp;&nbsp;&nbsp; //图表区域宽度</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 主要方法 ((示例折线图显示一个班级每个同学的：语文/数学/英语成绩))</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a .X轴标签(坐标)的方法，直接调用即可</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void AddAxisX()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // label x axis with product names<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Axis ax = C1WebChart1.ChartArea.AxisX;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.ValueLabels.Clear();&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; 100; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //DataRowView drv = dv[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.ValueLabels.Add(i, (i+1).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.Max = 10 - .5;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch {}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b .Y轴标签(坐标)的方法，直接调用即可</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void AddAxisY()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // label y axis with product names<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Axis ay = C1WebChart1.ChartArea.AxisY;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.ValueLabels.Clear();&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; 10; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //DataRowView drv = dv[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.ValueLabels.Add(i, (50*i).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.Max = 20 - .5;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch {}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c.画折线图的核心方法<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void GetLine_Plot()&nbsp;&nbsp; //方法中ds中存放了字段： 语文成绩/数学成绩/英语成绩/姓名 字段<BR>&nbsp;&nbsp;{&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//折线图<BR>&nbsp;&nbsp;&nbsp;//清除现有的折线图<BR>&nbsp;&nbsp;&nbsp;ChartDataSeriesCollection dscoll = C1WebChart1.ChartGroups[0].ChartData.SeriesList;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;dscoll.Clear();</P>
<P>&nbsp;&nbsp;&nbsp;int intOperatersNum = ds.Tables[0].Rows.Count;<BR>&nbsp;&nbsp;&nbsp;PointF[][] data = new PointF[3][];<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;for(int i =0;i &lt; 3; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;data[i] = new PointF[intOperatersNum];<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//语文成绩<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; intOperatersNum; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((ds.Tables[0].Rows[i]["语文成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[0][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[0][i] = new PointF(i, 0);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//数学成绩<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; intOperatersNum; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((ds.Tables[0].Rows[i]["数学成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[1][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[1][i] = new PointF(i, 0);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//英语成绩<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; intOperatersNum; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((ds.Tables[0].Rows[i]["英语成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[2][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[2][i] = new PointF(i, 0);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;for(int i=0; i &lt; 3; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ChartDataSeries series = dscoll.AddNewSeries();<BR>&nbsp;&nbsp;&nbsp;&nbsp;series.PointData.Length = intOperatersNum;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;series.PointData.CopyDataIn(data[i]);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;series.LineStyle.Thickness = 1;&nbsp;&nbsp; //厚度<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[0].Label = "语文成绩";<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[1].Label = "数学成绩";<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[2].Label = "英语成绩";</P>
<P>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[0].LineStyle.Color = Color.Blue;<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[1].LineStyle.Color = Color.Yellow;<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[2].LineStyle.Color = Color.Red;</P>
<P><BR>&nbsp;&nbsp;&nbsp;//显示姓名<BR>&nbsp;&nbsp;&nbsp;Axis ax = C1WebChart1.ChartArea.AxisX;<BR>&nbsp;&nbsp;&nbsp;ax.ValueLabels.Clear();&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; intOperatersNum; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ax.ValueLabels.Add(i, ds.Tables[0].Rows[i]["姓名"].ToString());<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;//ax.Max = Convert.ToSingle(intPeopleNum - .5);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch {}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;}</P>
<P></P>
<P>运行效果《类似》请看链接:<BR><A href="http://blog.csdn.net/ChengKing/archive/2005/11/15/529852.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/15/529852.aspx</A></P>
<P>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5006.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:21 <a href="http://www.cnitblog.com/ChengKing/articles/5006.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>谈谈HtmlControl与WebControl的区别及各自的用场</title><link>http://www.cnitblog.com/ChengKing/articles/5007.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:21:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5007.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5007.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5007.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5007.html</trackback:ping><description><![CDATA[<P>Web控件和Html控件虽然好多功能相同并且长得很像<BR>但是它们的内部实现机制是完全不一样的<BR>Web控件要比Html控件执行效率要好</P>
<P>1. 使用起来也相当方便,举个简单的例子,例如Button的生成:<BR>Html控件是将庞大控件集合全部弄到页面中，用到哪个功能，就设置一下属性,如下:<BR>&lt;input type=submit/button runat=server&gt;&nbsp;&nbsp; <BR>这样会占用相当大的控件资源</P>
<P>Web控件是将集成式的拆解成单功能的：<BR>&lt;asp:button id="btnOK" /&gt;<BR>这样就可以节省不必要的控件所占用的资源了</P>
<P>2.Web控件具有回送功能,能够用ViewState维持控件的状态.<BR>&nbsp; Html控件则不能,当点击页面的操作，其状态就会丢失.<BR>&nbsp; 可以做这样的一个实验:<BR>&nbsp; I. 分别建立两个文件:&nbsp; a.html&nbsp; b.aspx<BR>&nbsp; II.在a.html页面中加Html控件的RadioButton和一个button，<BR>&nbsp;&nbsp;&nbsp;&nbsp; 在b.aspx中加Web控件的RadioButton和一个button<BR>&nbsp; III.a.html直接双击浏览器运行,b.aspx通过IIS运行<BR>&nbsp; IV.在a.html运行界面中，选中RadioButton,再单击Button按钮，会发现RadioButton会<BR>&nbsp;&nbsp; 取消选中(丢失其状态),但在b.aspx页面执行同样的操作，RadioButton不会丢失，因为ViewState<BR>&nbsp;&nbsp; 给它保存了状态. 您可以在运行界面点击浏览器菜单"查看"-&gt;“源文件",打开Html代码文件，<BR>&nbsp;&nbsp; 找到加密后的ViewState,类似于下面:<BR>&nbsp;&nbsp; &lt;input type="hidden" name="_VIEWSTATE" value="dDw0ajfmafmjfzzmj4"/&gt;&nbsp; <BR>&nbsp;&nbsp; 其实ViewState实现原理也是将一些信息放到隐藏的一个控件中，并且asp.net生成的ViewState信息 </P>
<P>&nbsp;&nbsp; 是存储在客户端的&nbsp;&nbsp; <BR>&nbsp;&nbsp; 这里要注意的一点是：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只有当格式为*.aspx文件，并且控件具有属性:"runat=server"时，回送功能才能打开<BR>&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>3. Html控件与Web控件最大的区别是它们对事件处理的方法不同。对于Html窗体控件，<BR>当引发一个事件时，浏览器会处理它。但对于Web控件，事件仅由浏览器生成，但浏览<BR>器不会处理它，客户端要给服务器发个信息，告诉服务器处理事件。 不过有些事件，<BR>比如:<BR>&nbsp; 按下键/移动/鼠标等事件，Asp.net中没有这些事件<BR>&nbsp; (因为这些事件即时性强，服务器处理得不够及时)，这时候Html控件就发挥其作用了，结合Html事件 </P>
<P>&nbsp; 协助完成.</P>
<P>如下是一些Html常用的事件:<BR>在浏览器上执行的Html控件事件:</P>
<P>单击时触发:<BR>&lt;INPUT type="button" value="Click Me" onclick="alert('Hi,你好!');"&gt;</P>
<P>鼠标弹起时触发:<BR>&lt;INPUT type="button" value="Click Me" onmouseup="alert('Hi,你好!');"&gt;</P>
<P>//悬浮在控件上方时触发<BR>&lt;INPUT type="button" value="Click Me" onmouseover="alert('Hi,你好!');"&gt;</P>
<P>//鼠标在控件上方移动时触发<BR>&lt;INPUT type="button" value="Click Me" onmousemove="alert('Hi,你好!');"&gt;</P>
<P>//双击控件时触发<BR>&lt;INPUT type="button" value="Click Me" ondblclick="alert('Hi,你好!');"&gt;</P>
<P>//当焦点在控件时，按键时触发<BR>&lt;INPUT type="button" value="Click Me" onkeypress="alert('Hi,你好!');"&gt;</P>
<P>//按键按下时触发<BR>&lt;INPUT type="button" value="Click Me" onkeydown="alert('Hi,你好!');"&gt;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:21 <a href="http://www.cnitblog.com/ChengKing/articles/5007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(二)ComponentOne之WebChart(柱状图)</title><link>http://www.cnitblog.com/ChengKing/articles/5005.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:20:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5005.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5005.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5005.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5005.html</trackback:ping><description><![CDATA[<P>&nbsp;柱状图(代码示例一个比较复杂的柱状图,运行效果轮廓在最下面显示)<BR>（一）.配置</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.安装好ComponentOne软件.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.建立一个WEB应用程序项目，名称为: 柱状图示例</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.将ComponentOne软件自带的控件集DLL文件(不一定全部，只把需要的一部分)拷贝到自己刚建的</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项目TextChart的Bin目录下面 (这里要手动放的原因是ComponentOne有时会找不到Dll)&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.双击项目里任何一个*.aspx文件，打开设计界面。 打开工具栏，在工具栏空白处右击，选“添加/删除”</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项,打开自定义控件窗口，在.net frame 组件选项卡下选择ComponentOne相应的组件，如果有清楚，</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 就将所有的C1开头的全部勾选，点“确定按钮".&nbsp; 则ComponentOne的控件就显示在工具箱里面了&nbsp; :)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5. 到了这一步，就可以将ComponentOne控件像一般控件一样直接拖动使用了. 拖C1WebChart控件到</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 窗体页面上.&nbsp; 然后右击控件，选 "Chart wizard..."就可以为其设置显示的样式(饼图/柱状图/折线图等)和</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 属性了，用法跟一般控件差不多。(除了用设计器设置外，请看下面（二）</P>
<P>(二) . 代码部分&nbsp; ((示例柱状图显示一个班级每个同学的：语文/数学/英语成绩))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 柱状图的命名空间及控件声明&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChart;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //命名空间，必需加入,否则找不到里面的类和方法等<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChartBase;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Win.C1Chart;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected C1.Web.C1WebChart.C1WebChart C1WebChart1;&nbsp;&nbsp; // 控件声明</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 柱状图的主要属性<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Header.Text="2005级计算机系五班成绩图表显示";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表头标题<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Footer.Text="Chart 尾";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表尾文本<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.BackColor = Color.LightSteelBlue;&nbsp;&nbsp; //背景色<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;&nbsp; //图像存储格式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Bar;&nbsp;&nbsp; //图表<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 类型,Chart2DTypeEnum枚举下有所有的图表样式，如饼图/柱状图等<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Width=800;&nbsp;&nbsp;&nbsp;&nbsp; //图表区域宽度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.柱状图的核心方法<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void GetBarChart(DataView dv)&nbsp; //其中dv是传递过来的数据视图，直接用数据集DataSet也是一样的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //dv中有三列: 语文 数学 英语<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //生成三维数组点实例。存储每个同学语文/数学/英语三门课的成绩.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PointF[][] data = new PointF[3][];<BR>&nbsp;&nbsp;&nbsp;for(int i =0;i &lt; 3; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;data[i] = new PointF[dv.Count];<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//语文成绩<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; dv.Count; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((dv[i]["语文成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;data[0][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//数学成绩&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; dv.Count; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((dv[i]["数学成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;data[1][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//英语成绩&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; dv.Count; i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;float y = float.Parse((dv[i]["英语成绩"]).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;data[2][i] = new PointF(i, y);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //绑定数据&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;for(int i=0; i &lt; 3; i++) //如果是双条,则显示&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;ChartDataSeries series = C1WebChart1.ChartGroups[0].ChartData.SeriesList[i];&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;series.PointData.CopyDataIn(data[i]);// 这里的data是PointF类型<BR>&nbsp;&nbsp;&nbsp;&nbsp;series.FitType = C1.Win.C1Chart.FitTypeEnum.Spline;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//lend，对三种颜色Bar块的描述&nbsp;<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[0].Label="语文成绩";<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[1].Label="数学成绩";<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartGroups[0].ChartData.SeriesList[2].Label="英语成绩";&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//在Bar中显示值&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChartDataSeriesCollection dscoll = C1WebChart1.ChartGroups[0].ChartData.SeriesList;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;C1WebChart1.ChartLabels.LabelsCollection.Clear();<BR>&nbsp;&nbsp;&nbsp;for(int i=0; i &lt; dscoll.Count; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ChartDataSeries series = dscoll[i];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for(int j = 0;j &lt; dv.Count; j++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//加标签,在Bar块上面显示分数<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C1.Win.C1Chart.Label lbl = C1WebChart1.ChartLabels.LabelsCollection.AddNewLabel();&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(i == 0 &amp;&amp; int.Parse(dv[j]["ProjectlastNum"].ToString()) != 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Text = string.Format("{0}",int.Parse(dv[j]["语文成绩"].ToString()));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(i == 1 &amp;&amp; int.Parse(dv[j]["ProjectNormalNum"].ToString()) != 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Text = string.Format("{0}",int.Parse(dv[j]["数学成绩"].ToString()));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(i == 2 &amp;&amp; int.Parse(dv[j]["ProjectBeyondNum"].ToString()) != 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Text = string.Format("{0}",int.Parse(dv[j]["英语成绩"].ToString()));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Compass = LabelCompassEnum.South;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//lbl.Style.BackColor = Color.Brown;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Style.ForeColor = Color.Blue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Offset = 10;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Connected = false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.Visible = true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbl.AttachMethod = AttachMethodEnum.DataIndex;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AttachMethodData am = lbl.AttachMethodData;<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.GroupIndex&nbsp; = 0; //0<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.SeriesIndex = 0; //i<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.PointIndex&nbsp; = j;&nbsp;//0&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.GroupIndex&nbsp; = 0; //0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.SeriesIndex = i; //i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;am.PointIndex&nbsp; = j;&nbsp;//0&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//显示X轴标签&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;Axis ax = C1WebChart1.ChartArea.AxisX;<BR>&nbsp;&nbsp;&nbsp;ax.ValueLabels.Clear();&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; dv.Count; i++)<BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ax.ValueLabels.Add(i, dv[i]["ChiName"].ToString());<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;//ax.Max = Convert.ToSingle(intPeopleNum - .5);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch {}&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P><BR>图像运行后轮廓图如下图所示，只不过显示出的真实图表并不是用*&nbsp; &amp;&nbsp; 和 $表示的，是矩形块，并且有漂亮的颜色，<BR>我之所以手动简要画出轮廓是为了让读者更容易理解上面的代码.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>Y&nbsp;&nbsp; 2005级计算机系五班成绩<BR>^<BR>| <BR>|&nbsp;&nbsp;&nbsp; *80&nbsp;&nbsp; *76&nbsp;&nbsp;&nbsp; *88<BR>|<BR>|&nbsp;&nbsp;&nbsp; &amp;60&nbsp;&nbsp; &amp;96&nbsp;&nbsp;&nbsp; $87<BR>|<BR>|&nbsp;&nbsp;&nbsp; $75&nbsp;&nbsp; $86&nbsp;&nbsp;&nbsp; $89 <BR>|----------------------------&gt;X<BR>&nbsp;&nbsp;&nbsp; 张红&nbsp;&nbsp; 李四&nbsp;&nbsp; 张三</P>
<P>&nbsp; *语文&nbsp;&nbsp; &amp;数学&nbsp;&nbsp; $英语<BR></P>
<P>运行效果&lt;类似&gt;请看链接:<BR><A href="http://blog.csdn.net/ChengKing/archive/2005/11/15/529836.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/15/529836.aspx</A></P>
<P> </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:20 <a href="http://www.cnitblog.com/ChengKing/articles/5005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(一)ComponentOne之WebChart(饼图) ( 11-16 00:06)</title><link>http://www.cnitblog.com/ChengKing/articles/5004.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Tue, 29 Nov 2005 15:19:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/5004.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/5004.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/5004.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/5004.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/5004.html</trackback:ping><description><![CDATA[<P>&nbsp;饼图(形状如像切割后的蛋糕)<BR>（一）.配置</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.安装好ComponentOne软件.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.建立一个WEB应用程序项目，名称为: 饼图示例</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.将ComponentOne软件自带的控件集DLL文件(不一定全部，只把需要的一部分)拷贝到自己刚建的</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项目TextChart的Bin目录下面 (这里要手动放的原因是ComponentOne有时会找不到Dll)&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.双击项目里任何一个*.aspx文件，打开设计界面。 打开工具栏，在工具栏空白处右击，选“添加/删除”</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 项,打开自定义控件窗口，在.net frame 组件选项卡下选择ComponentOne相应的组件，如果有清楚，</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 就将所有的C1开头的全部勾选，点“确定按钮".&nbsp; 则ComponentOne的控件就显示在工具箱里面了&nbsp; :)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5. 到了这一步，就可以将ComponentOne控件像一般控件一样直接拖动使用了. 拖C1WebChart控件到</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 窗体页面上.&nbsp; 然后右击控件，选 "Chart wizard..."就可以为其设置显示的样式(饼图/柱状图/折线图等)和</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 属性了，用法跟一般控件差不多。(除了用设计器设置外，请看下面（二）</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 还可以代码用代码设置)</P>
<P>(二) . 代码部分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 引用命名空间</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChart;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //命名空间，必需加入,否则找不到里面的类和方法等<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Web.C1WebChartBase;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using C1.Win.C1Chart;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected C1.Web.C1WebChart.C1WebChart C1WebChart1;&nbsp;&nbsp; // 控件声明</P>
<P></P>
<P></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 主要属性</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Header.Text="Chart 头";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表头标题<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Footer.Text="Chart 尾";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //图表尾文本<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.BackColor = Color.LightSteelBlue;&nbsp;&nbsp; //背景色<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;&nbsp; //图像存储格式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Pie;&nbsp;&nbsp; //图表</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 类型,Chart2DTypeEnum枚举下有所有的图表样式，如饼图/柱状图等&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Width=800;&nbsp;&nbsp;&nbsp;&nbsp; //图表区域宽度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 主要方法</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a .X轴标签(坐标)的方法，直接调用即可</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void AddAxisX()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // label x axis with product names<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Axis ax = C1WebChart1.ChartArea.AxisX;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.ValueLabels.Clear();&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; 100; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //DataRowView drv = dv[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.ValueLabels.Add(i, (i+1).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ax.Max = 10 - .5;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch {}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b .Y轴标签(坐标)的方法，直接调用即可</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void AddAxisY()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // label y axis with product names<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Axis ay = C1WebChart1.ChartArea.AxisY;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.ValueLabels.Clear();&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.AnnoMethod = AnnotationMethodEnum.ValueLabels;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; 10; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //DataRowView drv = dv[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.ValueLabels.Add(i, (50*i).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ay.Max = 20 - .5;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch {}&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c.画饼图的核心方法<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void GetPieData()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1WebChart1.Legend.Visible = true;&nbsp; //图表区块注释.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.AddAxisX();&nbsp;&nbsp; //上面方法a<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.AddAxisY();&nbsp;&nbsp; //上面方法b<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //生成数据<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PointF[] data = new PointF[10];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; data.Length; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float y = float.Parse((3*i+5).ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data[i] = new PointF(i, y);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //清除现有的饼图图像(在画新饼图之前先清空现有图像)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChartDataSeriesCollection dscoll = C1WebChart2.ChartGroups[0].ChartData.SeriesList;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dscoll.Clear();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //汇图,即将点数组交给控件，它会自己分配,并画出图形<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChartDataSeries series = C1WebChart1.ChartGroups[0].ChartData.SeriesList[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; series.PointData.CopyDataIn(data);// 这里的data是PointF类型&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //给区块加标签<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; data.Length; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ChartDataSeries series = dscoll.AddNewSeries();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; series.PointData.Length = 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; series.Y[0] = data[i].Y;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; series.Label="我是:"+(i+1).ToString();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //加标签<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C1.Win.C1Chart.Label lbl = C1WebChart1.ChartLabels.LabelsCollection.AddNewLabel();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.Text = string.Format("{0} ({1:c})","第:"+i.ToString()+"扇区", data[i].Y);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.Compass = LabelCompassEnum.Radial;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.Offset = 20;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.Connected = true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.Visible = true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lbl.AttachMethod = AttachMethodEnum.DataIndex;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AttachMethodData am = lbl.AttachMethodData;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; am.GroupIndex&nbsp; = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; am.SeriesIndex = i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; am.PointIndex&nbsp; = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR></P>
<P>显示效果《类似》请看链接:<BR>&nbsp;<A href="http://blog.csdn.net/ChengKing/archive/2005/11/15/529833.aspx">http://blog.csdn.net/ChengKing/archive/2005/11/15/529833.aspx</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/5004.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-29 23:19 <a href="http://www.cnitblog.com/ChengKing/articles/5004.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分布式编程-&gt;Remoting的一个代码示例(借助Remoting实现发送信息功能) </title><link>http://www.cnitblog.com/ChengKing/articles/4014.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:49:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4014.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4014.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4014.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4014.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4014.html</trackback:ping><description><![CDATA[<P>(一).说明<BR>&nbsp;&nbsp;&nbsp; 一个远程调用示例. <BR>&nbsp;&nbsp;&nbsp; 此示例实现功能:&nbsp; 客房端调用远程方法（远程方法可以弹&nbsp;&nbsp;&nbsp; 出自定义信息），实现发送信息功能. <BR>&nbsp;&nbsp;&nbsp; 实现原理概是这样的：客户端不能直接调用远程对象，它必须先通过信道请求服务端宿主程序,当收到客户端请求时，<BR>&nbsp;&nbsp;&nbsp; .net远程处理框架会在宿主组件的应用程序域中生成所需要的远程对象. 并执行远程对象中的方法.&nbsp;&nbsp;&nbsp;&nbsp; <BR>(二).实现方案<BR>&nbsp; 在之前先介绍几种类:<BR>&nbsp;&nbsp;&nbsp; 1.可序列化的类：&nbsp; 以&lt;serializable&gt;属性为标记，可以在进程/应用程序/计算机之间传送.<BR>&nbsp;&nbsp;&nbsp; 2.可远程调用的类: 直接或间接地继承 System.MarshalByRefObject类，可以被远程激活.<BR>&nbsp;&nbsp;&nbsp; 3.一般类:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不能构建分布式，用于本地调用.<BR>&nbsp; 1.首先建立三个项目: <BR>&nbsp;&nbsp;&nbsp; RemoteObject: 提供远程对象，供客户端调用&nbsp; <BR>&nbsp;&nbsp;&nbsp; SimpleClient: 用于向服务端程序发出请求，调用远程对象 (winform)<BR>&nbsp;&nbsp;&nbsp; SimpleServer: 侦听客户端请求，并创建对象&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (winform) <BR>&nbsp; 2.在RemoteObject项目下面建立远程调用类: RemoteObject.cs<BR>&nbsp;&nbsp;&nbsp; 在SimpleClient项目下面建立: Form1.cs和SimpleClient.exe.config配置文件。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其中配置文件的作用是指定服务端地址和信道等信息，下面的代码里面有详细说明.<BR>&nbsp;&nbsp;&nbsp; 在SimpleServer项目下面建立: Form1.cs和SimpleServer.exe.config配置文件。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其中配置文件的作用是指定接受请求客户端的地址和信道等信息，下面的代码里面有详细说明.&nbsp; <BR>(三).<BR>&nbsp; 各文件源代码:<BR>&nbsp; 1.RemoteObject.cs<BR>&nbsp;&nbsp;&nbsp; using System;<BR>&nbsp;&nbsp;&nbsp; using System.Windows.Forms;<BR>&nbsp;&nbsp;&nbsp; namespace RemoteObjects<BR>&nbsp;&nbsp;&nbsp; {&nbsp;<BR>&nbsp;public class RemoteObject : System.MarshalByRefObject&nbsp; //继承此类才能被远程激活调用<BR>&nbsp;{<BR>&nbsp;&nbsp;public RemoteObject()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;//远程调用方法,功能： 弹出自定义消息, 参数: str是从客户端传递过来的<BR>&nbsp;&nbsp;public static void Method(string str)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageBox.Show(str);&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}&nbsp;&nbsp;<BR>&nbsp;}<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; 2.客户端工程SimpleClient项目中的Form1.cs:<BR>&nbsp;&nbsp;&nbsp; using System;<BR>&nbsp;&nbsp;&nbsp; using System.Drawing;<BR>&nbsp;&nbsp;&nbsp; using System.Collections;<BR>&nbsp;&nbsp;&nbsp; using System.ComponentModel;<BR>&nbsp;&nbsp;&nbsp; using System.Windows.Forms;<BR>&nbsp;&nbsp;&nbsp; using System.Data;<BR>&nbsp;&nbsp;&nbsp; using RemoteObjects;<BR>&nbsp;&nbsp;&nbsp; namespace SimpleClient<BR>&nbsp;&nbsp;&nbsp; {&nbsp;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;private System.Windows.Forms.TextBox textBox1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1;&nbsp;&nbsp;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();<BR>&nbsp;&nbsp;}&nbsp;&nbsp;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.textBox1 = new System.Windows.Forms.TextBox();<BR>&nbsp;&nbsp;&nbsp;this.label1 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// textBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.textBox1.Location = new System.Drawing.Point(40, 88);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Multiline = true;<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Name = "textBox1";<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Size = new System.Drawing.Size(336, 176);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Text = "";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label1.Location = new System.Drawing.Point(40, 32);<BR>&nbsp;&nbsp;&nbsp;this.label1.Name = "label1";<BR>&nbsp;&nbsp;&nbsp;this.label1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.label1.Text = "请输入信息:";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(296, 32);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 2;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "发送";<BR>&nbsp;&nbsp;&nbsp;this.button1.Click += new System.EventHandler(this.button1_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(416, 302);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.label1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.textBox1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "发送信息";<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //载入信道，用于侦听客户端请求，配置文件记载客户端地址等信息.<BR>&nbsp;&nbsp;&nbsp;System.Runtime.Remoting.RemotingConfiguration.Configure("Simpleclient.exe.config");&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void button1_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//开始调用远程对象(发送信息)<BR>&nbsp;&nbsp;&nbsp;RemoteObjects.RemoteObject.Method(this.textBox1.Text);<BR>&nbsp;&nbsp;}<BR>&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>3.客户端工程SimpleClient项目中的SimpleClient.exe.config:<BR>&nbsp;&nbsp; &lt;?xml version="1.0" encoding="utf-8" ?&gt;<BR>&nbsp;&nbsp; &lt;configuration&gt;<BR>&nbsp;&lt;system.runtime.remoting&gt;<BR>&nbsp;&nbsp;&lt;application name="simpleclient"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;!-- 指定请求的服务端地址和端口号--&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;!-- url中的:localhost是测试的本机，可以使用Intenet上的其它机器名或ip地址--&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;client url="tcp://localhost:8080/simpleserver"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;activated type="RemoteObjects.RemoteObject,RemoteObjects"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/activated&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/client&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;channels&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- 指定信道,有两种信道可选:Tcp(基于TCP协议)和Http(无连续连接协议)信道--&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;channel ref="tcp client"/&gt;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&lt;/channels&gt;<BR>&nbsp;&nbsp;&lt;/application&gt;<BR>&nbsp;&lt;/system.runtime.remoting&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<BR>4.服务端工程SimpleServer项目中的Form1.cs:<BR>&nbsp;&nbsp; using System;<BR>&nbsp;&nbsp; using System.Drawing;<BR>&nbsp;&nbsp; using System.Collections;<BR>&nbsp;&nbsp; using System.ComponentModel;<BR>&nbsp;&nbsp; using System.Windows.Forms;<BR>&nbsp;&nbsp; using System.Data;<BR>&nbsp;&nbsp; using System.Runtime.Remoting;</P>
<P>&nbsp;&nbsp; namespace SimpleServer<BR>&nbsp;&nbsp; {<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//Application.Run(new Form1());&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;Run();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private static void Run()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;System.Runtime.Remoting.RemotingConfiguration.Configure("SimpleServer.exe.config");<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>5.服务端工程SimpleServer项目中的SimpleServer.exe.config:<BR>&nbsp; &lt;?xml version="1.0" encoding="utf-8" ?&gt;<BR>&nbsp; &lt;configuration&gt;<BR>&nbsp;&lt;system.runtime.remoting&gt;<BR>&nbsp;&nbsp;&lt;application name="simpleserver"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;service&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;activated type="RemoteObjects.RemoteObject,RemoteObjects"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/activated&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/service&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;channels&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;channel ref="tcp server" port="8080" /&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/channels&gt;<BR>&nbsp;&nbsp;&lt;/application&gt;<BR>&nbsp;&lt;/system.runtime.remoting&gt;<BR>&nbsp; &lt;/configuration&gt;<BR>(四).注意点<BR>&nbsp;&nbsp; 1.由于配置文件默认是添加在根目录下的，要把两个配置文件拷贝到:根目录/bin/debug下面,要让它与执行文件在同一个目录下面。<BR>&nbsp;&nbsp; 2.右击RemoteObject项目，选“常规”下的，输入类型为：“类库”.&nbsp; 它默认为应用程序，这里作为类库使用.&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; 设置好后，按: Ctrl+Shift+B生成类库Dll.<BR>&nbsp;&nbsp; 3.在工程SimpleServer和SimpleClient中分别添加引用： 即将RemoteObject项目刚生成的DLL: RemoteObjects.dll添加到各自的工程中.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 具体方法：右击“引用“-&gt;”添加引用“-&gt;"浏览"，找到生成的RemoteObjects.dll分别添加进来.<BR>&nbsp;&nbsp; 4.右击解决方案，选择“属性”-&gt; “选中多启动项目单选框”-&gt;"选SimpleServer和SimpleClient同时启动".<BR>&nbsp;&nbsp;&nbsp;&nbsp; 因为： 当服务端宿主程序运行时，客户端才能正确调用远程对象.<BR>&nbsp;&nbsp; 5.按F5运行.&nbsp; 输入信息，点“发送”按钮，就可以调用远程对象了.<BR>(五).扩展<BR>&nbsp;&nbsp;&nbsp;&nbsp; 可以修改客户端配置文件:&lt;client url="tcp://localhost:8080/simpleserver"&gt;&nbsp; 中的localhost为其它的机器名称，只要另一台<BR>&nbsp;&nbsp;&nbsp;&nbsp; 机器运行了宿主程序,并处于运行状态. 那么当调用时，会在服务端弹出信息，即实现了发送信息功能.</P>
<P></P>
<P>以上代码已经测试，不正确的地方望批评指正!</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:49 <a href="http://www.cnitblog.com/ChengKing/articles/4014.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分布式编程-&gt;XML Webservice实现原理及相关知识</title><link>http://www.cnitblog.com/ChengKing/articles/4015.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:49:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4015.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4015.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4015.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4015.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4015.html</trackback:ping><description><![CDATA[<P>好多书籍只介绍创建XML Webservice，并没有详细介绍XML WebService的工作原理以及各部分(例如IIS Asp.net)<BR>在XML WebService中所起的作用.<BR>学习后整理了一下,希望对读者有所帮助!</P>
<P>(一).XML WebService作用<BR>&nbsp; XML WebService在应用程序中所起的作用与.Net远程调用处理组件相同. <BR>&nbsp; 用户不能直接使用WebService,只能通过Asp.net Web应用程序或Windows桌面<BR>&nbsp; 客户端来调用.<BR>(二).XML WebService与.Net远程处理区别<BR>&nbsp; 1. XML WebService比.Net远程处理对象所受的限制更多。它类似于.Net远程处理<BR>&nbsp;&nbsp;&nbsp;&nbsp; 的单独调用对象的工作机制。 不能创建一个单独的或是由客户端激活的对象.<BR>&nbsp; 2.XML WebService的创建和设计比远程组件更容易/简单.<BR>&nbsp; 3.Net远程处理二进制通信要比XML WebService SOAP格式通信要快捷.<BR>&nbsp; 4.XML WebService较.Net远程处理扩展性强。 它支持以跨平台使用为目的的开放标准.<BR>&nbsp; 5.XML WebService不需要专门的宿主程序，而是由Asp.net承载。 可以访问一些重要的<BR>&nbsp;&nbsp;&nbsp; 平台服务，如：数据缓存/网络会话状态管理/身份验证/全局共享应用程序集合等。而.Net<BR>&nbsp;&nbsp;&nbsp; 远程处理则很难实现这些功能.<BR>&nbsp; 6.XML WebService运行在IIS和ASP.NET之上，使用http信道(80端口)与客户通信。<BR>&nbsp;&nbsp;&nbsp; 可以自由跨越防火墙.<BR>(三).XML WebService创建与调用过程<BR>&nbsp; I.服务端创建<BR>&nbsp;&nbsp;&nbsp;&nbsp; 1.使用IIS，在Web服务器上新建一个虚拟目录来存放XML Web服务.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 2.建立XML WebService类，使用[WebMethod]属性来标记方法可以被远程调用.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 3.在虚拟目录中部署XML Web服务的文件.<BR>&nbsp; II.客户端使用<BR>&nbsp;&nbsp;&nbsp;&nbsp; 1.客户端通过URL或文件查询或UDDI注册，发现XML WebService<BR>&nbsp;&nbsp;&nbsp;&nbsp; 2.客户端请求描述XML WebService的WSDL文档。<BR>&nbsp;&nbsp;&nbsp;&nbsp; 3.客户端在WSDL文档的基础上生成一个代理类。<BR>&nbsp;&nbsp;&nbsp;&nbsp; 4.客户端生成代理类的实例，并调用XML Webservice，发送消息并接受处理后结果.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 也就是说调用XML WebService是由客户端生成的代理类实例对象完成的.<BR>(四).IIS作用<BR>&nbsp; 1.IIS通过虚拟目录提供对Web服务器进行访问。简单的说： 就是将"c:\MyWeb"映射<BR>&nbsp;&nbsp;&nbsp; 一个URL地址形式的虚拟目录:"<A href="http://192.168.83.66/MyWeb">http://192.168.83.66/MyWeb</A>",供本机或Internet<BR>&nbsp;&nbsp;&nbsp; 上计算机访问Webservice.<BR>&nbsp; 2.虚拟目录的权限与普通目录不同。根据默认设置，不允许远程用户浏览虚拟目录，运行<BR>&nbsp;&nbsp;&nbsp; 可执行文件，新建文件和下载某些文件类型文件。可以根据需要自定义IIS虚拟目录权限设置.<BR>&nbsp; 3.IIS对Internet进行公开处理. IIS并不负责运行Asp或Asp.net布面 或XML Webservice,而是<BR>&nbsp;&nbsp;&nbsp; 维护一个注册的文件扩展名列表。如果IIS收到对某一种文件类型的请求，就把工作提交给<BR>&nbsp;&nbsp;&nbsp; Asp.net工作进程，由Asp.net工作进程处理剩下的工作.<BR>(五).XML WebService和SOAP标准支持的数据类型<BR>&nbsp; 不知道读者有没有遇到这种情况，在调用WebService并给一个方法传递了一个DataRow参数时，运行<BR>&nbsp; 时会抛出异常： "没法将参数序列化！"，如果把DataRow加入到DataSet中，并将DataSet作为参数<BR>&nbsp; 传递再运行就OK了。 这是因为：XML WebService只能对数据集DataSet对象类型进行XML序列化，<BR>&nbsp; 不能对DataRow对象类型进行XML序列化造成的错误.&nbsp; 所以了解一下XML WebService支持序列化的基<BR>&nbsp; 本数据类型是比较重要的.它支持的数据类型如下:<BR>&nbsp; 1.基本数据类型.&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 标准类型，如：int float bool DateTime string等基本数据类型<BR>&nbsp; 2.枚举.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 支持枚举Enum定义的类型<BR>&nbsp; 3.自定义对象.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以传递任意基于自定义类或结构创建的对象。 但要注意一点： 它只能传输数据成员(变量和属性).<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果定义了方法，则方法不能进行序列化传输,序列化后只剩下数据成员.<BR>&nbsp; 4.DataSet对象<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 支持DataSet,切记：不支持DataTable和DataRow,DataSet已经是XML Webservice能够支持的最小的可序列化对象.<BR>&nbsp; 5.XmlNode对象<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 基于XmlNode的对象可以表示XML文档的一部分.<BR>&nbsp; 6.数组和集合<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以使用任何被支持的类型的数组和简单集合，包括: DataSet对象/XmlNode对象和自定义对象.</P>
<P>另外，关于创建XML WebService实例代码示例，几乎任何一本涉及到WebService的书籍都会讲的。而且创建一个<BR>WebService非常简单. 这里就不多说了. </P>
<P><BR>哦,已经: 00:43点了，该睡觉了.&nbsp; :)<BR>&nbsp; <BR>&nbsp; <BR>&nbsp; </P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4015.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:49 <a href="http://www.cnitblog.com/ChengKing/articles/4015.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>注册表操作</title><link>http://www.cnitblog.com/ChengKing/articles/4013.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:48:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4013.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4013.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4013.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4013.html</trackback:ping><description><![CDATA[<P>(一）写入<BR>&nbsp;&nbsp; 1.建立文件<BR>&nbsp;&nbsp;&nbsp; 建立一个注册表格式文件: *.reg,内容如下:</P>
<P>&nbsp;&nbsp;&nbsp; Windows Registry Editor Version 5.00<BR>&nbsp;&nbsp;&nbsp; [HKEY_LOCAL_MACHINE\SOFTWARE\Test]<BR>&nbsp;&nbsp;&nbsp; "server"="192.168.66.22"<BR>&nbsp;&nbsp;&nbsp; "database"="NorthWind"<BR>&nbsp;&nbsp;&nbsp; "user"="XiaoWang"<BR>&nbsp;&nbsp;&nbsp; "Password"="123456"<BR>&nbsp;&nbsp;&nbsp; 其中:<BR>&nbsp;&nbsp;&nbsp;&nbsp; I.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [HKEY_LOCAL_MACHINE\SOFTWARE\Test] : 表示路径,如果路径不存在，系统会自动创建路径<BR>&nbsp;&nbsp;&nbsp;&nbsp; II.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "server"="192.168.66.22"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "database"="NorthWind"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "user"="XiaoWang"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Password"="123456"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表示: 键和值，左边是键，右边是键的值。 在读取时根据键读取.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 2.双击运行即可。 它会自动将键值放到配置好的路径下面.</P>
<P>(二) 读取<BR>&nbsp;&nbsp; 打开命名空间:&nbsp;&nbsp; using Microsoft.Win32;<BR>&nbsp;&nbsp; 1.方法<BR>&nbsp;&nbsp;&nbsp;&nbsp; //参数1表示路径. 如: HKEY_LOCAL_MACHINE\SOFTWARE<BR>&nbsp;&nbsp;&nbsp;&nbsp; //参数2表示键.&nbsp; 自定义的<BR>&nbsp;&nbsp;&nbsp;&nbsp; public static object GetRegValue(string strRegPath,string strName)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;strRegPath = strRegPath.Trim();<BR>&nbsp;&nbsp;&nbsp;//接收值的对象&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;object objRet;</P>
<P>&nbsp;&nbsp;&nbsp;//&nbsp;如果名称为空，则抛出一个参数为空的异常。&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (strName == "")<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw new ArgumentNullException(strName,"键值不能为空!");<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;//去除"\"字符<BR>&nbsp;&nbsp;&nbsp;if ( strRegPath.StartsWith("\\") ) <BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;strRegPath = strRegPath.Substring(1,strRegPath.Length - 1);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;if ( strRegPath.EndsWith("\\") )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;strRegPath = strRegPath.Substring(0,strRegPath.Length - 1);<BR>&nbsp;&nbsp;&nbsp;}</P>
<P><BR>&nbsp;&nbsp;&nbsp;//拆分根键和路径&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strRootKey,strPath;<BR>&nbsp;&nbsp;&nbsp;int intIndex = strRegPath.IndexOf("\\");</P>
<P>&nbsp;&nbsp;&nbsp;strRootKey = strRegPath.Substring(0,intLoc).ToUpper();</P>
<P>&nbsp;&nbsp;&nbsp;strPath = strRegPath.Substring(intIndex&nbsp; + 1,strRegPath.Length - intIndex - 1);<BR>&nbsp;&nbsp;&nbsp;RegistryKey _root;<BR>&nbsp;&nbsp;&nbsp;switch( strRootKey )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_CLASSES_ROOT":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.ClassesRoot;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_CURRENT_CONFIG":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.CurrentConfig;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_CURRENT_USER":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.CurrentUser;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_DYN_DATA":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.DynData;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_LOCAL_MACHINE":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.LocalMachine;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_PERFORMANCE_DATA":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.PerformanceData;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;case "HKEY_USERS":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root = Registry.Users;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception("找不到路径!");<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;//打开注册表路径的键&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegistryKey regKey = _root.OpenSubKey(@strPath);<BR>&nbsp;&nbsp;&nbsp;&nbsp;//取值&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objRet = regKey.GetValue(strName);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(Exception e)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw e;<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;return objRet;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp; 2.用法:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strConnectString = GetRegValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Test","strConnString").ToString();</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:48 <a href="http://www.cnitblog.com/ChengKing/articles/4013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Web.Config文件详解</title><link>http://www.cnitblog.com/ChengKing/articles/4012.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:47:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4012.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4012.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4012.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4012.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4012.html</trackback:ping><description><![CDATA[<P>(一).Web.Config是以XML文件规范存储,配置文件分为以下格式<BR>&nbsp;&nbsp;&nbsp; 1.配置节处理程序声明<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点： 位于配置文件的顶部，包含在&lt;configSections&gt;标志中。<BR>&nbsp;&nbsp;&nbsp; 2.特定应用程序配置<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点:&nbsp; 位于&lt;appSetting&gt;中。 可以定义应用程序的全局常量设置等信息.<BR>&nbsp;&nbsp;&nbsp; 3.配置节设置<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点:&nbsp; 位于&lt;system.Web&gt;节中，控制Asp.net运行时的行为.<BR>&nbsp;&nbsp;&nbsp; 4.配置节组<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点:&nbsp; 用&lt;sectionGroup&gt;标记，可以自定义分组，可以放到&lt;configSections&gt;内部或其它&lt;sectionGroup&gt;标记的内部.<BR>(二).配置节的每一节<BR>&nbsp;&nbsp;&nbsp; 1.&lt;configuration&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 根元素，其它节都是在它的内部.<BR>&nbsp;&nbsp;&nbsp; 2.&lt;appSetting&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 此节用于定义应用程序设置项。对一些不确定设置，还可以让用户根据自己实际情况自己设置<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用法:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;appSettings&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;add key="Conntction" value="server=192.168.85.66;userid=sa;password=;database=Info;"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;appSettings&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 定义了一个连接字符串常量，并且在实际应用时可以修改连接字符串，不用修改程式代码.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.&lt;appSettings&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add key="ErrPage" value="Error.aspx"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;appSettings&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 定义了一个错误重定向页面.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 3.&lt;compilation&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格式:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;compilation <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultLanguage="c#"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; debug="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.default language: 定义后台代码语言,可以选择C#和VB.net两种语言.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IIdebug : 为true时，启动aspx调试； 为false不启动aspx调试，因而可以提高应用程序运行<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 时的性能。 一般程序员在开发时设置为true,交给客户时设置为false.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 4.&lt;customErrors&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格式:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;customErrors <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mode="RemoteOnly" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; defaultRedirect="error.aspx"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;error statusCode="440" redirect="err440page.aspx"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;error statusCode="500" redirect="err500Page.aspx"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.mode : 具有On,Off,RemoteOnly 3种状态。On表示始终显示自定义的信息; Off表示始终显示详细的asp.net错误信息; RemoteOnly表示只对不在本地Web服务器上运行的用户显示自定义信息.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.defaultRedirect: 用于出现错误时重定向的URL地址. 是可选的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.statusCode:&nbsp; 指明错误状态码，表明一种特定的出错状态.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IV. redirect:错误重定向的URL.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.&lt;globalization&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格式:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;globalization <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requestEncoding="utf-8" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; responseEncoding="utf-8" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileEncoding="utf-8"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.requestEncoding: 它用来检查每一个发来请求的编码.&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.responseEncoding: 用于检查发回的响应内容编码.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.fileEncoding: 用于检查aspx,asax等文件解析的默认编码.&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6.&lt;sessionState&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格式:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;sessionState <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mode="InProc"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stateConnectionString="tcpip=127.0.0.1:42424"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cookieless="false" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeout="20" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.mode: 分为off,Inproc,StateServer,SqlServer几种状态<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里有详细介绍此属性: <A href="http://blog.csdn.net/chengking/archive/2005/10/27/518079.aspx">http://blog.csdn.net/chengking/archive/2005/10/27/518079.aspx</A> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II. stateConnectionString :指定Asp.net应用程序存储远程会话状态的服务器名，默认为本机<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.sqlConnectionString: 当用会话状态数据库时，在这里设置连接字符串<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IV. Cookieless: 设置为true时，表示不使用cookie会话状态来标识客户； 否则，相反.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; V.&nbsp; TimeOut: 用来定义会话状态存储的时间，超过期限，将自动终止会话.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7.&lt;authentication&gt;节<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 格式:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;authentication mode="Forms"&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/authentication&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;authorization&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;deny users="?"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/authorization&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.Windows: 使用IIS验证方式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.Forms: 使用基于窗体的验证方式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.Passport: 采用Passport cookie验证模式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IV.None: 不采用任何验证方式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 里面内嵌Forms节点的属性涵义:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.Name: 指定完成身份验证的Http cookie的名称.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.LoginUrl: 如果未通过验证或超时后重定向的页面URL，一般为登录页面，让用户重新登录<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.Protection: 指定 cookie数据的保护方式. <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可设置为: All None Encryption Validation四种保护方式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a. All表示加密数据，并进行有效性验证两种方式<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b. None表示不保护Cookie.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c. Encryption表示对Cookie内容进行加密<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d. validation表示对Cookie内容进行有效性验证<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IV. TimeOut: 指定Cookie的失效时间.&nbsp; 超时后要重新登录.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:47 <a href="http://www.cnitblog.com/ChengKing/articles/4012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>巧用: Trace跟踪输出 进行调试</title><link>http://www.cnitblog.com/ChengKing/articles/4011.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:46:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4011.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4011.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4011.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4011.html</trackback:ping><description><![CDATA[<P>(一).说明<BR>&nbsp;&nbsp;&nbsp;&nbsp; 很多人在调试输入时，一般用: Respone.Write(),或跟踪后再在命令窗口计算对象的值等方法.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 其实Microsoft为Asp.net提供很好的输出调试类Trace.&nbsp; 这里讲一下它的用法<BR>(二)具体用法</P>
<P>&nbsp; 分为页面级别调试和应用程序级别跟踪调试:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 1.页级别跟踪: 在页的开头包括如下的页指令&lt;%@ Page Trace="True"&nbsp;&nbsp; TraceMode="SortByCategory/SortByTime" %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.自定义消息示例: <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trace.Write("这里为要输出结果的变量或自定义字符串"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trace.Warn("这里为要显示的字符串");&nbsp;&nbsp; //与Trace.Write相同,只是字体为红色<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 检查是否使用了跟踪<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.判断是否启用了跟踪输出:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(Trace.IsEnabled) { Trace.Warn("已启用跟踪")}&nbsp; </P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp; 2.应用程序级别跟踪: <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在Web.config文件的&lt;System.Web&gt;节中 &lt;trace enabled="true" pageOutput="true"/&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样就不用在一个一个页面中设置了.</P>
<P><BR>用Trace跟踪调试最大的好处是：&nbsp; 程序员用完后只要将 页面或应用程序跟踪设为:false即可.</P>
<P>不用将其删除或注释. 因为编译器编译到Trace输出<BR>语句时，不会将其编译，会略过Trace语句继续编译下面的语句。&nbsp;</P>
<P>&nbsp;从程序员角度看,即Trace相当于已经注释掉了</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:46 <a href="http://www.cnitblog.com/ChengKing/articles/4011.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Asp.Net性能优化</title><link>http://www.cnitblog.com/ChengKing/articles/4010.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:45:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4010.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4010.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4010.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4010.html</trackback:ping><description><![CDATA[<P>(一).选择会话状态存储方式<BR>&nbsp;&nbsp;&nbsp; 在Webconfig文件配置:<BR>&nbsp;&nbsp;&nbsp; &lt;sessionState mode="???" stateConnectionString="tcpip=127.0.0.1:42424" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cookieless="false" timeout="20"/&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Asp.net有三种方式存储会话状态信息: <BR>&nbsp;&nbsp;&nbsp; 1. 存储在进程中: 属性mode = InProc<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点：&nbsp; 具有最佳的性能，速度最快,但不能跨多台服务器存储共享.<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 2. 存储在状态服务器中: 属性mode = "StateServer" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点:&nbsp;&nbsp; 当需要跨服务器维护用户会话信息时，使用此方法。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 但是信息存储在状态服务器上，一旦状态服务器出现故障，信息将丢失<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 3. 存储在Sql Server中: 属性mode="SqlServer"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 特点:&nbsp;&nbsp; 工作负载会变大，但信息不会丢失.<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 补充一点： <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I. 由于某些页面不需要会话状态，则可以将会话状态禁用:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 代码如下： &lt;%@ Page EnableSessionState="false" %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.如果页面需要访问会话变量但不允许修改它们，可以设置页面会话状态为只读:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 代码如下： &lt;%@ Page EnableSessionState="false" %&gt;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 使用时可以根据具体情况选择某种方式<BR>(二).使用Page.IsPostBack<BR>&nbsp;&nbsp;&nbsp; Page.IsPostBack表示是否是从客户端返回的. 初次运行时，不是从客户端返回，它的值<BR>&nbsp;&nbsp;&nbsp; 为false,当触发页面上的事件或刷新页面时，Page.IsPostBack由于是回发的，值变为true;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 一般在:&nbsp; Page_Load方法中用:<BR>&nbsp;&nbsp;&nbsp; private void Page_Load(Object sender,EventArgs e)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!Page.IsPostBack)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....;&nbsp; //初始化页面的代码。这些代码第一次页面初始化时执行，当第二次回发时，<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //不会再执行。提高效率。&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 往往很多时候不得不用IsPostBack, 因为有些控件初始化后，要保持它的状态.<BR>&nbsp;&nbsp;&nbsp; 例如: DropDownList,如果每次都初始化，则用户无论选择其选项，都会被初始化为默认值.<BR>(三).避免使用服务器控件<BR>&nbsp;&nbsp;&nbsp; 1.一般的静态显示信息，尽量不要用服务端控件显示. 因为服务端控件需要回发服务端执行,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 会降低程序执行效率,一般用&lt;DIV&gt;显示即可.&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果用了服务端控件，将: runat="server"去掉,也会提高效率.<BR>&nbsp;&nbsp;&nbsp; 2.禁用服务端控件的状态视图，有些控件不需要维护其状态，可以设置其属性: EnableViewState=false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果整个页面控件都不需要维持状态视图，则可以设置整个页面的状态视力为false:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 代码如下: &lt;%@ Page EnableViewState="false"%&gt;<BR>&nbsp;&nbsp;&nbsp; 3.在Web.Config文件中配置:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ASP.NET Sessionss可以在Web.config或Machine.config中的Sessionsstate元素中配置。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面是在 Web.config中的设置的例子：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Sessionsstate timeout="10" cookieless="false" mode="Inproc" /&gt; <BR>(四).避免使用DataGrid<BR>&nbsp;&nbsp;&nbsp; 大家都知道DataGrid功能强大。 但是功能强大的同时，增加了性能上的开销。 一般用其它控件: DataList<BR>&nbsp;&nbsp;&nbsp; 或Repeater控件能实现的，尽量不用DataGrid.<BR>(五).字符串操作<BR>&nbsp;&nbsp;&nbsp; 1.避免装箱操作.&nbsp; 装箱操作运行效率比较低.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 例如运行两个代码段:&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string test="";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(for int i=0;i&lt;10000;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test = test + i;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 和<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string test="";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(for int i=0;i&lt;10000;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; test = test + i.ToString();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面的代码段显然效率要高.因为i是整型的，系统要先把i进行装箱转换为string型的，再进行连接. 需要时间<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 读者可以Copy到自己机器上测试一下.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 2.使用StringBulider类<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在进行字符串连接时:&nbsp; string str = str1 + str2 + ....; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般超过三项连接，最好用StringBuilder来代替String类.&nbsp; StringBuilder可以避免重新创建String 对象造成<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 的性能损失.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般用于组装Sql语句时用到: StringBulider.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 读者可以到自己机器上测试一下.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.尽量少用: <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 语句.此语句执行效率比较低.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>(六).ADO.Net使用方面优化<BR>&nbsp;&nbsp;&nbsp;&nbsp; 1.数据库连接打开和关闭。&nbsp; 在需要连接时打开，当访问完数据库要立刻关闭连接.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 举例说明,还是看两个代码段:<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection MyConnection = new SqlConnection("server=localhost; uid=sa; pwd=; database=NorthWind");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand myCommand = new SqlCommand(strSql,MyConnection);&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter myAdapter=new SqlDataAdapter(queryStr,connectionStr);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConnection.Open();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //打开连接<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0;i&lt;1000;i++)&nbsp;&nbsp; //for循环模拟取得数据前的商业逻辑操作<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(1000);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myAdapter.Fill(ds);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0;i&lt;1000;i++)&nbsp;&nbsp; //for循环模拟取得数据后的商业逻辑操作<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(1000);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConnection.Close();&nbsp;&nbsp;&nbsp;&nbsp; //关闭连接<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection MyConnection = new SqlConnection("server=localhost; uid=sa; pwd=; database=NorthWind");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand myCommand = new SqlCommand(strSql,MyConnection);&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter myAdapter=new SqlDataAdapter(queryStr,connectionStr);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0;i&lt;1000;i++)&nbsp;&nbsp; //for循环模拟取得数据前的商业逻辑操作<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(1000);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConnection.Open();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //打开连接<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myAdapter.Fill(ds);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConnection.Close();&nbsp;&nbsp;&nbsp;&nbsp; //关闭连接<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0;i&lt;1000;i++)&nbsp;&nbsp; ////for循环模拟取得数据后的商业逻辑操作<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(1000);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显示II代码比I代码好的多，I中早早占着连接不放，如果用户很多的话，容易出现连接池满情况。严重时出现死机现象.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.数据库查询<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I.&nbsp; 直接生成SQL语句。 Sql Server每次都要对其进行编译，在性能方面不会有很大的提高。 另外也不够安全。容易被攻击.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II. 使用带参数的SQL命令。这种方式Sql Server只对其编译一次，对于不同的参数可以重复使用编译后的命令。提高了性能.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; III.使用Sql Server存储过程. 编译一次. 具有独立性，便于修改和维护.&nbsp; 一次能完成用语句发送多次的功能.减少了网络的<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 流量。&nbsp; 并不一定存储过程一定比语句效率要高，如果商业逻辑很复杂的话，有时候用语句比存储过程效率要高.<BR>(六).缓存优化<BR>&nbsp;&nbsp;&nbsp;&nbsp; 缓存分为两种： 页面缓存和API缓存.<BR>&nbsp;&nbsp;&nbsp; 1.使用页面缓存和片段缓存&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%@ OutputCache Duration="5" VaryByParam="None"%&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%@ OutputCache Duration=60 VaryByParam=”TextBox1,TextBox2” %&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 说明: Duration是设置Cache的过期时间;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VarByParam是设置是否根据参数而变化,None时所有参数使用同一Cache,&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 设置TextBox1时则根据TextBox1的不同值分别缓存;当有多个参数时则要组合缓存;<BR>&nbsp;&nbsp;&nbsp; 2.API缓存。用于在应用程序中使用<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I. 一个Cache使用的例子:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://blog.csdn.net/chengking/archive/2005/10/03/494545.aspx">http://blog.csdn.net/chengking/archive/2005/10/03/494545.aspx</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; II.使用时注意Page.Cache和HttpContext.Current.Cache区别:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 它们指的同一个对象，在Page里，用Page.Cache，如果在global.asax或自己的类里用:HttpContext.Current.Cache<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在有些事件中，由于其没有HttpContext，就用HttpRuntime.Cache.</P>
<P>不对的地方请读者批评指正!</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:45 <a href="http://www.cnitblog.com/ChengKing/articles/4010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用IFormatter实现&gt;存储容器(功能:实现游戏保存和读取). </title><link>http://www.cnitblog.com/ChengKing/articles/4008.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:44:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4008.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4008.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4008.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4008.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4008.html</trackback:ping><description><![CDATA[<P>(一)引言</P>
<P>&nbsp;&nbsp;&nbsp; 用using System.Runtime.Serialization命名空间中的:IFormatter实现存储容器.<BR>&nbsp;&nbsp;&nbsp; 用堆栈的实现原理.&nbsp; 可以存储几乎.Net所有的对象. <BR>&nbsp;&nbsp; 本实现实现用它存储Form窗体中的所有对象,包括Label/TextBox/任意类等状态值.</P>
<P>&nbsp; 保存到文件中,并从文件中读取数据.</P>
<P>(二)代码</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 说明:&nbsp; 下面代码实现的是存储象棋游戏棋盘上的所有对象,比如: 用于保存某一时刻棋盘的位置,以及各种控件的状态值等.&nbsp; 读者可以用此方法来保存一些应用程序中的状态值等.</P>
<P>为了便于理解,把整个文件都显示出来了.主要包括两个方法: &nbsp;保存(序列化)和读取(反序列)</P>
<P>&nbsp;&nbsp;&nbsp; using System;<BR>using System.IO;<BR>using System.Drawing;<BR>using System.Runtime.Serialization;<BR>using System.Runtime.Serialization.Formatters.Binary;</P>
<P>namespace 智能象棋游戏<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// 功能:实现 游戏&nbsp;保存和读取</P>
<P>&nbsp;/// 特点:不但能够恢复断点,而且还能够在相应的断点执行退旗等操作<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Class6<BR>&nbsp;{&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; public string openFileName="..\\..\\save\\SAVA.bin";&nbsp;&nbsp; //存储文件名<BR>&nbsp;&nbsp;&nbsp;&nbsp; public string saveFileName="..\\..\\save\\SAVA.bin";&nbsp;&nbsp; //存储文件名&nbsp;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;public Class6()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;public void Save(Form2 form2)<BR>&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //******序列化Form2中的数组和变量和类*******//<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IFormatter formatter=new BinaryFormatter();&nbsp;&nbsp;&nbsp;//定义类,主要用此类中的两个方法来实现功能<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stream stream=new FileStream&nbsp;&nbsp;&nbsp;&nbsp; (this.saveFileName,FileMode.Create,FileAccess.Write,FileShare.None);&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //序列化Form2 中pictureBoxStatus数组<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.pictureBoxsStatus);</P>
<P>&nbsp;&nbsp;&nbsp;//存储象棋的当前残局,各个棋子的位置等,以及各方的分数,下棋用时等<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.battle);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; formatter.Serialize(stream,form2.soldiers);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.tempPoint);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.whetherSelected);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.letDown);<BR>&nbsp; &nbsp; &nbsp;&nbsp;formatter.Serialize(stream,form2.signRight);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.start);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.wrongString);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.startTime);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.displaystartTime);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.pause);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.whichFangQianZou);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.pauseCount);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.label3_ShanShuo);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.add_Or_Not);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.shanShuoVarialbe);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.whoGoString);</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//序列化Form2中类Class2 a中的变量和数组;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; formatter.Serialize(stream,form2.a.GenEatGen);&nbsp;formatter.Serialize (stream,form2.a.have);&nbsp;formatter.Serialize(stream,form2.a.who);&nbsp;formatter.Serialize(stream,form2.a.str);&nbsp;formatter.Serialize(stream,form2.a.allPoint);&nbsp;formatter.Serialize(stream,form2.a.partPoint);&nbsp;formatter.Serialize(stream,form2.a.whichPicture);&nbsp;formatter.Serialize(stream,form2.a.rednum);&nbsp;formatter.Serialize(stream,form2.a.bluenum);&nbsp;formatter.Serialize(stream,form2.a.width);&nbsp;formatter.Serialize(stream,form2.a.height);&nbsp;formatter.Serialize(stream,form2.a.first_X);&nbsp;formatter.Serialize(stream,form2.a.first_Y);&nbsp;formatter.Serialize(stream,form2.a.blueNumTotal);&nbsp;formatter.Serialize(stream,form2.a.redNumTotal);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//序列化Form2中类Class5 keyBoard中的变量 &nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.keyBoard.KeyBoardOperating);<BR>&nbsp;&nbsp;&nbsp;formatter.Serialize(stream,form2.keyBoard.MouseOperating);&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;stream.Close();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;public void Read(ref Form2 form2)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp; IFormatter formatter=new BinaryFormatter();<BR>&nbsp;&nbsp;&nbsp;&nbsp; Stream stream=new FileStream(this.openFileName,FileMode.Open,FileAccess.Read,FileShare.Read);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; //Form2 a=new Form2();<BR>&nbsp;&nbsp;&nbsp;&nbsp; Form2 a=form2;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; //反序列化Form2 中pictureBoxStatus数组<BR>&nbsp;&nbsp;&nbsp; &nbsp;a.pictureBoxsStatus=(bool[])formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.battle=(string)formatter.Deserialize(stream);&nbsp;<BR>&nbsp;&nbsp;&nbsp; &nbsp;a.soldiers=(string[])formatter.Deserialize(stream);<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.tempPoint=(Point[])formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp; &nbsp;a.whetherSelected=(bool)formatter.Deserialize(stream);<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.letDown=(bool)formatter.Deserialize(stream);<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.signRight=(int)formatter.Deserialize(stream);<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.start=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.wrongString=(string)formatter.Deserialize(stream);<BR>&nbsp; &nbsp;&nbsp;&nbsp;a.startTime=(DateTime)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp; &nbsp;a.displaystartTime=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.pause=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.whichFangQianZou=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.pauseCount=(int)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.label3_ShanShuo=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.add_Or_Not=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.shanShuoVarialbe=(int)formatter.Deserialize(stream);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.whoGoString=(string)formatter.Deserialize(stream);&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; //反序列化Form2中类Class5 keyBoard中的变量 <BR>&nbsp;&nbsp;&nbsp;&nbsp; a.keyBoard.KeyBoardOperating=(bool)formatter.Deserialize(stream);<BR>&nbsp;&nbsp;&nbsp;&nbsp; a.keyBoard.MouseOperating=(bool)formatter.Deserialize(stream);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<BR>&nbsp; &nbsp;&nbsp;&nbsp;stream.Close();<BR>&nbsp; &nbsp; }&nbsp;&nbsp;<BR>&nbsp; }<BR>}<BR></P>
<P></P>
<P>需要注意的一点时，在往容器里存储和从容器里读取时，要按照椎栈的原理进行存储和读取.</P>
<P>遵守“先进后出，后进先出原则”。 </P>
<P>即先放到容器里的对象，在读取时到最后才能读取出来.最后存储的对象，在读取时第一个被读取出来.<BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4008.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:44 <a href="http://www.cnitblog.com/ChengKing/articles/4008.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用SHA1或MD5 对用户身份验证的简单实现</title><link>http://www.cnitblog.com/ChengKing/articles/4009.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:44:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4009.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4009.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4009.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4009.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4009.html</trackback:ping><description><![CDATA[<P>(一).功能<BR>&nbsp;&nbsp; 用哈希算法: SHA1或MD5 实现用户账号和密码验证.<BR>&nbsp;&nbsp; 数据库存储实现原理是: 用户账号直接存储在数据库中，密码经过加密后再存储到数据库中.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当用户登录时，密码要经过加密后再与数据库中的实际存储密码比较，确定是否合法用户.<BR>(二).代码及实现&nbsp; </P>
<P>&nbsp; 1.打开命名空间:<BR>&nbsp;&nbsp;&nbsp; using System.Web.Security;</P>
<P><BR>&nbsp; 2.在用户注册界面,简要代码:&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Regist(UserID.Text,FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text,"MD5"));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //其中: "MD5",可以替换为:"SHA1",用另一种加密方式</P>
<P>&nbsp;&nbsp;&nbsp; 其中: UserID.Text表示用户ID，即注册登录帐号;&nbsp; Password.Text表示注册密码<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Regist实现将账号和加密后的密码字符串存储到数据库中.&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp; 3.在登录界面,简要代码:</P>
<P>&nbsp;&nbsp;&nbsp; Check(UserID.Text,FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text,"MD5"));&nbsp;&nbsp;&nbsp; //其中: "MD5",可以替换为:"SHA1",用另一种加密方式<BR>&nbsp;&nbsp;&nbsp; 其中: UserID.Text表示注册成功用户ID，即已经存在的登录帐号;&nbsp; Password.Text表示登录用户的密码<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Regist实现用户输入的账号和加密后的密码 与数据库中的帐号密码是否匹配.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数据库其实只是存储了加密后的字符串而已。 除了密码加密，还可以对“提示问题”“提示问题答案”等其它存储，<BR>&nbsp;&nbsp;&nbsp; 实现原理是一样的.<BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4009.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:44 <a href="http://www.cnitblog.com/ChengKing/articles/4009.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数据库连接字符串集合</title><link>http://www.cnitblog.com/ChengKing/articles/4007.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:43:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4007.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4007.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4007.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4007.html</trackback:ping><description><![CDATA[(一)常用连接:<BR>1.使用SqlConnection对象:<BR>public void SqlConnectionOpen()<BR>{<BR>&nbsp;&nbsp; SqlConnection conn= new SqlConnection();<BR>&nbsp;&nbsp; conn.ConnectionString = "user id=sa;password=;initial catalog=northwind;datasource=localhost;connect Timeout=20";<BR>&nbsp;&nbsp; conn.Open();<BR>}<BR>2.使用OleDbConnection对象:<BR>public void OleDBConnectionOpen()<BR>{<BR>&nbsp;&nbsp; OleDBConnection conn = new OleDbconnection();<BR>&nbsp;&nbsp; conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Customer.mdb";<BR>&nbsp;&nbsp; conn.Open();<BR>}<BR>(二)其它:<BR>1.ODBC连接Access本地数据库<BR>&nbsp; conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=C:\a.mdb;"+<BR>&nbsp; "Uid=Admin;"+"Pwd=;");<BR>2.ODBC连接Access系统数据库<BR>&nbsp; conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=C:\a.mdb;"+<BR>&nbsp; "SystemDB=Admin;"+"Pwd=;");<BR>3.ODBC连接Access系统数据库<BR>&nbsp; conGoodDay.Open("Driver={Microsoft Access Driver(*.mdb)};"+"Dbq=\\server\share\a.mdb;");<BR>4.ODBC连接Excel系统数据库<BR>&nbsp; conGoodDay.Open("Driver={Microsoft Access Driver(*.xls)};"+"DriverId=790;"+<BR>&nbsp; "Dbq=C:\a.xls;"+"DefaultDir=c:\somepath;");<BR>5.ODBC连接Oracle系统数据库<BR>&nbsp; conGoodDay.Open("Driver={Microsoft ODBC for Oracle};"+"Server=OracleServer.world;"+<BR>&nbsp; "Uid=Admin;"+"Pwd=password;");<BR>6.ODBC连接Sql Servr<BR>&nbsp; conGoodDay.Open("Driver={Sql Server};"+"Server=myServer;"+"Database=myDatabaseName;"<BR>&nbsp; "Uid=Admin;"+"Pwd=password;");<BR>7.ODBC连接Visual FoxPro<BR>&nbsp; conGoodDay.Open("Driver={Microsoft Visual FoxPro Driver};"+<BR>&nbsp; "SourceType=DBC;"+"SourceDB=c:a.dbc;"+"Exclusive=No;");<BR>&nbsp;<img src ="http://www.cnitblog.com/ChengKing/aggbug/4007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:43 <a href="http://www.cnitblog.com/ChengKing/articles/4007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScript使用技巧精萃</title><link>http://www.cnitblog.com/ChengKing/articles/4006.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:42:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4006.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4006.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4006.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4006.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4006.html</trackback:ping><description><![CDATA[<P>(一).确认删除用法:<BR>&nbsp; 1. BtnDel.Attributes.Add("onclick","return confirm('"+"确认删除?"+"')");<BR>&nbsp; 2. linktempDelete.Attributes["onclick"]="javascript:return&nbsp; confirm('"+"确认删除?"+"');";<BR>&nbsp; 3. private void grdProject_ItemDataBound(object sender, DataGridItemEventArgs e)<BR>&nbsp; 4.<BR>&nbsp; {<BR>&nbsp;if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem))<BR>&nbsp;{<BR>&nbsp;&nbsp;// 刪除按鈕上的提示部分<BR>&nbsp;&nbsp;e.Item.Cells[10].Attributes.Add("onclick", "return confirm('确定删除吗？');");<BR>&nbsp;}&nbsp;&nbsp;<BR>&nbsp; }<BR>&nbsp; 5.<BR>&nbsp;&nbsp;&nbsp; &lt;script language="JavaScript" type="text/JavaScript"&gt;<BR>&nbsp;function delete_y(e)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(event.srcElement.outerText == "删除")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event.returnValue=confirm("确定删除?");<BR>&nbsp;}<BR>&nbsp;document.onclick=delete_y;<BR>&nbsp;&nbsp;&nbsp; &lt;/script&gt; </P>
<P>(二).跨语言字符串替换<BR>&nbsp;&nbsp;&nbsp; System.Text.RegularExpressions.Regex.Replace(str1,@"&lt;{1}[^&lt;&gt;]*&gt;{1}","").Replace("&amp;nbsp;","").Replace("&amp;#092;","<A href="file://%22).Replace(%22%26%23045;%22,%22-%22).Replace(%22%26amp;%22,%22%26%22).Replace(%22%26lt;%22,%22%3C%22).Replace(%22%26gt;%22,%22%3E%22).Replace(%22br%22,%22/n">\\").Replace("&amp;#045;","-").Replace("&amp;amp;","&amp;").Replace("&amp;lt;","&lt;").Replace("&amp;gt;","&gt;").Replace("br","\n</A>");</P>
<P>(三).关闭窗体<BR>&nbsp;&nbsp; 1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.btnClose.Attributes.Add("onclick",&nbsp; "window.close();return false;");<BR>&nbsp;&nbsp; 2.关闭本窗体间跳转到另一个页面<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.HyperLink1.NavigateUrl = "javascript:onclick=window.opener.location.assign<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ('" + "index.aspx"+ "?&amp;Func=Edit&amp;AutoID=" + intAutoid + ');window.close();"; <BR>&nbsp;&nbsp; 3.关闭父窗体:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;INPUT type="reset" value='&lt;%=this._Cancel%&gt;' onclick="window.parent.close()"&nbsp; Class="Button"&gt;</P>
<P><BR>(四).Web MessageBox&nbsp;&nbsp; <BR>&nbsp;&nbsp; 1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write("&lt;script language=javascript&gt; window.alert('保存成功1');&lt;/script&gt;");<BR>&nbsp;&nbsp; 2.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write("&lt;script&gt;alert('"+"保存成功!"+"');&lt;/script&gt;");<BR>&nbsp;&nbsp; 3.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Page.RegisterStartupScript("ChiName","&lt;script language='javascript'&gt;alert('" + "保存成功!" + "')&lt;/script&gt;");</P>
<P>(五).DataGrid中加CheckBox控件模板列.<BR>&nbsp;&nbsp; 请看:&nbsp; <A href="http://blog.csdn.net/chengking/archive/2005/10/08/497520.aspx">http://blog.csdn.net/chengking/archive/2005/10/08/497520.aspx</A></P>
<P>(六). window.open() 方法 <BR>&nbsp;语法：window.open(pageurl,name,parameters);<BR>&nbsp;window对象的open()方法用于创建一个新的窗口实例，新创建的窗口的外观由参数：parameters指定。新窗口中打开的文档由参数：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pageurl指定。系统能够根据参数：name确定的名称访问该窗口。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下表为parameters参数表：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 参数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 衩始值&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 说明 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alwaysLowered yes/no 指定窗口隐藏在所有窗口之下。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alwaysRaised yes/no 指定窗口浮在所有窗口之上。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dependent yes/no 指定打开的窗口为父窗口的一个了窗口。并随父窗口的关闭而关闭。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; directions yes/no 指定Navigator 2和3的目录栏是否在新窗口中可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height pixel value 设定新窗口的像素高度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hotkeys yes/no 在没有菜单栏的新窗口设置安全退出热键。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; innerHeight pixel value 设置新窗口中文档的像素高度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; innerWidth pixel value 设置新窗口中文档的像素宽度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location yes/ no 指明位置栏在新窗口中是否可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; menubar yes /no 指明菜单栏在新窗口中是否可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outerHeight pixel value 设定窗口（包括装饰边框）的像素高度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outerWidth pixel value 设定窗口（包括装饰边框）的像素宽度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resizable yes /no 指明新窗口是否可以调整。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; screenX pixel value 设定新窗口离屏幕边界的像素长度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; screenY pixel value 设定新窗口离屏幕上边界的像素长度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scrollbars yes /no 指明滚动栏在新窗口中是否可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; titlebar yes /no 指明菜单题目栏在新窗口是否可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; toolbar yes /no 指明工具栏在新窗口中是否可见。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Width pixel value 设定窗口的像素宽度。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; z-look yes /no 在文档中包含各个&lt;pplet&gt;标签的数组。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fullscreen yes / no 打开的窗体是否进行全屏显示 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left pixel value 设定新窗口距屏幕左方的距离 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; top pixel value 设定新窗口距屏幕上方的距离 <BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 例子:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;head&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;window.open函数&lt;/title&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/head&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;body&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script language="javascript"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!--<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.open("","name1","width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //--&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/script&gt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/body&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/html&gt;</P>
<P>(七).location对象&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; href 整个URL字符串. <BR>&nbsp;&nbsp;&nbsp; protocol 含有URL第一部分的字符串,如http: <BR>&nbsp;&nbsp;&nbsp; host 包含有URL中主机名:端口号部分的字符串.如//www.cenpok.net/server/ <BR>&nbsp;&nbsp;&nbsp; hostname 包含URL中主机名的字符串.如<A href="http://www.cenpok.net/">http://www.cenpok.net</A> <BR>&nbsp;&nbsp;&nbsp; port 包含URL中可能存在的端口号字符串. <BR>&nbsp;&nbsp;&nbsp; pathname URL中"/"以后的部分.如~list/index.htm <BR>&nbsp;&nbsp;&nbsp; hash "#"号(CGI参数)之后的字符串. <BR>&nbsp;&nbsp;&nbsp; search "?"号(CGI参数)之后的字符串. </P>
<P>(八).按键捕捉<BR>&nbsp;&nbsp; 1.Ctrl+Enter按键捕捉方法<BR>&nbsp;&nbsp;&nbsp; &lt;body onkeydown="doKeyDown()"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;script language="JavaScript"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;!--<BR>&nbsp;&nbsp;&nbsp; function doKeyDown() <BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (event.ctrlKey &amp;&amp; event.keyCode == 13) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("You pressed the Ctrl + Enter")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; //--&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/script&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/body&gt;<BR>&nbsp;&nbsp; 2.Alt加快捷键: Alt+A<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;button accessKey=A title="Alt+A" onclick="alert('Button clicked!')"&gt;Alt+A&lt;/button&gt;<BR>(九).控制输入，非法字符不能输入到TextBox.<BR>&nbsp;&nbsp;&nbsp; &lt;asp:textbox class="Text" <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onkeypress="if (event.keyCode &lt; 48 || event.keyCode &gt;57) event.returnValue = false;"<BR>&nbsp;id="txtY_Revenue" style="TEXT-ALIGN: right" runat="server" Width="90%" MaxLength="12"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/asp:textbox&gt;<BR>&nbsp;&nbsp;&nbsp; 说明： 此方法控制TextBox只收数字：0~9 , 也自可以定义其它可输入字符,如改成: 65~123,只允许输入: a~z和A~Z 等.</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4006.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:42 <a href="http://www.cnitblog.com/ChengKing/articles/4006.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScript实现DataGrid中的CheckBox全选与否 </title><link>http://www.cnitblog.com/ChengKing/articles/4005.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:41:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4005.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4005.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4005.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4005.html</trackback:ping><description><![CDATA[<P>(一).功能</P>
<P>&nbsp;&nbsp;&nbsp; 1. JavaScript检索CheckBox并实现全选和全消功能</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 用C#等写的CheckBox需要回发到服务端执行，<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;而用JavaScript可以在直接客户端实现,效率高些</P>
<P>(二).代码</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. DataGrid中的代码主要片段:</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Columns&gt;</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;HeaderTemplate&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //头模板代码<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;asp:CheckBox id="chkHeader" runat="server" AutoPostBack="False"&nbsp;&nbsp; //AutoPostBack设为假，不需要回发</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onclick="javascript:SelectAll(this);"&gt;&lt;/asp:CheckBox&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/HeaderTemplate&gt;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //项模板代码<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;asp:CheckBox id="chkItem" runat="server"&gt;&lt;/asp:CheckBox&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Columns&gt;</P>
<P>2.&nbsp; 在当页加入:</P>
<P>&nbsp;&nbsp;&lt;script language="javascript"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function SelectAll(tempControl)<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//将除头模板中的其它所有的CheckBox取反&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;var theBox=tempControl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;xState=theBox.checked;&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;elem=theBox.form.elements;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for(i=0;i&lt;elem.length;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(elem[i].type=="checkbox" &amp;&amp; elem[i].id!=theBox.id)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(elem[i].checked!=xState)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elem[i].click();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;}&nbsp;&nbsp;<BR>&lt;/script&gt;</P>
<P></P>
<P>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:41 <a href="http://www.cnitblog.com/ChengKing/articles/4005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DerectX7实现播放音乐效果</title><link>http://www.cnitblog.com/ChengKing/articles/4004.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:40:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4004.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4004.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4004.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4004.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4004.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>using DxVBLib;</P>
<P>namespace 播放音乐<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;directX=new DirectX7Class();<BR>&nbsp;&nbsp;&nbsp;performance=directX.DirectMusicPerformanceCreate();<BR>&nbsp;&nbsp;&nbsp;composer=directX.DirectMusicComposerCreate();<BR>&nbsp;&nbsp;&nbsp;loader=directX.DirectMusicLoaderCreate();</P>
<P>&nbsp;&nbsp;&nbsp;performance.Init(null,0);<BR>&nbsp;&nbsp;&nbsp;performance.SetPort(-1,4);<BR>&nbsp;&nbsp;&nbsp;performance.SetMasterAutoDownload(true);</P>
<P>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//chordMap=loader.LoadChordMap(@"F:\游戏音乐(mid)\GAME01FM.MID");<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;chordMap=loader.LoadChordMap("CHORDMAP.CDM");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch (Exception)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show("Could not load ChordMap."+"Please ensure that CHORDMAP.CDM is"+"in the directory of this exectutable.");<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(96, 192);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.Click += new System.EventHandler(this.button1_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private DirectX7 directX;<BR>&nbsp;&nbsp;private DirectMusicChordMap chordMap;<BR>&nbsp;&nbsp;private DirectMusicComposer composer;<BR>&nbsp;&nbsp;private DirectMusicPerformance performance;<BR>&nbsp;&nbsp;private DirectMusicSegment segment;<BR>&nbsp;&nbsp;private DirectMusicLoader loader;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1;<BR>&nbsp;&nbsp;private DirectMusicStyle style;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void button1_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;style=loader.LoadStyle(@"F:\游戏音乐(mid)\GAME01FM.MID");<BR>&nbsp;&nbsp;&nbsp;&nbsp;segment=composer.ComposeSegmentFromShape(style,64,0,2,false,false,chordMap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;composer.AutoTransition(performance,segment,(int)CONST_DMUS_COMMANDT_TYPES.DMUS_COMMANDT_FILL,(int)CONST_DMUS_COMPOSEF_FLAGS.DMUS_COMPOSEF_IMMEDIATE,chordMap);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(Exception)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show("不能播放音乐");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4004.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:40 <a href="http://www.cnitblog.com/ChengKing/articles/4004.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 用Process调用其它应用程序</title><link>http://www.cnitblog.com/ChengKing/articles/4002.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:38:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4002.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4002.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4002.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4002.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;<BR>using System.Diagnostics;</P>
<P>namespace WindowsApplication3<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;private System.ComponentModel.IContainer components;</P>
<P>&nbsp;&nbsp;private System.Diagnostics.Process process;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1; <BR>&nbsp;&nbsp;//Form2 a;<BR>&nbsp;&nbsp;//Graphics g=pictureBox1.CreateGraphics();<BR>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(136, 144);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.Click += new System.EventHandler(this.button1_Click_1);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(344, 302);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.HelpButton = true;<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.Form1_HelpRequested);<BR>&nbsp;&nbsp;&nbsp;this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}&nbsp;</P>
<P>&nbsp;&nbsp;private void Form1_HelpRequested(object sender, System.Windows.Forms.HelpEventArgs hlpevent)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void button1_Click_1(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;process=new Process();&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;process.StartInfo.FileName="skate.exe";<BR>&nbsp;&nbsp;&nbsp;<A>//process.StartInfo.FileName=@"F:\c#\</A>拼图游戏2\bin\Release\拼图游戏2.exe";<BR>&nbsp;&nbsp;&nbsp;this.process.Start();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<BR>&nbsp;&nbsp;{&nbsp;<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}<BR></P>
<P>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:38 <a href="http://www.cnitblog.com/ChengKing/articles/4002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control study -&gt; Drag拖放事件示例 </title><link>http://www.cnitblog.com/ChengKing/articles/4003.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:38:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4003.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4003.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4003.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4003.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4003.html</trackback:ping><description><![CDATA[<P>(一).功能描述</P>
<P>&nbsp;&nbsp; 涉及到DragEnter DragDrop DragLeave DragOver QueryContinueDrag事件用法的一个例子</P>
<P>(二).代码</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>namespace 拖放数据操作_按键事件_<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1;<BR>&nbsp;&nbsp;private System.Windows.Forms.TextBox textBox1;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.textBox1 = new System.Windows.Forms.TextBox();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(112, 72);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.button1_QueryContinueDrag);<BR>&nbsp;&nbsp;&nbsp;this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// textBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.textBox1.AccessibleDescription = "aaaaa";<BR>&nbsp;&nbsp;&nbsp;this.textBox1.AccessibleName = "bbbbbb";<BR>&nbsp;&nbsp;&nbsp;this.textBox1.AllowDrop = true;<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Location = new System.Drawing.Point(64, 160);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Multiline = true;<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Name = "textBox1";<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Size = new System.Drawing.Size(168, 48);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.textBox1.Text = "";<BR>&nbsp;&nbsp;&nbsp;this.textBox1.DragOver += new System.Windows.Forms.DragEventHandler(this.textBox1_DragOver);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.textBox1_DragDrop);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.textBox1_DragEnter);<BR>&nbsp;&nbsp;&nbsp;this.textBox1.DragLeave += new System.EventHandler(this.textBox1_DragLeave);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.textBox1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void button1_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.EscapePressed)<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Action=DragAction.Cancel;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;button1.DoDragDrop(button1.Text,DragDropEffects.Copy|DragDropEffects.Move);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void textBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.Data.GetDataPresent(DataFormats.Text))<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Effect=DragDropEffects.Copy;<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Effect=DragDropEffects.None;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void textBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//使用KeyState属性<BR>&nbsp;&nbsp;&nbsp;if((e.KeyState&amp;(1&lt;&lt;3))!=0)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if((e.AllowedEffect&amp;DragDropEffects.Copy)!=0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Effect=DragDropEffects.Copy;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textBox1.Text=e.Data.GetData(DataFormats.Text).ToString();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Effect=DragDropEffects.Move;<BR>&nbsp;&nbsp;&nbsp;&nbsp;textBox1.Text=e.Data.GetData(DataFormats.Text).ToString();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void textBox1_DragLeave(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;textBox1.Text="执行 DragLeave";<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void textBox1_DragOver(object sender, System.Windows.Forms.DragEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;textBox1.Text="执行 DragOver";<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}<BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4003.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:38 <a href="http://www.cnitblog.com/ChengKing/articles/4003.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 实现:用鼠标拖动图片</title><link>http://www.cnitblog.com/ChengKing/articles/4001.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:37:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4001.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4001.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4001.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4001.html</trackback:ping><description><![CDATA[<P>(一).说明</P>
<P>&nbsp;&nbsp;&nbsp; 功能:用鼠标实现拖动图片.<BR>&nbsp;&nbsp;&nbsp; 用法:将鼠标指向一图片,按住鼠标左键拖动. 图片会随鼠标一起移动.</P>
<P>(二).代码</P>
<P>&nbsp;&nbsp;&nbsp; (说明: 此功能我用的用途是将象棋游戏之棋子拖动效果)</P>
<P>&nbsp;&nbsp;&nbsp; 读者可以将此功能用作其它用途,也可以用作设计其它的游戏.</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;<BR>using System.Threading;</P>
<P>namespace 拖动图片<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;public System.Windows.Forms.PictureBox[] pictureBox=new PictureBox[2];<BR>&nbsp;&nbsp;//private System.Windows.Forms.PictureBox pictureBox2;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();<BR>&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;2;i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pictureBox[i].MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pictureBox[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pictureBox[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows Form Designer generated code<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0] = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1] = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].BackColor = System.Drawing.Color.Transparent;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].Location = new System.Drawing.Point(200, 192);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].Name = "pictureBox1";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].Size = new System.Drawing.Size(88, 72);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[0].TabStop = false;<BR>&nbsp;&nbsp;&nbsp;/*this.pictureBox[1].MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);*/<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox2<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;//this.Opacity=0.8;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].BackColor = System.Drawing.Color.DodgerBlue;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].Location = new System.Drawing.Point(200, 72);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].Name = "pictureBox2";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].Size = new System.Drawing.Size(88, 64);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[1].TabStop = false;<BR>&nbsp;&nbsp;&nbsp;/*this.pictureBox[2].MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[2].MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox[2].MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);<BR>&nbsp;&nbsp;&nbsp;*/<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(432, 348);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.pictureBox[0]);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.pictureBox[1]);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool whetherSelected=false;<BR>&nbsp;&nbsp;Point p=new Point();</P>
<P>&nbsp;&nbsp;#region 事件代码<BR>&nbsp;&nbsp;private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; whetherSelected=true;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;p.X=Cursor.Position.X;<BR>&nbsp;&nbsp;&nbsp;p.Y=Cursor.Position.Y;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;whetherSelected=false;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(whetherSelected==true) <BR>&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//加入一个函数,得到是哪个pictureBox<BR>&nbsp;&nbsp;&nbsp;&nbsp;int index=-1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;2;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(this.pictureBox[i].Capture)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index=i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pictureBox[index].Left=this.pictureBox[index].Left+(Cursor.Position.X-p.X);<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pictureBox[index].Top=this.pictureBox[index].Top+(Cursor.Position.Y-p.Y);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.pictureBox[1-index].SendToBack();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;p.X=Cursor.Position.X;<BR>&nbsp;&nbsp;&nbsp;&nbsp;p.Y=Cursor.Position.Y;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4001.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:37 <a href="http://www.cnitblog.com/ChengKing/articles/4001.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control study -&gt; 图像格式转换 如:将*.jpg -&gt; *.gif进行转换</title><link>http://www.cnitblog.com/ChengKing/articles/4000.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:36:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/4000.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/4000.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/4000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/4000.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/4000.html</trackback:ping><description><![CDATA[<P>(一).功能</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个演示图像格式转换的示例程序.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 支持格式:&nbsp; bmp jpeg gif tiff png wmf 等之间的相互转换</P>
<P>(二).代码(整个后台代码)</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;<BR>using System.IO;<BR>using System.Drawing.Imaging;<BR>namespace 图像格式转换<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class FormMain : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;private System.Windows.Forms.Panel panel1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Splitter splitter1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Panel panel2;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button buttonOpen;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button buttonConvert;<BR>&nbsp;&nbsp;private System.Windows.Forms.ComboBox comboBox;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label2;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;<BR>&nbsp;&nbsp;private System.Windows.Forms.PictureBox pictureBox;<BR>&nbsp;&nbsp;private System.Drawing.Bitmap bitmap;</P>
<P>&nbsp;&nbsp;public FormMain()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;bitmap=null;<BR>&nbsp;&nbsp;&nbsp;pictureBox.Width=panel2.Width;<BR>&nbsp;&nbsp;&nbsp;pictureBox.Height=panel2.Height;<BR>&nbsp;&nbsp;&nbsp;pictureBox.Top=panel1.Top;<BR>&nbsp;&nbsp;&nbsp;pictureBox.Left=panel1.Left;<BR>&nbsp;&nbsp;&nbsp;panel2.Resize+=new System.EventHandler(panel2_Resize);<BR>&nbsp;&nbsp;&nbsp;//buttonOpen.Click+=new System.EventHandler(buttonOpen_Click);<BR>&nbsp;&nbsp;&nbsp;comboBox.Items.AddRange(new object[]{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.jpg",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.bmp",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.gif",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.png",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.tif",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "*.wmf"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows Form Designer generated code<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.panel1 = new System.Windows.Forms.Panel();<BR>&nbsp;&nbsp;&nbsp;this.buttonConvert = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.comboBox = new System.Windows.Forms.ComboBox();<BR>&nbsp;&nbsp;&nbsp;this.label1 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.label2 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.splitter1 = new System.Windows.Forms.Splitter();<BR>&nbsp;&nbsp;&nbsp;this.panel2 = new System.Windows.Forms.Panel();<BR>&nbsp;&nbsp;&nbsp;this.pictureBox = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;this.panel1.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;this.panel2.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// panel1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;<BR>&nbsp;&nbsp;&nbsp;this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.buttonConvert,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.buttonOpen,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.comboBox,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.label1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.label2});<BR>&nbsp;&nbsp;&nbsp;this.panel1.Dock = System.Windows.Forms.DockStyle.Left;<BR>&nbsp;&nbsp;&nbsp;this.panel1.Name = "panel1";<BR>&nbsp;&nbsp;&nbsp;this.panel1.Size = new System.Drawing.Size(128, 365);<BR>&nbsp;&nbsp;&nbsp;this.panel1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// buttonConvert<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.buttonConvert.Location = new System.Drawing.Point(40, 264);<BR>&nbsp;&nbsp;&nbsp;this.buttonConvert.Name = "buttonConvert";<BR>&nbsp;&nbsp;&nbsp;this.buttonConvert.Size = new System.Drawing.Size(56, 24);<BR>&nbsp;&nbsp;&nbsp;this.buttonConvert.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.buttonConvert.Text = "转换";<BR>&nbsp;&nbsp;&nbsp;buttonConvert.Click+=new System.EventHandler(buttonConvert_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// buttonOpen<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.Location = new System.Drawing.Point(32, 56);<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.Name = "buttonOpen";<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.Size = new System.Drawing.Size(64, 24);<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.Text = "打开文件";<BR>&nbsp;&nbsp;&nbsp;this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// comboBox<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.comboBox.Location = new System.Drawing.Point(64, 224);<BR>&nbsp;&nbsp;&nbsp;this.comboBox.Name = "comboBox";<BR>&nbsp;&nbsp;&nbsp;this.comboBox.Size = new System.Drawing.Size(48, 20);<BR>&nbsp;&nbsp;&nbsp;this.comboBox.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.comboBox.Text = "comboBox1";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label1.Location = new System.Drawing.Point(24, 104);<BR>&nbsp;&nbsp;&nbsp;this.label1.Name = "label1";<BR>&nbsp;&nbsp;&nbsp;this.label1.Size = new System.Drawing.Size(80, 40);<BR>&nbsp;&nbsp;&nbsp;this.label1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.label1.Text = "label1";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label2<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label2.Location = new System.Drawing.Point(8, 224);<BR>&nbsp;&nbsp;&nbsp;this.label2.Name = "label2";<BR>&nbsp;&nbsp;&nbsp;this.label2.Size = new System.Drawing.Size(48, 16);<BR>&nbsp;&nbsp;&nbsp;this.label2.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.label2.Text = "转换为";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// splitter1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.splitter1.Location = new System.Drawing.Point(128, 0);<BR>&nbsp;&nbsp;&nbsp;this.splitter1.Name = "splitter1";<BR>&nbsp;&nbsp;&nbsp;this.splitter1.Size = new System.Drawing.Size(3, 365);<BR>&nbsp;&nbsp;&nbsp;this.splitter1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.splitter1.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// panel2<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;<BR>&nbsp;&nbsp;&nbsp;this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.pictureBox});<BR>&nbsp;&nbsp;&nbsp;this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;<BR>&nbsp;&nbsp;&nbsp;this.panel2.Location = new System.Drawing.Point(131, 0);<BR>&nbsp;&nbsp;&nbsp;this.panel2.Name = "panel2";<BR>&nbsp;&nbsp;&nbsp;this.panel2.Size = new System.Drawing.Size(373, 365);<BR>&nbsp;&nbsp;&nbsp;this.panel2.TabIndex = 2;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox.Name = "pictureBox";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox.Size = new System.Drawing.Size(369, 361);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// FormMain<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(504, 365);<BR>&nbsp;&nbsp;&nbsp;this.Controls.AddRange(new System.Windows.Forms.Control[] {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.panel2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.splitter1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.panel1});<BR>&nbsp;&nbsp;&nbsp;this.Name = "FormMain";<BR>&nbsp;&nbsp;&nbsp;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;<BR>&nbsp;&nbsp;&nbsp;this.Text = "FormMain";<BR>&nbsp;&nbsp;&nbsp;this.panel1.ResumeLayout(false);<BR>&nbsp;&nbsp;&nbsp;this.panel2.ResumeLayout(false);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new FormMain());<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void buttonOpen_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;OpenFileDialog openFileDialog=new OpenFileDialog();<BR>&nbsp;&nbsp;&nbsp;openFileDialog.Filter="*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";<BR>&nbsp;&nbsp;&nbsp;openFileDialog.Title="打开图像文件";<BR>&nbsp;&nbsp;&nbsp;openFileDialog.Multiselect=false;<BR>&nbsp;&nbsp;&nbsp;if(openFileDialog.ShowDialog()==DialogResult.OK)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(bitmap!=null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;string fileName=openFileDialog.FileName;<BR>&nbsp;&nbsp;&nbsp;&nbsp;bitmap=new Bitmap(fileName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(bitmap.Width&gt;bitmap.Width)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Width=panel2.Width;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Height=(int)((double)bitmap.Height*panel2.Width/bitmap.Width);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Height=panel2.Height;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pictureBox.Width=(int)((double)bitmap.Width*panel2.Height/bitmap.Height);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Image=bitmap;<BR>&nbsp;&nbsp;&nbsp;&nbsp;FileInfo f=new FileInfo(fileName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.Text="图象转换:"+f.Name;<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.label1.Text=f.Name;<BR>&nbsp;&nbsp;&nbsp;&nbsp;buttonConvert.Enabled=true;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void panel2_Resize(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;pictureBox.Top=panel1.Top;<BR>&nbsp;&nbsp;&nbsp;pictureBox.Left=panel1.Left;<BR>&nbsp;&nbsp;&nbsp;if(bitmap!=null)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(bitmap.Width&gt;bitmap.Height)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Width=panel2.Width;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Height=(int)((double) bitmap.Height*panel2.Width/bitmap.Width);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Height=panel2.Height;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Width=(int)((double)bitmap.Width*panel2.Height/bitmap.Height);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Width=panel2.Width;<BR>&nbsp;&nbsp;&nbsp;&nbsp;pictureBox.Height=panel2.Height;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;pictureBox.Refresh();<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void buttonConvert_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(comboBox.SelectedItem==null)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;return;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;SaveFileDialog saveFileDialog=new SaveFileDialog();<BR>&nbsp;&nbsp;&nbsp;&nbsp;saveFileDialog.Title="转化为:";<BR>&nbsp;&nbsp;&nbsp;&nbsp;saveFileDialog.OverwritePrompt=true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveFileDialog.CheckPathExists=true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;saveFileDialog.Filter=comboBox.Text+"|"+comboBox.Text;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(saveFileDialog.ShowDialog()==DialogResult.OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string fileName=saveFileDialog.FileName;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(comboBox.Text)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case "*.bmp":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Bmp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "*.jpg":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Jpeg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "*.gif":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Gif);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "*.tif":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Tiff);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "*.png":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Png);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "*.wmf":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Save(fileName,ImageFormat.Wmf);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInfo f=new FileInfo(fileName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.Text="图像转换:"+f.Name;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label1.Text=f.Name;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/4000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:36 <a href="http://www.cnitblog.com/ChengKing/articles/4000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 模拟鼠标 </title><link>http://www.cnitblog.com/ChengKing/articles/3999.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:31:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3999.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3999.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3999.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3999.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3999.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>namespace 模拟鼠标<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1 = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;this.label1 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Location = new System.Drawing.Point(88, 120);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Name = "pictureBox1";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.pictureBox1_KeyDown);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label1.BackColor = System.Drawing.Color.DarkOliveGreen;<BR>&nbsp;&nbsp;&nbsp;this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;<BR>&nbsp;&nbsp;&nbsp;this.label1.Location = new System.Drawing.Point(48, 208);<BR>&nbsp;&nbsp;&nbsp;this.label1.Name = "label1";<BR>&nbsp;&nbsp;&nbsp;this.label1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.label1.Text = "label1";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(292, 266);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.label1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.pictureBox1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);<BR>&nbsp;&nbsp;&nbsp;this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);<BR>&nbsp;&nbsp;&nbsp;this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;[System.Runtime.InteropServices.DllImport("user32")]<BR>&nbsp;&nbsp;&nbsp;&nbsp; private static extern int mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MOVE=0x0001;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_LEFTDOWN=0X0002;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_LEFTUP=0X0004;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_RIGHTDOWN=0X0008;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_RIGHTUP=0X0010;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MIDDLEDOWN=0X0020;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_MIDDLEUP=0X0040;<BR>&nbsp;&nbsp;private System.Windows.Forms.PictureBox pictureBox1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label1;<BR>&nbsp;&nbsp;const int MOUSEEVENTF_ABSOLUTE=0X8000;</P>
<P>&nbsp;&nbsp;private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//mouse_event(MOUSEEVENTF_MOVE,-10,-10,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Down)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Up)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Left)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,-20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,20,0,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;public void pictureBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;/*if(e.KeyCode==Keys.Down)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Up)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Left)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,-20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;if(e.KeyCode==Keys.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,20,0,0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;*/<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;</P>
<P>&nbsp;&nbsp;private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.Button==MouseButtons.Right)<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,20,0,0);<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;mouse_event(MOUSEEVENTF_MOVE,0,-20,0,0);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}</P>
<P><BR>&nbsp;&nbsp;<BR>&nbsp;<BR>&nbsp;}<BR>}<BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:31 <a href="http://www.cnitblog.com/ChengKing/articles/3999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 放大图像区域</title><link>http://www.cnitblog.com/ChengKing/articles/3997.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:30:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3997.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3997.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3997.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3997.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3997.html</trackback:ping><description><![CDATA[<P>(一).说明</P>
<P>&nbsp; 将鼠标指向一幅图片的一块区域,此区域会放大显示,变清晰.<BR>用类: Graphics 实现.</P>
<P>(二).代码&nbsp;&nbsp;</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;<BR>using System.Drawing.Drawing2D;</P>
<P>namespace 放大图像区域<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Form1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;private System.Windows.Forms.PictureBox pictureBox1;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 必需的设计器变量。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private System.ComponentModel.Container components = null;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button button1;<BR>&nbsp;&nbsp;//private Cursor myCursor;<BR>&nbsp;&nbsp;Cursor myCursor=new Cursor("..\\..\\MAGNIFY.cur"); //自定义鼠标<BR>&nbsp;&nbsp;Graphics g;<BR>&nbsp;&nbsp;Image myImage;</P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Windows 窗体设计器支持所必需的<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在 InitializeComponent 调用后添加任何构造函数代码<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 清理所有正在使用的资源。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#region Windows 窗体设计器生成的代码<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 设计器支持所需的方法 - 不要使用代码编辑器修改<BR>&nbsp;&nbsp;/// 此方法的内容。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1 = new System.Windows.Forms.PictureBox();<BR>&nbsp;&nbsp;&nbsp;this.button1 = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// pictureBox1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Location = new System.Drawing.Point(24, 16);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Name = "pictureBox1";<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.Size = new System.Drawing.Size(440, 384);<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// button1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.button1.Location = new System.Drawing.Point(384, 96);<BR>&nbsp;&nbsp;&nbsp;this.button1.Name = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.button1.Text = "button1";<BR>&nbsp;&nbsp;&nbsp;this.button1.Click += new System.EventHandler(this.button1_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);<BR>&nbsp;&nbsp;&nbsp;this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(472, 406);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.button1);<BR>&nbsp;&nbsp;&nbsp;this.Controls.Add(this.pictureBox1);<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);<BR>&nbsp;&nbsp;&nbsp;this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Cursor.Current=myCursor;<BR>&nbsp;&nbsp;&nbsp;Rectangle sourceRectangle=new Rectangle(e.X-10,e.Y-10,20,20);&nbsp;&nbsp;//要放大的区域<BR>&nbsp;&nbsp;&nbsp;//Rectangle destRectangle=new Rectangle(e.X-20,e.Y-20,40,40);<BR>&nbsp;&nbsp;&nbsp;Rectangle destRectangle=new Rectangle(pictureBox1.Width-150,pictureBox1.Height-150,pictureBox1.Width,pictureBox1.Height);&nbsp;&nbsp; //放大的比例<BR>&nbsp;&nbsp;&nbsp;g.DrawLine(myImage,destRectangle,sourceRectangle,GraphicsUnit.Pixel);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Cursor.Current=Cursors.Default;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{&nbsp;<BR>&nbsp;&nbsp;&nbsp;g=this.pictureBox1.CreateGraphics();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;myImage=this.pictureBox1.Image;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void button1_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;//Graphics g=this.pictureBox1.CreateGraphics();<BR>&nbsp;&nbsp;&nbsp;Graphics g=pictureBox1.CreateGraphics();<BR>&nbsp;&nbsp;&nbsp;g.DrawLine(new Pen(Color.Red,5),20,20,50,50);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3997.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:30 <a href="http://www.cnitblog.com/ChengKing/articles/3997.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Control Study -&gt; 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形)</title><link>http://www.cnitblog.com/ChengKing/articles/3998.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:30:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3998.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3998.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3998.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3998.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3998.html</trackback:ping><description><![CDATA[<P>(一).功能</P>
<P>     有时候由于显示效果,需要将某个控件变一下形状.<BR>     本文举例将PictureBox[]数组变成圆形.</P>
<P>(二).代码</P>
<P>    (这里说明一下,我个人将它变形是因为我用PictureBox表示象棋棋子,</P>
<P>     由于PictureBox默认是方 的,  所以得把它变成圆的)</P>
<P>     大家可以将这个功能作为其它用途使用.</P>
<P>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P><BR>namespace 智能象棋游戏<BR>{<BR> /// <summary><BR> /// 功能:将所有picturebox控件变为圆形<BR> /// 特点:使旗子变圆形</P>
<P> /// </summary></P>
<P> public class Class7<BR> {<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern IntPtr BeginPath(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern int SetBkMode(IntPtr hdc,int nBkMode);  <BR>  const int TRANSPARENT=1;<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]     <BR>  private static extern IntPtr EndPath(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern IntPtr PathToRegion(IntPtr hdc);<BR>  [System.Runtime.InteropServices.DllImport("gdi32")]<BR>  private static extern int Ellipse(IntPtr hdc,int x1,int y1,int x2,int y2);<BR>  [System.Runtime.InteropServices.DllImport("user32")]<BR>  private static extern IntPtr SetWindowRgn(IntPtr hwnd,IntPtr hRgn,bool bRedraw);<BR>  [System.Runtime.InteropServices.DllImport("user32")]<BR>  private static extern IntPtr GetDC(IntPtr hwnd);<BR>  public Class7()<BR>  {   <BR>  }<BR>  public void MakeToPictureBoxsToCircle(PictureBox[] pb)<BR>  {<BR>   IntPtr dc;<BR>   IntPtr region;<BR>   for(int i=0;i<pb.Length;i++)<BR>   {<BR>    dc=GetDC(pb[i].Handle);<BR>    BeginPath(dc);<BR>    SetBkMode(dc,TRANSPARENT);<BR>    Ellipse(dc,0,0,pb[i].Width-3,pb[i].Height-2);<BR>    EndPath(dc);<BR>    region=PathToRegion(dc);<BR>    SetWindowRgn(pb[i].Handle,region,false);<BR>   }   <BR>  }<BR> }<BR>}</P>
<P></P>
<P><BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3998.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:30 <a href="http://www.cnitblog.com/ChengKing/articles/3998.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Collection -&gt; 由IComparer派生的自定义比较器</title><link>http://www.cnitblog.com/ChengKing/articles/3996.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:28:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3996.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3996.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3996.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3996.html</trackback:ping><description><![CDATA[<P>(一). 说明</P>
<P>1.继承IComparer接口,可以自定义比较器<BR>2.由于Array.Sort()方法接受IComparer参数,进行自定义排序规则.<BR>&nbsp;&nbsp; 示例中也将IComparer作为Sort方法的参数,将Icomparer应用于Array.Sort()方法</P>
<P>(二).示例代码</P>
<P>using System;<BR>using System.Collections;</P>
<P>namespace 比较器IComparer<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Class1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class Person<BR>&nbsp;{<BR>&nbsp;&nbsp;public int ID;<BR>&nbsp;&nbsp;public int Age;<BR>&nbsp;&nbsp;public Person()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;ID=0;<BR>&nbsp;&nbsp;&nbsp;Age=0;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;public Person(int id,int age)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;ID=id;<BR>&nbsp;&nbsp;&nbsp;Age=age;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;public void Show()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("年龄={0},代号={1}",Age,ID);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;public static void&nbsp; ShowPersons(Person []persons)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;foreach(Person person in persons)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine("年龄={0},代号={1}",person.Age,person.ID);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;public class PersonComparer:System.Collections.IComparer<BR>&nbsp;{<BR>&nbsp;&nbsp;int System.Collections.IComparer.Compare(object x,object y)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(x==null||y==null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentException("参数不能为空");&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;Person temp=new Person();<BR>&nbsp;&nbsp;&nbsp;if(!x.GetType().Equals(temp.GetType())||!y.GetType().Equals(temp.GetType()))<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw new ArgumentException("类型不一致");<BR>&nbsp;&nbsp;&nbsp;temp=null;<BR>&nbsp;&nbsp;&nbsp;Person personX=(Person)x;<BR>&nbsp;&nbsp;&nbsp;Person personY=(Person)y;<BR>&nbsp;&nbsp;&nbsp;if(personX.ID&gt;personY.ID)<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 1;<BR>&nbsp;&nbsp;&nbsp;if(personX.ID&lt;personY.ID)<BR>&nbsp;&nbsp;&nbsp;&nbsp;return -1;<BR>&nbsp;&nbsp;&nbsp;if(personX.Age&gt;personY.Age)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;<BR>&nbsp;&nbsp;&nbsp;if(personX.Age&lt;personY.Age)<BR>&nbsp;&nbsp;&nbsp;&nbsp;return -1;<BR>&nbsp;&nbsp;&nbsp;return 0;<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;class Class1<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main(string[] args)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在此处添加代码以启动应用程序<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;Random rand=new Random();<BR>&nbsp;&nbsp;&nbsp;Person[] persons=new Person[6];<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("随机产生的Person数组为:");<BR>&nbsp;&nbsp;&nbsp;for(int i=0;i&lt;persons.GetLength(0);i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;persons[i]=new Person();<BR>&nbsp;&nbsp;&nbsp;&nbsp;persons[i].ID=rand.Next()%10;<BR>&nbsp;&nbsp;&nbsp;&nbsp;persons[i].Age=rand.Next()%50;<BR>&nbsp;&nbsp;&nbsp;&nbsp;persons[i].Show();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;PersonComparer personComparer=new PersonComparer();<BR>&nbsp;&nbsp;&nbsp;//System.Collections.IComparer personComparer=new IComparer;<BR>&nbsp;&nbsp;&nbsp;Array.Sort(persons,personComparer);<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("排序后的结果:");<BR>&nbsp;&nbsp;&nbsp;Person.ShowPersons(persons);<BR>&nbsp;&nbsp;&nbsp;Person personToBeFind=new Person();<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("输入ID");<BR>&nbsp;&nbsp;&nbsp;personToBeFind.ID=int.Parse(Console.ReadLine());<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("输入Age");<BR>&nbsp;&nbsp;&nbsp;personToBeFind.Age=int .Parse(Console.ReadLine());<BR>&nbsp;&nbsp;&nbsp;int index=Array.BinarySearch(persons,personToBeFind,personComparer);<BR>&nbsp;&nbsp;&nbsp;if(index&gt;=0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine("待查找的元素是数组的第{0}个元素",index+1);<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine("对不起,没有所找的元素");<BR>&nbsp;&nbsp;&nbsp;Console.ReadLine();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P></P>
<P><BR>&nbsp;</P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:28 <a href="http://www.cnitblog.com/ChengKing/articles/3996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Collection -&gt; Array的排序(正序/逆序)</title><link>http://www.cnitblog.com/ChengKing/articles/3995.html</link><dc:creator>ZhengJian</dc:creator><author>ZhengJian</author><pubDate>Sun, 06 Nov 2005 04:27:00 GMT</pubDate><guid>http://www.cnitblog.com/ChengKing/articles/3995.html</guid><wfw:comment>http://www.cnitblog.com/ChengKing/comments/3995.html</wfw:comment><comments>http://www.cnitblog.com/ChengKing/articles/3995.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/ChengKing/comments/commentRss/3995.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/ChengKing/services/trackbacks/3995.html</trackback:ping><description><![CDATA[<P>using System;</P>
<P>namespace Array操作<BR>{<BR>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// Class1 的摘要说明。<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;class Class1<BR>&nbsp;{<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// 应用程序的主入口点。<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main(string[] args)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: 在此处添加代码以启动应用程序<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;String[] friends=new String[]{"2mojian","1zhengjian","3xugang","4guoyonghui"};<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("操作前数组数据为:");<BR>&nbsp;&nbsp;&nbsp;foreach(string index in friends)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(index+" ");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;Array.Sort(friends);<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("\n排序后的数据为:");<BR>&nbsp;&nbsp;&nbsp;for(int i=friends.GetLowerBound(0);i&lt;=friends.GetUpperBound(0);i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(friends[i]+" ");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;Array.Reverse(friends);<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine("\n逆序后的数据为:");<BR>&nbsp;&nbsp;&nbsp;for(int i=friends.GetLowerBound(0);i&lt;=friends.GetUpperBound(0);i++)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(friends[i]+" ");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;Console.WriteLine();<BR>&nbsp;&nbsp;&nbsp;Console.Read();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}<BR></P><img src ="http://www.cnitblog.com/ChengKing/aggbug/3995.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/ChengKing/" target="_blank">ZhengJian</a> 2005-11-06 12:27 <a href="http://www.cnitblog.com/ChengKing/articles/3995.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>