<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>爱人-爱人的大杂烩 &#187; vb.net</title>
	<atom:link href="http://ai-2.cn/category/programming/vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://ai-2.cn</link>
	<description>一切研究的资料库</description>
	<lastBuildDate>Thu, 09 Sep 2010 06:15:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>手机手写笔长按动作消息事件响应</title>
		<link>http://ai-2.cn/2009/09/wm_lbuttondown/</link>
		<comments>http://ai-2.cn/2009/09/wm_lbuttondown/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:51:51 +0000</pubDate>
		<dc:creator>csecong</dc:creator>
				<category><![CDATA[vb.net]]></category>
		<category><![CDATA[右键菜单]]></category>
		<category><![CDATA[手写笔长按]]></category>
		<category><![CDATA[手机右键]]></category>

		<guid isPermaLink="false">http://ai-2.cn/?p=184</guid>
		<description><![CDATA[如何响应手写笔长按动作消息，一开始走了弯路，想到用API拦截，其实很简单的 只要绑定右键菜单就可以了^_^ 因为手机手写笔不分左右键，所以点击代表左键单击，长按代表右键单击]]></description>
			<content:encoded><![CDATA[<p>如何响应手写笔长按动作消息，一开始走了弯路，想到用API拦截，其实很简单的</p>
<p>只要绑定右键菜单就可以了^_^</p>
<p>因为手机手写笔不分左右键，所以点击代表左键单击，长按代表右键单击</p>
]]></content:encoded>
			<wfw:commentRss>http://ai-2.cn/2009/09/wm_lbuttondown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>定时自动刷新页面工具</title>
		<link>http://ai-2.cn/2009/06/autorefreshurl/</link>
		<comments>http://ai-2.cn/2009/06/autorefreshurl/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 02:14:52 +0000</pubDate>
		<dc:creator>csecong</dc:creator>
				<category><![CDATA[vb.net]]></category>
		<category><![CDATA[站长工具]]></category>
		<category><![CDATA[自动刷新]]></category>

		<guid isPermaLink="false">http://ai-2.cn/?p=114</guid>
		<description><![CDATA[昨天碰到个网站，要靠在线时间兑换点数才能下载这个网站的资料，所以做了个自动刷新页面的小工具，每隔几分钟刷新一下页面来防止自动退出登陆，功能相当简单。]]></description>
			<content:encoded><![CDATA[<p>昨天碰到个网站，要靠在线时间兑换点数才能下载这个网站的资料，所以做了个自动刷新页面的小工具，每隔几分钟刷新一下页面来防止自动退出登陆，功能相当简单。</p>
<div id="attachment_118" class="wp-caption alignnone" style="width: 620px"><img class="size-full wp-image-118" title="自动刷新页面工具" src="http://ai-2.cn/wp-content/uploads/2009/06/autoRefresh.gif" alt="自动刷新页面工具" width="610" height="317" /><p class="wp-caption-text">自动刷新页面工具</p></div>
<p><a title="定时刷新页面工具" href="http://www.ai-2.cn/tools/AutoRefresh.exe" target="_blank">点击这里下载AutoRefresh.exe</a></p>
<pre lang="vb.net">Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "开始" Then
Timer1.Interval = TextBox1.Text * 60 * 1000
Timer1.Enabled = True
Button1.Text = "结束"
Else
Timer1.Enabled = False
Button1.Text = "开始"
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WebBrowser1.Refresh()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

WebBrowser1.Navigate(TextBox2.Text)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox2.AutoCompleteSource = AutoCompleteSource.HistoryList
WebBrowser1.Navigate("http://ai-2.cn")
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("http://ai-2.cn")
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Refresh()
End Sub
End Class</pre>
]]></content:encoded>
			<wfw:commentRss>http://ai-2.cn/2009/06/autorefreshurl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用ContentTableAdapter和DataDataSet操作数据库</title>
		<link>http://ai-2.cn/2008/09/contenttableadapter_datadataset/</link>
		<comments>http://ai-2.cn/2008/09/contenttableadapter_datadataset/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 03:20:54 +0000</pubDate>
		<dc:creator>csecong</dc:creator>
				<category><![CDATA[vb.net]]></category>
		<category><![CDATA[contenttableadapter]]></category>
		<category><![CDATA[datadataset]]></category>
		<category><![CDATA[datagridview]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[源码]]></category>
		<category><![CDATA[自动发帖]]></category>

		<guid isPermaLink="false">http://ai-2.cn/?p=63</guid>
		<description><![CDATA[vb6.0时代，我们要使用数据库，还需要先引入ado组件，然后使用 Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb，然后conn.open的方式操作数据库，现在不需要了，直接使用ContentTableAdapter和 DataDataSet就能完成了，简单、方便、快捷]]></description>
			<content:encoded><![CDATA[<p>使用工具Visual Studio 2005</p>
<p>vb6.0时代，我们要使用数据库，还需要先引入ado组件，然后使用 Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb，然后conn.open的方式操作数据库，现在不需要了，直接使用ContentTableAdapter和 DataDataSet就能完成了，简单、方便、快捷</p>
<p>首先，将数据库加入程序中，在解决方案资源管理器里项目名称上点右键，选择添加，选择现有项，然后找到你要的数据库文件，添加进入<br />
<a href="http://www.ai-2.cn/attachment/da001.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da001.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="294" /></a><br />
然后会弹出数据源配置向导，将你需要的数据表打上钩<br />
<a href="http://www.ai-2.cn/attachment/da002.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da002.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="294" /></a><br />
然后点击完成，ok，解决方法资源管理器里会自动添加上dataDataSet.xsd文件，数据源添加完成<br />
，然后双击打开dataDataSet.xsd文件<br />
<a href="http://www.ai-2.cn/attachment/da003.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da003.gif" border="0" alt="点击在新窗口中浏览此图片" /></a><br />
出现当前的数据源，分为两部分，上面是表结构，下面是数据库命令，命令里已经默认添加了一个fill,GetData()，这个命令是列出数据库中对应表中的所有数据<br />
我们可以自己添加需要的sql命令了<br />
在这里点击右键，选择添加-&gt;query，进入向导页，因为我们用的access数据库，所以只有一个，使用sql语句来加载数据<br />
<a href="http://www.ai-2.cn/attachment/da004.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da004.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="380" /></a><br />
点击下一步，ok，选择你要加入的sql语句类型吧<br />
<a href="http://www.ai-2.cn/attachment/da005.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da005.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="380" /></a><br />
我们选择insert，向数据库中添加数据，然后编辑一下sql语句，一直下一步，完成，命令行里添加了一个insertquery的命令了<br />
<a href="http://www.ai-2.cn/attachment/da006.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da006.gif" border="0" alt="点击在新窗口中浏览此图片" /></a><br />
添加数据是需要参数的，参数怎么加呢？<br />
首先在insertquery()这个上点右键，配置，看一下sql语句<br />
在需要添加参数的地方把参数添进去，比如aa,bb<br />
<a href="http://www.ai-2.cn/attachment/da007.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da007.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="380" /></a><br />
点击完成，然后在insertquery()的属性窗口，选择parameters(sql语句或存储过程的参数)，然后添加两个参数aa和bb，当然，数据类型一定要选择正确哦<br />
<a href="http://www.ai-2.cn/attachment/da008.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da008.gif" border="0" alt="点击在新窗口中浏览此图片" width="450" height="331" /></a><br />
确定，参数添加完成<br />
<a href="http://www.ai-2.cn/attachment/da009.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da009.gif" border="0" alt="点击在新窗口中浏览此图片" /></a><a href="http://www.ai-2.cn/attachment/da009.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da009.gif" border="0" alt="点击在新窗口中浏览此图片" /></a><a href="http://www.ai-2.cn/attachment/da009.gif" target="_blank"><img class="insertimage" title="点击在新窗口中浏览此图片" src="http://www.ai-2.cn/attachment/da009.gif" border="0" alt="点击在新窗口中浏览此图片" /></a></p>
<p>怎么使用呢？^_^，在需要的地方直接用me.ContentTableAdapter.insertquery(参数1,参数2)就行了^_^</p>
<p>为了更好的看到数据库的变化，你可以添加一个DataGridView来进行显示，数据源上记得绑定datadataset啊</p>
<p>PS:插入数据后，需要重新读入才能在DataGridView中显示出来</p>
]]></content:encoded>
			<wfw:commentRss>http://ai-2.cn/2008/09/contenttableadapter_datadataset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vb.net使用HttpWebResponse进行网站登陆并保持Session</title>
		<link>http://ai-2.cn/2008/09/httpwebresponse/</link>
		<comments>http://ai-2.cn/2008/09/httpwebresponse/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 03:15:37 +0000</pubDate>
		<dc:creator>csecong</dc:creator>
				<category><![CDATA[vb.net]]></category>
		<category><![CDATA[httpwebresponse]]></category>
		<category><![CDATA[自动发帖]]></category>
		<category><![CDATA[自动登陆]]></category>

		<guid isPermaLink="false">http://ai-2.cn/?p=60</guid>
		<description><![CDATA[打算做一个论坛自动发帖的软件，涉及到登陆及在登陆状态下发布文章的问题
1、登陆
登陆我们可以直接用WebRequest.Create(url)的方法,POST数据即可……]]></description>
			<content:encoded><![CDATA[<p>打算做一个论坛自动发帖的软件，涉及到登陆及在登陆状态下发布文章的问题<br />
1、登陆<br />
登陆我们可以直接用WebRequest.Create(url)的方法,POST数据即可，这里需要注意的就是post的数据必须编码一下，文本是不能直接post的<br />
2、取得cookie<br />
如果你想把cookie显示出来，需要使用GetResponseHeader(&#8220;Set-Cookie&#8221;)将cookie以文本字段显示<br />
如果你要发布文章时也提交cookie，直接提交GetResponseHeader(&#8220;Set-Cookie&#8221;)是不行的，因为他是string的文本字段，而HttpWebResponse的CookieContainer确实cookie数组<br />
这时你需要首先定义一个空白的CookieContainer，登陆时就会得到cookie，提交文章直接使用这个值即可</p>
<p>源码部分如下：</p>
<p>以下为网上找到的测试源码，不是vb.net的，不过说明了原理</p>
<div class="code">CookieContainer cc = new CookieContainer();<br />
for(int i=0;i&lt;100;i++)<br />
{<br />
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(&#8220;http://localhost/AspxApp/MainForm.aspx&#8221;);<br />
myReq.CookieContainer = cc;<br />
HttpWebResponse resp = myReq.GetResponse() as HttpWebResponse;<br />
Stream s = resp.GetResponseStream();<br />
StreamReader sr = new StreamReader(s);    String text = sr.ReadToEnd();<br />
sr.Close();<br />
s.Close();<br />
}</div>
<p>我写的代码很乱，而且只是为了测试，所以看起来很繁琐，效率很差，大家将就看一下吧</p>
<div class="code">Imports System.net<br />
Imports System.IO<br />
Imports System.Text.RegularExpressions<br />
Imports System.Text<br />
Public Class Form1<br />
Private requestScrape As HttpWebRequest<br />
Private responseScrape As HttpWebResponse<br />
Private cc As New CookieContainer<br />
Function GetHttpStream(ByVal url As String, ByVal uname As String, ByVal upass As String) As Stream<br />
&#8216; 使用 WebRequestFactory 创建请求。<br />
Dim encoding = New ASCIIEncoding<br />
Dim aa As String, ab As Byte()<br />
aa = &#8220;username=&#8221; &amp; uname &amp; &#8220;&amp;password=&#8221; &amp; upass &amp; &#8220;&amp;loginsubmit=true&#8221;<br />
ab = encoding.GetBytes(aa)<br />
&#8216;TextBox3.Text = aa<br />
requestScrape = CType(WebRequest.Create(url), HttpWebRequest)<br />
With requestScrape<br />
.UserAgent = &#8220;Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)&#8221;<br />
.Method = &#8220;POST&#8221;<br />
.ContentType = &#8220;application/x-www-form-urlencoded&#8221;<br />
.ContentLength = ab.Length<br />
.Timeout = 10000<br />
.CookieContainer = cc</p>
<p>End With<br />
Dim newStream As Stream = requestScrape.GetRequestStream()<br />
newStream.Write(ab, 0, ab.Length)<br />
newStream.Close()<br />
Try<br />
&#8216; 返回响应流。<br />
responseScrape = CType(requestScrape.GetResponse(), HttpWebResponse)<br />
Return responseScrape.GetResponseStream()<br />
Catch exp As Exception<br />
&#8216; 因为错误最有可能是由键入错误的 Url 或者<br />
&#8216; 没有 Internet 连接造成的，所以创建一条转发回调用函数的<br />
&#8216; 自定义错误信息。<br />
Throw New Exception(exp.Message.ToString)<br />
End Try<br />
End Function<br />
&#8216; 此函数读取由 httpWebResponse 对象返回的流，并<br />
&#8216; 将其转换为字符串供 RegEx 处理。<br />
Function ConvertStreamToString(ByVal stmSource As Stream, ByVal codeb As Integer) As String<br />
Dim sr As StreamReader = Nothing</p>
<p>If Not IsNothing(stmSource) Then<br />
Try<br />
sr = New StreamReader(stmSource, System.Text.Encoding.GetEncoding(codeb))<br />
&#8216; 使用设定的编码格式读取并返回流的全部内容。<br />
Return sr.ReadToEnd<br />
Catch exp As Exception<br />
&#8216; 不显示 MsgBox。只是转发<br />
&#8216;来自 GetHttpStream() 的错误信息。<br />
Throw New Exception()<br />
Finally<br />
&#8216; 清理 Stream 和 StreamReader。<br />
responseScrape.Close()<br />
sr.Close()<br />
End Try<br />
End If<br />
Return Nothing<br />
End Function</p>
<p>Function GetHttpStream2(ByVal url As String) As Stream<br />
&#8216; 使用 WebRequestFactory 创建请求。<br />
requestScrape = CType(WebRequest.Create(url), HttpWebRequest)<br />
With requestScrape<br />
.UserAgent = &#8220;Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)&#8221;<br />
.Method = &#8220;GET&#8221;<br />
.CookieContainer = cc<br />
.Timeout = 10000<br />
End With</p>
<p>Try<br />
&#8216; 返回响应流。<br />
responseScrape = CType(requestScrape.GetResponse(), HttpWebResponse)<br />
Return responseScrape.GetResponseStream()<br />
Catch exp As Exception<br />
&#8216; 因为错误最有可能是由键入错误的 Url 或者<br />
&#8216; 没有 Internet 连接造成的，所以创建一条转发回调用函数的<br />
&#8216; 自定义错误信息。<br />
Throw New Exception(exp.Message.ToString)<br />
End Try<br />
End Function<br />
&#8216; 此函数读取由 httpWebResponse 对象返回的流，并<br />
&#8216; 将其转换为字符串供 RegEx 处理。<br />
Function ConvertStreamToString2(ByVal stmSource As Stream, ByVal codeb As Integer) As String<br />
Dim sr As StreamReader = Nothing</p>
<p>If Not IsNothing(stmSource) Then<br />
Try<br />
sr = New StreamReader(stmSource, System.Text.Encoding.GetEncoding(codeb))<br />
&#8216; 使用设定的编码格式读取并返回流的全部内容。<br />
Return sr.ReadToEnd<br />
Catch exp As Exception<br />
&#8216; 不显示 MsgBox。只是转发<br />
&#8216;来自 GetHttpStream() 的错误信息。<br />
Throw New Exception()<br />
Finally<br />
&#8216; 清理 Stream 和 StreamReader。<br />
responseScrape.Close()<br />
sr.Close()<br />
End Try<br />
End If<br />
Return Nothing<br />
End Function</p>
<p>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim ystrm As Stream = GetHttpStream(&#8220;http://127.0.0.1/login.asp&#8221;, TextBox1.Text, TextBox2.Text)  &#8217;获取网址<br />
Dim respHTML As String = ConvertStreamToString(ystrm, 65001)<br />
RichTextBox1.Text = respHTML.ToString<br />
TextBox3.Text = responseScrape.GetResponseHeader(&#8220;Set-Cookie&#8221;).ToString</p>
<p>Dim ystrm2 As Stream = GetHttpStream2(&#8220;http://127.0.0.1/post.asp&#8221;)  &#8217;获取网址<br />
Dim respHTML2 As String = ConvertStreamToString2(ystrm2, 65001)<br />
RichTextBox1.Text = respHTML2.ToString<br />
End Sub<br />
End Class</p></div>
<p>通过比较RichTextBox1.Text的内容判断是否正常发送cookie<br />
65001是UTF8编码，一般用0即可</p>
]]></content:encoded>
			<wfw:commentRss>http://ai-2.cn/2008/09/httpwebresponse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
