<?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>BncApps &#187; Visual Basics .NET</title>
	<atom:link href="http://bncapps.com/category/vbnetsnippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://bncapps.com</link>
	<description>Open Source Applications and General Technology Blog</description>
	<lastBuildDate>Sat, 11 Dec 2010 23:48:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>DotMSN &#8211; Messaging Library</title>
		<link>http://bncapps.com/dotmsn-messaging-library/</link>
		<comments>http://bncapps.com/dotmsn-messaging-library/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 23:00:13 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[making a msn client]]></category>
		<category><![CDATA[msn in c#.net]]></category>
		<category><![CDATA[msn in vb]]></category>
		<category><![CDATA[msn protocol]]></category>
		<category><![CDATA[sending msn in c#]]></category>
		<category><![CDATA[sending msn messages in vb.net]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=301</guid>
		<description><![CDATA[DotMSN is a messaging library to work with the MSN protocol in your .NET applications. It is made and managed by Xihsolutions and it is also open source. I will take a look at this and try to put together some cool things that can be done with it. In the meantime, check it out [...]]]></description>
			<content:encoded><![CDATA[<p>DotMSN is a messaging library to work with the MSN protocol in your .NET applications. It is made and managed by Xihsolutions and it is also open source.</p>
<p>I will take a look at this and try to put together some cool things that can be done with it.</p>
<p>In the meantime, check it out for yourself: <a href="http://www.xihsolutions.net/dotmsn/">http://www.xihsolutions.net/dotmsn/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/dotmsn-messaging-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET + Java &#8211; Collision Detection</title>
		<link>http://bncapps.com/vbnet-java-collision-detection/</link>
		<comments>http://bncapps.com/vbnet-java-collision-detection/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 19:23:38 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[check if objects are touching]]></category>
		<category><![CDATA[collision detection]]></category>
		<category><![CDATA[java collisions]]></category>
		<category><![CDATA[vb.net collisions]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=260</guid>
		<description><![CDATA[I got a email asking how to do collision detection in Java. While i'm at it, I might as well review collision detection in VB.NET, that was used for the gravity example (http://bncapps.com/?p=91) Visual Basics .NET &#160; If Object1.IntersectsWith&#40;Object2&#41; Then 'do whatever End If &#160; Object1 and Object2 can be anything from labels or shapes. [...]]]></description>
			<content:encoded><![CDATA[<p>I got a email asking how to do collision detection in Java. While i'm at it, I might as well review collision detection in VB.NET, that was used for the gravity example (<a href="http://bncapps.com/?p=91">http://bncapps.com/?p=91</a>)</p>
<p><strong>Visual Basics .NET</strong></p>
<pre class="vbnet">&nbsp;
<span style="color: #0600FF;">If</span> Object1.<span style="color: #0000FF;">IntersectsWith</span><span style="color: #000000;">&#40;</span>Object2<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
<span style="color: #008080; font-style: italic;">'do whatever</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;</pre>
<p>Object1 and Object2 can be anything from labels or shapes. This code can be placed in a timer to continuously check if there's a intersection occurring and act accordingly.</p>
<p><strong>Java</strong><br />
In Java, the code is almost the exact same.</p>
<pre class="java">&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>Object1.<span style="color: #006600;">intersects</span><span style="color: #66cc66;">&#40;</span>Object2.<span style="color: #006600;">getBounds</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">//do stuff</span>
 <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>The use is the same and only executes the if statement if they are touching.</p>
<p>And that's it, hope it helps.</p>
<p>If you have any more suggestions, don't hesitate to <a href="http://bncapps.com/?page_id=176">contact me</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-java-collision-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET &#8211; Lights On Level Loader</title>
		<link>http://bncapps.com/vbnet-lights-on-level-loader/</link>
		<comments>http://bncapps.com/vbnet-lights-on-level-loader/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 16:52:29 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[.txt in vb]]></category>
		<category><![CDATA[.txt in visual basics]]></category>
		<category><![CDATA[level loader]]></category>
		<category><![CDATA[load text files]]></category>
		<category><![CDATA[load text files in vb.net]]></category>
		<category><![CDATA[load txt files in vb.net]]></category>
		<category><![CDATA[txt]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=245</guid>
		<description><![CDATA[I got a email requesting that I go over the code that I wrote to load levels into the Lights On puzzel game clone I made (found here) So I will go over line by line what each thing does in the full article. Here is the full loadLevel function from the LightsOn clone posted [...]]]></description>
			<content:encoded><![CDATA[<p>I got a email requesting that I go over the code that I wrote to load levels into the Lights On puzzel game clone I made (<a href="http://bncapps.com/?p=239">found here</a>)</p>
<p>So I will go over line by line what each thing does in the full article.<br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-5038888073735758";
google_ad_slot = "6099537090";
google_ad_width = 468;
google_ad_height = 15;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center><br />
<span id="more-245"></span></p>
<p>Here is the full loadLevel function from the LightsOn clone posted yesterday:</p>
<pre class="vbnet">&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> loadLevel<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> level <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> oFile <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">IO</span>.<a href="http://www.google.com/search?q=FILE+msdn.microsoft.com"><span style="color: #008000;">File</span></a>
        <span style="color: #0600FF;">Dim</span> oRead <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0000FF;">StreamReader</span>
        <span style="color: #0600FF;">Dim</span> LineIn <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
        <span style="color: #0600FF;">Dim</span> currentcolumn <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span>
        <span style="color: #0600FF;">If</span> System.<span style="color: #0000FF;">IO</span>.<a href="http://www.google.com/search?q=FILE+msdn.microsoft.com"><span style="color: #008000;">File</span></a>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CurDir</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> &amp; <span style="color: #808080;">&quot;\levels\&quot;</span> &amp; level.<span style="color: #0000FF;">ToString</span> &amp; <span style="color: #808080;">&quot;.txt&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            oRead = oFile.<span style="color: #0000FF;">OpenText</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CurDir</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> &amp; <span style="color: #808080;">&quot;\levels\&quot;</span> &amp; level.<span style="color: #0000FF;">ToString</span> &amp; <span style="color: #808080;">&quot;.txt&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">While</span> oRead.<span style="color: #0000FF;">Peek</span> &lt;&gt; <span style="color: #FF0000;">-1</span>
                LineIn = oRead.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #FF8000;">For</span> i <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> = <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> <span style="color: #000000;">&#40;</span>LineIn.<span style="color: #0000FF;">Length</span> - <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Step</span> <span style="color: #FF0000;">1</span>
                    <span style="color: #0600FF;">If</span> LineIn.<span style="color: #0000FF;">ElementAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> = <span style="color: #808080;">&quot;|&quot;</span> <span style="color: #FF8000;">Then</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Text</span> = <span style="color: #808080;">&quot;|&quot;</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ForeColor</span> = Color.<span style="color: #0600FF;">Blue</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">BackColor</span> = Color.<span style="color: #0600FF;">Blue</span>
                    <span style="color: #FF8000;">Else</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Text</span> = <span style="color: #808080;">&quot;-&quot;</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ForeColor</span> = Color.<span style="color: #0600FF;">Red</span>
                        buttons<span style="color: #000000;">&#40;</span>i, currentcolumn<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">BackColor</span> = Color.<span style="color: #0600FF;">Red</span>
                    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
                <span style="color: #FF8000;">Next</span>
                currentcolumn = currentcolumn + <span style="color: #FF0000;">1</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">While</span>
            oRead.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Level &quot;</span> &amp; level.<span style="color: #0000FF;">ToString</span> &amp; <span style="color: #808080;">&quot; does not exist!&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;</pre>
<p>The function takes the integer value of the level to load. This is used in finding the level .txt file (level & ".txt")</p>
<p>The first two variables declared are for the streamreader, this allows the loading of files. There is also another variable that can be declared for the writing of txt files, can be used to make a level editor. But that wont be looked at. </p>
<p>LineIn is the string that holds the current line that has been read for later processing. The integer currentcolumn holds the current column the txt file loading is on (can be a max of 7).</p>
<p>Right away it checks to make sure the file located in the current directory\levels\levelnumber.txt exists. This is to prevent errors from trying to load a text file that dosn't exist.</p>
<p>The entire text file is loaded into the StreamReader that was previously declared as oRead. A while loop is started that loops while there is still more columns left. Right after the loop is started, the string LineIn is set to the entire string found at that current line in the text file. </p>
<p>Now its for the fun part, the part that generates the level based on what it loads.</p>
<p>A For loop is started from 0 to the size of the line minus 1. Remember, everything in programming starts at 0, not a 1. If we were to start the for loop at a 1, the first button in each column would be ignored!</p>
<p>A if statement is used to check the ElementAt the i index. ElementAt returns the value at the index.</p>
<p>For example, if there is a string that says:<br />
Dim mystring as string<br />
mystring = "BncApps"</p>
<p>And this was done:<br />
MessageBox.Show(mystring.ElementAt(2))</p>
<p>A message box would appear saying "c"</p>
<p>So if the element at the current loop index is a |, then it sets the tiles to blue, meaning they are on. Notice how currentcolumn isn't incremented at all within the for loop. If the element at that position is not a |, then it assumes its a dash (-) and sets them to red, or off.</p>
<p>After the for loop exits, currentcolumn is incremented by one.</p>
<p>Once the while loop finishes, it closes the StreamReader. A else statement is set for the first if statement that was in place (the one that made sure the file existed) to give a message box if the level does not exist.</p>
<p>Well that's everything, hope it helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-lights-on-level-loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET &#8211; Lights On</title>
		<link>http://bncapps.com/vbnet-lights-on/</link>
		<comments>http://bncapps.com/vbnet-lights-on/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 16:33:14 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[lights on]]></category>
		<category><![CDATA[puzzel]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=239</guid>
		<description><![CDATA[Edit: Here is a demo video! This is a clone of the popular puzzle game Lights on. The purpose of the game is to turn all the lights on, or in this case; make all the buttons blue. Sounds easy, but once clicked the button clicked, the one above, below, to the left and right [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bncapps.com/wp-content/uploads/2008/12/lightson.png" alt="lightson" title="lightson" width="216" height="258" class="aligncenter size-full wp-image-240" /><br />
Edit: Here is a demo video!<br />
<center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/KF7GvIdbMSo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/KF7GvIdbMSo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></center><br />
This is a clone of the popular puzzle game Lights on. The purpose of the game is to turn all the lights on, or in this case; make all the buttons blue. Sounds easy, but once clicked the button clicked, the one above, below, to the left and right are inverted. That means if any of the ones around are already blue, they will become red. Its a fun challenging puzzle game.<br />
More info in the full article!<br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-5038888073735758";
google_ad_slot = "0739265609";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center><br />
<span id="more-239"></span><br />
This version allows you to make your own levels in .txt files and have them automatically loaded. It demonstrates creating 2D array button objects, instead of drawing 49 buttons manually, and controlling them all. </p>
<p>This is how a level file would look:<br />
<code><br />
|||||||<br />
||-||||<br />
|--||||<br />
|||--||<br />
|||-|||<br />
|||||||<br />
|||||||<br />
</code><br />
Where | are the blue ones and the dashes (-) are the ones that must be turned into blue. Levels can be created anyway, aslong as they are 7x7. There is 7 levels included, all I have been able to finish except level 7 (can any of you try to beat it?)</p>
<p>If you create any levels and would like to share them, please use the contact me form and they will be posted!</p>
<p>As always, its Open Source.<br />
Download the binary and source here: <a class="downloadlink" href="http://bncapps.com/wp-content/plugins/download-monitor/download.php?id=14" title="Version 1.0 downloaded 741 times" >LightsOn (741) - 192.62 kB</a><br />
Or<br />
<a href="http://www.ziddu.com/download/2982355/LightsOn.rar.html">Download from Ziddu and support BncApps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-lights-on/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VB.NET Mouse Macro</title>
		<link>http://bncapps.com/vbnet-mouse-macro/</link>
		<comments>http://bncapps.com/vbnet-mouse-macro/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 23:55:25 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[mouse macro]]></category>
		<category><![CDATA[movement]]></category>
		<category><![CDATA[scirpt]]></category>
		<category><![CDATA[subscript]]></category>
		<category><![CDATA[vb]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=217</guid>
		<description><![CDATA[This is a simple application that demonstrates how you can allow your application users a basic scripting language. This is a programmable mouse macro where you add commands such as "setx 120" to the listbox and each line is executed one by one. This can be used for easy mouse movements and clicks. It demonstrates [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple application that demonstrates how you can allow your application users a basic scripting language. This is a programmable mouse macro where you add commands such as "setx 120" to the listbox and each line is executed one by one. This can be used for easy mouse movements and clicks. It demonstrates substring to show splitting strings to find the part of the command we want. </p>
<p>This can be futher extended with more commands such as a way to jump to a certain part of the code. This is not in the project, but if requested a new version will be released.</p>
<p>Download the binary and source: <a class="downloadlink" href="http://bncapps.com/wp-content/plugins/download-monitor/download.php?id=12" title="Version1.0 downloaded 698 times" >MouseMacro (698)</a><br />
<a href="http://www.ziddu.com/download/2953605/MouseMacro.rar.html ">Download from Ziddu.com and support BncApps!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-mouse-macro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET &#8211; Slot Machine</title>
		<link>http://bncapps.com/vbnet-slot-machine/</link>
		<comments>http://bncapps.com/vbnet-slot-machine/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 21:56:26 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[slot machine]]></category>
		<category><![CDATA[slots]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual basics]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=191</guid>
		<description><![CDATA[Edit: Now a demo video! This is one of the first VB.NET projects I actually did back in 2006. It's a slot machine that had to incorporate alot of different things as part of the assignment, such as use of the string classes (toUpperCase, .length, etc) The features: -When you click the handle to pull [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bncapps.com/wp-content/uploads/2008/12/screenshot.jpg"><img src="http://bncapps.com/wp-content/uploads/2008/12/screenshot.jpg" alt="" title="screenshot" width="300" height="296" class="aligncenter size-medium wp-image-192" /></a><br />
Edit: Now a demo video!<br />
<center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/pTh2i_BwYs0&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pTh2i_BwYs0&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></center><br />
This is one of the first VB.NET projects I actually did back in 2006. It's a slot machine that had to incorporate alot of different things as part of the assignment, such as use of the string classes (toUpperCase, .length, etc)<br />
<span id="more-191"></span><br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-5038888073735758";
google_ad_slot = "0739265609";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center><br />
The features:<br />
-When you click the handle to pull down the slot machine, it slides down and up. You wont be able to click it again until it has finished rolling<br />
-You can not roll unless you add a coin by clicking one first<br />
-When a coin is added, it slides up to the machine and goes into the coin slot, once it hits it, the coin is no longer visible and your credits increases.<br />
-"Blur" effect, simulating long hours playing slots and falling asleep<br />
-Mini slot machine made as a proof of concept to a way to make the rolling more realistic<br />
-Payouts based on different outcomes, some outcomes have a higher chance than others</p>
<p>Since this is a big project, only registered users will be able to download it. It will not take you any longer than 2 minutes to be registered. When registered you will also be able to post comments!</p>
<p>Download Binary and Source (Registered members only): <a class="downloadlink" href="http://bncapps.com/wp-content/plugins/download-monitor/download.php?id=8" title="Version 1.0 downloaded 654 times" >Slot Machine (654) - </a><br />
<a href="http://www.ziddu.com/download/2927929/vbnet-SlotMachine.rar.html ">Don't want to register? Click here to download the Binary and Source from Ziddu and support BncApps at the same time!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-slot-machine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>VB.NET &#8211; Mouse Events</title>
		<link>http://bncapps.com/vbnet-mouse-events/</link>
		<comments>http://bncapps.com/vbnet-mouse-events/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 01:38:48 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[mouse clicks]]></category>
		<category><![CDATA[mouse down]]></category>
		<category><![CDATA[mouse events]]></category>
		<category><![CDATA[mouse up]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual basics]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=147</guid>
		<description><![CDATA[I figured a little tutorial on mouse events in VB will be helpful! There are two methods, mouse down and mouse up. Mouse down handles clicking on the form, and basically doing things while the mouse button is being held down. Mouse up does the opposite, handles doing things when the mouse is not being [...]]]></description>
			<content:encoded><![CDATA[<p>I figured a little tutorial on mouse events in VB will be helpful!</p>
<p>There are two methods, mouse down and mouse up. Mouse down handles clicking on the form, and basically doing things while the mouse button is being held down. Mouse up does the opposite, handles doing things when the mouse is not being clicked, or detecting where it was unclicked.<br />
<span id="more-147"></span><br />
Here is the mouse down event:<br />
<code><br />
    Private Sub Form1_Mousedown(ByVal sender As System.Object, ByVal e As  _<br />
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown<br />
If e.Button = MouseButtons.Left Then<br />
'do stuff<br />
End If<br />
    End Sub<br />
</code><br />
With this you can do various things. Instead of MouseButtons.Left you can also use MouseButtons.Right and MouseButtons.Middle. Also, you can determine where the mouse was clicked by using e.X and e.Y.</p>
<p>For example, add this line of code into your mouseDown method and click on the form:<br />
<code><br />
If e.Button = MouseButtons.Left Then<br />
MessageBox.Show("Left mouse button clicked at: " & e.X & ", " & e.Y)<br />
Else If e.Button = Mousebuttons.Middle Then<br />
MessageBox.Show("Middle mouse button clicked at: " & e.X & ", " & e.Y)<br />
Else If e.Button = Mousebuttons.Right Then<br />
MessageBox.Show("Right mouse button clicked at: " & e.X & ", " & e.Y)<br />
End If<br />
</code></p>
<p>Easy enough? MouseUp is the exact same thing...<br />
<code><br />
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp<br />
If e.Button = MouseButtons.Left Then</p>
<p>End If<br />
End Sub<br />
</code></p>
<p>This allows you to do all the same functions. </p>
<p>What can it be used for? Well when the mouse is clicked, you can set a boolean to true, and when its released you can set it back to false. Then you can have a Timer to check when the mouse is being held down and do something. In the project file from my previous post, <a href="http://bncapps.com/?p=91">VB.NET - Handling shape movements and collision</a>, it is used for growth of the shapes. When the "helddown" boolean is true, the size of the current rectangle is continuously increased by 1 until the mouse is released.</p>
<p>Thats all for that!</p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-mouse-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET &#8211; Handling shape movements and collision</title>
		<link>http://bncapps.com/vbnet-handling-shape-movements-and-collision/</link>
		<comments>http://bncapps.com/vbnet-handling-shape-movements-and-collision/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 20:27:06 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Visual Basics .NET]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[collision]]></category>
		<category><![CDATA[movement]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[rectangle]]></category>
		<category><![CDATA[squares]]></category>
		<category><![CDATA[timers]]></category>
		<category><![CDATA[visual basics]]></category>

		<guid isPermaLink="false">http://bncapps.com/?p=91</guid>
		<description><![CDATA[Edit: Now a video is up of the attached demo: In the previous post(Found here) I talked about creating shape objects at random positions and drawing them on the form. This tutorial will go over making them all move, and handling collisions. I made a Visual Basics project as a way to test "gravity." You [...]]]></description>
			<content:encoded><![CDATA[<p>Edit: Now a video is up of the attached demo:<br />
<center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/RcD_VPZZpjU&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RcD_VPZZpjU&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></center></p>
<p>In the previous post(<a href="http://bncapps.com/?p=67">Found here</a>) I talked about creating shape objects at random positions and drawing them on the form. This tutorial will go over making them all move, and handling collisions. I made a Visual Basics project as a way to test "gravity." You click around the form and it will create a square at that position, they instantly bein to fall. Once they hit the ground (the bottom of the form) they stop moving, if they hit others that are <strong>touching the ground</strong> (double clicking in the air will not work) they will stack up and stop moving.</p>
<p>The project binary and full source code will be available at the end of this post.<br />
<strong>Note: This was made in Visual Studio 2008, if you try on previous versions you may have problems! You can download Visual Studio 2008 for FREE on Microsoft's website!</strong><br />
<center><script type="text/javascript"><!--
google_ad_client = "pub-5038888073735758";
google_ad_slot = "0739265609";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center><br />
<span id="more-91"></span><br />
Note: The project that will be available for download has basic "winds" to cause the objects to be blown against the wall. Adding that will not be discussed here but it is in the project file. Also, the project file has a "growth" feature, where the longer you hold the mouse down, the bigger the shape gets.<br />
Here are the new variables that must be declared, assuming you already have myGraphics and everything else from the previous post<br />
<code><br />
Dim rectangleLock(500) As Boolean<br />
Dim intersectLock(500) As Boolean<br />
Dim connectsToGround(500) As Boolean<br />
Dim drawnRectangles As Integer<br />
Dim squareLocked(500) As Boolean<br />
</code></p>
<p>Notice how most of these are arrays of 500, just like the Rectangle array. Each rectangle will have its own slot in each of these arrays.</p>
<p>Add this to your form_load, this reduces the flicker when the form refreshes:<br />
<code><br />
Me.DoubleBuffered = True<br />
</code><br />
And add this to your form_load:<br />
<code><br />
drawnRectangles = 1<br />
unlockAll()<br />
intersectUnlock()<br />
connectsUnlock()<br />
unlockSquares()<br />
</code><br />
This is basically to call methods that will set all the boolean variables to false, useful for instantiating them and each time we decide to clear the form. </p>
<p>Here is the full code for the methods:<br />
<code><br />
Sub unlockAll()<br />
For i As Integer = 1 To 500 Step 1<br />
rectangleLock(i) = False<br />
Next<br />
End Sub</p>
<p>Sub intersectUnlock()<br />
For i As Integer = 1 To 500 Step 1<br />
intersectLock(i) = False<br />
Next<br />
End Sub</p>
<p>Sub connectsUnlock()<br />
For i As Integer = 1 To 500 Step 1<br />
Next<br />
End Sub</p>
<p>Sub unlockSquares()<br />
For i As Integer = 1 To 500 Step 1<br />
squareLocked(i) = False<br />
Next<br />
End Sub<br />
</code></p>
<p>The next thing to add is the mousedown event:<br />
<code><br />
Private Sub Form1_Mousedown(ByVal sender As System.Object, ByVal e As  _<br />
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown<br />
If e.Button = MouseButtons.Left Then<br />
drawRectangle(drawnRectangles, e.X, e.Y)<br />
drawnRectangles = drawnRectangles + 1<br />
If drawnRectangles = 500 Then<br />
drawnRectangles = 1<br />
unlockAll()<br />
intersectUnlock()<br />
connectsUnlock()<br />
End If<br />
End If<br />
End Sub<br />
</code><br />
What this basically does is get the x and y position of where the mouse was clicked, pass the integer value drawnRectangles, x, and y to drawRectangle. Within drawRectangle it adds it to the array (as mentioned in the previous post) It then increases drawnRectagngles by 1, and if drawnRectangles is 500 (the size of the array) it will reset it down to 1 and clear the form of all squares by calling all the unlock functions.</p>
<p>Add a timer, call it tmrRefresh, set its interval to 1 and enable it right away. All the code this timer needs is:<br />
<code><br />
Me.Refresh()<br />
</code><br />
This will refresh the form and clear all the other shapes for them to be redrawn. After we add the movement section, try disabling this timer and see what happens!</p>
<p>Next is the timer that will force all the shapes downwards, name it tmrMove, in the project file its called Timer1. Give it a interval of 2</p>
<p><code><br />
For i As Integer = 1 To (drawnRectangles - 1) Step 1<br />
If (myRectangle(i).Top < Me.Height - 50) And rectangleLock(i) = False Then<br />
If intersectLock(i) = False Then '<br />
If (myRectangle(i).Left > 0) Then<br />
myRectangle(i).Location = New Point(myRectangle(i).X, myRectangle(i).Y + 1)<br />
Else<br />
myRectangle(i).Location = New Point(myRectangle(i).X, myRectangle(i).Y + 1)<br />
End If ' end if for the width check<br />
End If<br />
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle(i))<br />
myGraphics.FillRectangle(brush:=myBrush, rect:=myRectangle(i))<br />
Else<br />
If intersectLock(i) = False Then<br />
myRectangle(i).Location = New Point(myRectangle(i).X, Me.Height - 50)<br />
End If<br />
rectangleLock(i) = True<br />
connectsToGround(i) = True 'This one has hit the ground<br />
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle(i))<br />
myGraphics.FillRectangle(brush:=myBrush, rect:=myRectangle(i))<br />
End If<br />
Next<br />
</code><br />
Steps in the code:<br />
1.The code starts with a loop from 1 to the number of rectangles drawn on the form (remember the variable was increased when we clicked?)</p>
<p>2. Within that it checks if the Top value (basically the y value) is less than the forms height, and rectangleLock at the array spot i, meaning the loop index is false. </p>
<p>3. Right after it checks if the boolean intersectLock is also false<br />
Then it checks to makesure the left (or x value) is greater than 0. This part is mainly used for the "wind" code thats in the project file, to make sure the square is not moved off the form.</p>
<p>4. If all these if statements passed, then it runs the code of setting the rectangles location to a new point, of the rectangles y value, plus 1. This will make it slide down each timer tick.</p>
<p>5. If the rectangle's x value is less than 0, it will only pull it downwards. This is for the "wind" part, which is why it may not sound right. In the project file you will see it makes more sense.</p>
<p>6. The rectangle is then redrawn and refilled</p>
<p>7. The else statement is called for the first if statement (the one that checks if its y value is greater than the forms height). Within this, it checks to see if intersectLock is false, the purpose of this variable is described later. If the Y position of the square did go outside of the form, it resets it to the forms height, subtracted from 50. It then sets intersectLock to true, to prevent it from moving anymore. It will then lock it in and since it touched the ground, it sets that one to true. This is used later for the collision stacking.</p>
<p>8. The rectangles are drawn again and the final end if appears</p>
<p>9. The loop restarts, for the next rectangle.</p>
<p>So movement is out of the way, now for collision and stacking.</p>
<p>Add a new timer, this one will be to handle collisions. Call it tmrCollisions (in the project file its Timer2) and give it a interval of 1, enable it right away.</p>
<p>The code for this timer is much shorter, but more complex:<br />
<code><br />
For i As Integer = 1 To (drawnRectangles - 1) Step 1<br />
For x As Integer = 1 To (drawnRectangles - 1) Step 1<br />
If i <> x Then<br />
If connectsToGround(x) = True Then<br />
If myRectangle(i).IntersectsWith(myRectangle(x)) Then<br />
intersectLock(i) = True<br />
connectsToGround(i) = True 'its connected to one thats touching the ground<br />
End If<br />
End If 'end if for   if rectangleLock<br />
End If<br />
Next 'x<br />
Next 'i<br />
</code><br />
The code starts by starting a for loop to the size of the drawn rectangles, then another to the size of the rectangles. A nested for loop within the main for loop. Right away it checks to makesure I is not the same as X, to prevent it from checking a collision with itself (which will always be true). Then it checks if x is connected to the ground, if it is then that means its touching the floor. It then calls the .intersectsWith to check if i intersects with X. If it does, then it intersect locks it, and sets i being connected to the ground, as its connected to one that links to the ground. And thats it for that!</p>
<p>The 2 loops cause something like this:<br />
i and x, i and x+1, i and x+2</p>
<p>x will always be incrementing, once x has finished its loop, i gets incremented, then the x loop starts again, comparing each with each other to check for intersections.</p>
<p>And thats it! You can get the source download below. No screenshot this time as the form is really big to allow the objects space to fall and stack.</p>
<p>Like always, the source is licensed under the GPL license. If you use it with the intent to re distribute it, the source must be released too, as well as a link back to BncApps. </p>
<p>Download: <a class="downloadlink" href="http://bncapps.com/wp-content/plugins/download-monitor/download.php?id=3" title="Version 1.0 downloaded 871 times" >GravityExample (871) - 136.19 kB</a></p>
<p>Helpful?  <a href="http://bncapps.com/?page_id=106">why not buy me a coffee for my next project?</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://bncapps.com/vbnet-handling-shape-movements-and-collision/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
