<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D04GR3o6fSp7ImA9WhRaFE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321</id><updated>2012-02-16T15:45:26.415-08:00</updated><category term="install" /><category term="swipe" /><category term="block" /><category term="arguments" /><category term="documentation" /><category term="unit" /><category term="vs2008" /><category term="conditions" /><category term="getter" /><category term="method" /><category term="c#" /><category term="objective-c" /><category term="prime" /><category term="values" /><category term="audio" /><category term="akhn" /><category term="mouse" /><category term="revision-control" /><category term="copy" /><category term="resource" /><category term="video" /><category term="multi-dimensional-Array" /><category term="virtual" /><category term="performance" /><category term="default-constructor" /><category term="strings" /><category term="variables" /><category term="distribute" /><category term="hangman" /><category term="while" /><category term="exercise" /><category term="abstract" /><category term="java" /><category term="slow" /><category term="arrays" /><category term="field" /><category term="property" /><category term="graphics" /><category term="data-driven" /><category term="improvement" /><category term="?:" /><category term="game" /><category term="goto" /><category term="change-size" /><category term="protected" /><category term="///" /><category term="protected-internal" /><category term="stone" /><category term="scissor" /><category term="parameter" /><category term="mp3" /><category term="fix" /><category term="project" /><category term="testing" /><category term="cat" /><category term="basi" /><category term="advantage" /><category term="ide" /><category term="subversion" /><category term="this" /><category term="moving" /><category term="setup" /><category term="operator" /><category term="loop" /><category term="comment" /><category term="skills" /><category term="public" /><category term="auto" /><category term="list" /><category term="optional-parameter" /><category term="flickering" /><category term="media-player" /><category term="Access-modifier" /><category term="event" /><category term="collision" /><category term="switch" /><category term="winform" /><category term="interface" /><category term="arraylist" /><category term="for" /><category term="rectangle" /><category term="agile" /><category term="else" /><category term="setter" /><category term="vs2010" /><category term="compare" /><category term="overloading" /><category term="class" /><category term="ppt" /><category term="polymorphism" /><category term="dos" /><category term="cmd" /><category term="csv" /><category term="attitude" /><category term="embed" /><category term="if" /><category term="version-control" /><category term="paper" /><category term="fallthrough" /><category term="cvs" /><category term="revision" /><category term="sdlc" /><category term="do while" /><category term="guide" /><category term="drawing" /><category term="basic" /><category term="bounding" /><category term="process" /><category term="override" /><category term="main" /><category term="static" /><category term="programming" /><category term="source-control" /><category term="random" /><category term="tutorial" /><category term="deployment" /><category term="sorting" /><category term="complete" /><category term="music" /><category term="oop" /><category term="internal" /><category term="add-reference" /><category term="dog" /><category term="keypress" /><category term="bubble" /><category term="ball" /><category term="constructor" /><category term="replace" /><category term="private" /><category term="paddle" /><category term="wav" /><category term="dictionary" /><category term="decimal" /><category term="tic-tac-toe" /><category term="bitmap" /><category term="beginner" /><category term="named-parameter" /><category term="calculator" /><title>Software &amp; Programming Fundamentals</title><subtitle type="html">Games Development Tutorials using C#</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://mpgddspf.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>87</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/SoftwareProgrammingFundamentals" /><feedburner:info uri="softwareprogrammingfundamentals" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DEYCQ3w_eip7ImA9WhdRFE8.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-3327229603209533067</id><published>2011-08-01T18:07:00.001-07:00</published><updated>2011-08-03T19:49:22.242-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-03T19:49:22.242-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="csv" /><category scheme="http://www.blogger.com/atom/ns#" term="testing" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="advantage" /><category scheme="http://www.blogger.com/atom/ns#" term="unit" /><category scheme="http://www.blogger.com/atom/ns#" term="auto" /><title>Unit Testing–Manual, Automatic &amp; Choosing test cases</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ye_ZRSGO-TYZsI50nB-pWz78t8c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ye_ZRSGO-TYZsI50nB-pWz78t8c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ye_ZRSGO-TYZsI50nB-pWz78t8c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ye_ZRSGO-TYZsI50nB-pWz78t8c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We perform adhoc testing as we code.&amp;nbsp; However, to properly test our smallest unit of code, we will need to perform unit testing.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Why border with unit testing?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Proper unit testing provides the following advantages:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;font color="#ff0000"&gt;Robustness&lt;/font&gt;  &lt;li&gt;&lt;font color="#ff0000"&gt;Productivity&lt;/font&gt;  &lt;li&gt;&lt;font color="#ff0000"&gt;Repeatability&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;strong&gt;Robustness&lt;/strong&gt;: It ensure that your code works under error for abnormal inputs or values or etc.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Productivity&lt;/strong&gt;: It makes it easier to perform testing at a higher level and later stage since we have tested the lower level codes thoroughly.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Repeatability&lt;/strong&gt;: With proper documentation and creation of the test cases, we are able to repeat those tests again in the future.&amp;nbsp; For bugs found, the test case ensures that the programmer during debugging will be able to repeat the test again to re-create the problem.&lt;/p&gt; &lt;h3&gt;Automatic Creation of Unit Tests to use Data File&lt;/h3&gt; &lt;p&gt;We go through the steps to use a *.csv file for testing.&lt;/p&gt; &lt;p&gt;For this project, imagine we are creating a new Math Library to be distributed. &lt;/p&gt; &lt;p&gt;Start VS2010 &amp;gt; New Project: Class Library &amp;gt; Name: “MathLibrary” and click [OK]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-bEd_dyDx-hY/Tjc_U5BkJNI/AAAAAAAADc0/MrVNwtbNfBk/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-drSPv34bCxc/Tjc_Vnjl-bI/AAAAAAAADc4/f_Qb5Vzzp_U/image_thumb111.png?imgmax=800" width="484" height="278"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the name of the class to "Calculator":&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-3zoM37pvSDQ/Tjc_Vz42GFI/AAAAAAAADc8/tVVQtTJD8JU/s1600-h/image11.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-KhEsApdB7ho/Tjc_Xl23LMI/AAAAAAAADdA/WQ_nLiAJJaE/image_thumb51.png?imgmax=800" width="484" height="312"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add a new method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-yAbjIbR-hhg/Tjc_YFJX3oI/AAAAAAAADdE/W5-YwJpkdJQ/s1600-h/image15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5ey_we-GlHM/Tjc_YufiFXI/AAAAAAAADdI/x3z9081kksY/image_thumb71.png?imgmax=800" width="484" height="346"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Generate auto test&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Now we will use the automatic generation of the unit tests.&lt;/p&gt; &lt;p&gt;Select the method “AddNumbers”, right-click and select “Create Unit Tests…”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-PwAeBCdQQos/Tjc_ZevObfI/AAAAAAAADdM/KfZ8x6UvwC4/s1600-h/image19.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-uQNMRdtCY0k/TjdAaPDF_5I/AAAAAAAADdQ/C3FdCgWc46w/image_thumb9.png?imgmax=800" width="484" height="478"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;There is no need to change the default setting, just click [OK]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-DhCw27ptNU0/TjdAah_zAWI/AAAAAAAADdU/0r2bVVWlhjQ/s1600-h/image23.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-VoS7TH6L1Vw/TjdAbWZPiMI/AAAAAAAADdY/dS2y8lPaOeQ/image_thumb11%25255B1%25255D.png?imgmax=800" width="484" height="268"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the new test project name to “TestCalculator” and click [Create]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-PZYJQ7btjeE/TjdAbyq-eHI/AAAAAAAADdc/d3r0R-0uwLc/s1600-h/image27.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-G3hB7K3N10A/TjdAdc0SymI/AAAAAAAADdg/DSM46GMpcWs/image_thumb13.png?imgmax=800" width="484" height="170"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The following new test project (TestCalculator) and class (CalculatorTest.cs) will be generated:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-hSGaNs5MWEw/TjdAdydyOnI/AAAAAAAADdk/5EhAb2JDJ-E/s1600-h/image81.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-iLcOG-6VjDk/TjdAeVMK-FI/AAAAAAAADdo/NHmtqVZpOSg/image_thumb3.png?imgmax=800" width="364" height="336"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Look for the method that is performing the test:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-j9hrpmopQfw/TjdAe5lkn4I/AAAAAAAADds/BRniYEl4Zzg/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-aINNDl1rC5U/TjdAgg21PcI/AAAAAAAADdw/c3gejcx9w9k/image_thumb11.png?imgmax=800" width="484" height="208"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the TODO to perform a test as follows:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-MPiAPnyr2Xw/TjdAhNJjePI/AAAAAAAADd0/_evB9AdcsJk/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-OiYG838Z8yU/TjdAhrZ32XI/AAAAAAAADd4/qILCpgY5TzI/image_thumb5.png?imgmax=800" width="484" height="236"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Execute the test: File menu “Test” &amp;gt; Run &amp;gt; All Tests in Solution&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-44pC-5yaHEM/TjdAiMIVKVI/AAAAAAAADd8/HmabeJyVAM0/s1600-h/image131%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-vmErhRC3M2o/TjdA_NgNxHI/AAAAAAAADeA/DSDrIWOPCsQ/image13_thumb.png?imgmax=800" width="364" height="163"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The result will be as follows:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-c9hZdI_60JE/TjdA_Vt2d3I/AAAAAAAADeE/eBJhbTLpjW8/s1600-h/image181.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Q8wziPpknt4/TjdA_7CHNRI/AAAAAAAADeI/VeJIygEolFM/image18_thumb.png?imgmax=800" width="364" height="112"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Create test cases&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Create a text file on desktop, name the file “test.csv” and add the following test cases:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-wymtigR_IEk/TjdBAVziGVI/AAAAAAAADeM/5JjtPPgd1cs/s1600-h/image251.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-YnUp2-b823Q/TjdBGPbczyI/AAAAAAAADeQ/NvJcJ6vHSWs/image_thumb121.png?imgmax=800" width="364" height="224"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Save the above file. &lt;/p&gt; &lt;p&gt;To use the file as input for the test cases: File menu “Test” &amp;gt; Windows &amp;gt; Test View&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-fGpVtxJPfTU/TjdBGoN6WJI/AAAAAAAADeU/j03gpWzZ-N4/s1600-h/image41.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-rq6d57pGkTo/TjdBHPOyMPI/AAAAAAAADeY/ujJdFPoOay0/image_thumb1.png?imgmax=800" width="364" height="254"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Make sure that the “Properties” window is visible. Select “Data Connection String” and click on “…”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-asQtDK6iSPE/TjdBHhZuYrI/AAAAAAAADec/BlCpjtowpPM/s1600-h/image81%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-3ZGLmEgCkTE/TjdBKmvWe8I/AAAAAAAADeg/IQn_mMaczU4/image_thumb31.png?imgmax=800" width="364" height="406"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select “CSV file” and click Next&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-uTGyMT5435M/TjdBLGFLsuI/AAAAAAAADek/GgqYMa3Qydw/s1600-h/image16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-1u2oooFmH8c/TjdBLrCGrQI/AAAAAAAADeo/L6cZsakXp9I/image_thumb7.png?imgmax=800" width="364" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Click on […] to select the “test.csv” file that we have created just now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-ulCp_A3jONQ/TjdBMBOHY_I/AAAAAAAADes/9mo6kKhso8E/s1600-h/image17.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-bYelEnWhrVU/TjdBOPvU5OI/AAAAAAAADew/hO18_V_Wz2M/image_thumb8.png?imgmax=800" width="364" height="364"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Check that the values in the table is correct (otherwise, need to check the test.csv file to correct the error) and click [Finish]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-qi_eigbs-wM/TjdBOj9Hm6I/AAAAAAAADe0/YN4lzutOvwg/s1600-h/image21.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-O26-uNo_ao8/TjdBPDwbC1I/AAAAAAAADe4/OCh4KrsGDLw/image_thumb10.png?imgmax=800" width="364" height="363"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Click “Yes” to copy the file into current project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-RGzWW6qf-nM/TjdBPjAdxuI/AAAAAAAADe8/0qrB99Ou7Zc/s1600-h/image25.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-C8vcyg9cSu4/TjdHJYVSRhI/AAAAAAAADfA/ebKV-X6v5Qg/image_thumb12.png?imgmax=800" width="364" height="152"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice that the test.csv file has been copied into the test project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-QV3N0zGga68/TjdHJxYnJmI/AAAAAAAADfE/Vkr1lWN500c/s1600-h/image29.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-V95oqW6yZCY/TjdHK3OJkGI/AAAAAAAADfI/VG4ij5O8Fro/image_thumb14.png?imgmax=800" width="364" height="400"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The following Attributes have been automatically generated.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Kf7AEFKjioQ/TjdHLmj1DTI/AAAAAAAADfM/PQrcii_1sGk/s1600-h/image33.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-n6dSn3KrKqU/TjdHNwQvngI/AAAAAAAADfQ/811SxT_SN4I/image_thumb16.png?imgmax=800" width="484" height="270"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the code to use the data in the csv file:&lt;/p&gt; &lt;p&gt;DataRow[nn] where nn is the column in each row.&amp;nbsp; DataRow[0] contains the test, DataRow[1] containts n1 and so on.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-tQ8vq9UzfmE/TjoIpJ_bQCI/AAAAAAAADiA/B8DAeecmIvM/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-J2CqcmS9OMs/TjoIr--sEzI/AAAAAAAADiE/P_F2oCW4YA8/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="286"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Execute the test: File menu “Test” &amp;gt; Run &amp;gt; All Tests in Solution&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-r8aywqX2NT0/TjdHP57r4HI/AAAAAAAADfc/Tpy-EKnY4sc/s1600-h/image41%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-BQSkuz5NrTI/TjdMddXVdmI/AAAAAAAADfg/Lv1B3M-ssAs/image_thumb20.png?imgmax=800" width="364" height="158"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The result will be as follows:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-TsqRVVg5xJg/TjdMeeXS9-I/AAAAAAAADfk/v3RmvNoUvg4/s1600-h/image45.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-otbBkNn7Yx8/TjdMfDuJucI/AAAAAAAADfo/aHlmH_JLEFQ/image_thumb22.png?imgmax=800" width="364" height="104"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Double-click on the Failed result to see its details:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-A09RKG5xunA/TjdMgbAc_uI/AAAAAAAADfs/q4hpUvG-avA/s1600-h/image49.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Zrz6QKewZWM/TjdNwYdrQvI/AAAAAAAADfw/Qy6b3AfwVzs/image_thumb24.png?imgmax=800" width="484" height="210"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The above is a simple tutorial on how to use a data file and use the automatically generated test class.&amp;nbsp; Since it is not possible for us to list down all test cases, how should we choose the test cases to ensure that they test our method completely?&lt;/p&gt; &lt;h3&gt;How to choose test case?&lt;/h3&gt; &lt;p&gt;We choose values for the test cases to test all statements, all branches, all path combinations and finally the boundary conditions:&lt;/p&gt; &lt;li&gt;Statement coverage - makes sure each statement is executed during the test.  &lt;li&gt;Branch coverage - makes sure flow of control traverses each branch in the code.  &lt;li&gt;Path coverage - makes sure each path through the code is traversed.  &lt;li&gt;Boundary testing - makes sure boundaries are exercised .  &lt;p&gt;That’s all for unit testing&lt;/p&gt; &lt;/li&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-3327229603209533067?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/nYbkJH2kJH4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/3327229603209533067/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/08/unit-testingmanual-automatic-choosing.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/3327229603209533067?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/3327229603209533067?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/nYbkJH2kJH4/unit-testingmanual-automatic-choosing.html" title="Unit Testing–Manual, Automatic &amp;amp; Choosing test cases" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-drSPv34bCxc/Tjc_Vnjl-bI/AAAAAAAADc4/f_Qb5Vzzp_U/s72-c/image_thumb111.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/08/unit-testingmanual-automatic-choosing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4FSH8_cSp7ImA9WhdREUo.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-2073438108487381260</id><published>2011-07-31T21:45:00.001-07:00</published><updated>2011-07-31T21:45:19.149-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-31T21:45:19.149-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="revision-control" /><category scheme="http://www.blogger.com/atom/ns#" term="subversion" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="cvs" /><category scheme="http://www.blogger.com/atom/ns#" term="akhn" /><category scheme="http://www.blogger.com/atom/ns#" term="vs2010" /><category scheme="http://www.blogger.com/atom/ns#" term="version-control" /><category scheme="http://www.blogger.com/atom/ns#" term="source-control" /><title>Source Control</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PFG1CQNXo72gnpuGWv7wWaB3iYc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PFG1CQNXo72gnpuGWv7wWaB3iYc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PFG1CQNXo72gnpuGWv7wWaB3iYc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PFG1CQNXo72gnpuGWv7wWaB3iYc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; &lt;p&gt;According to &lt;a href="http://en.wikipedia.org/wiki/Revision_control"&gt;Wikipedia Revision Control&lt;/a&gt;: Revision control, also known as version control or source control (and an aspect of software configuration management or SCM), is the management of changes to documents, programs, and other information stored as computer files. It is most commonly used in software development, where a team of people may change the same files. Changes are usually identified by a number or letter code, termed the "revision number" …&lt;/p&gt; &lt;p&gt;In its smallest scope, a Source Control System allows team to check in and out source code to edit.&amp;nbsp; In its biggest scope, a Revision Control System allows the whole company to check in and out documents, digital assets on top of source code.&lt;/p&gt; &lt;p&gt;In our daily work, we may already have our own revision control practices, such as adding versions to file names:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-wnHvwnMKpQM/TjYrBv8NU8I/AAAAAAAADXE/KA3IJRc3ikw/s1600-h/image41%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-jTDDimmRvIQ/TjYrDDg0KHI/AAAAAAAADXI/lZCnJVqCV74/image_thumb21.png?imgmax=800" width="364" height="132"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;There are 3 terms that we use in revision control: Trunk, Branch and Tag:&lt;/p&gt; &lt;p&gt;&lt;img src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Revision_controlled_project_visualization-2010-24-02.svg/220px-Revision_controlled_project_visualization-2010-24-02.svg.png"&gt;&lt;/p&gt; &lt;p&gt;Extracted from “&lt;a href="http://stackoverflow.com/questions/16142/what-do-branch-tag-and-trunk-really-mean"&gt;What do track, branch and tag mean?”:&lt;/a&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Trunk&lt;/strong&gt; would be the main body of development, originating from the the start of the project until the present.&lt;/p&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Branch&lt;/strong&gt; will be a copy of code derived from a certain point in the trunk that is used for applying major changes to the code while preserving the integrity of the code in the trunk. If the major changes work according to plan, they are usually merged back into the trunk. &lt;/p&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Tag&lt;/strong&gt; will be a point in time on the trunk or a branch that you wish to preserve. The two main reasons for preservation would be that either this is a major release of the software, whether alpha, beta, RC or RTM, or this is the most stable point of the software before major revisions on the trunk were applied.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Software&lt;/h3&gt; &lt;p&gt;There are many Revision Control Software available in the market:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-a0pbLkP4Aig/TjYrENi00oI/AAAAAAAADXM/ptY85D3XfNE/s1600-h/image19.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Y5-vZo6LOTY/TjYrFgGVzpI/AAAAAAAADXQ/r5_rLgDujpU/image_thumb9.png?imgmax=800" width="484" height="144"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this blog, we shall cover only &lt;a href="http://en.wikipedia.org/wiki/Apache_Subversion"&gt;Subversion (SVN)&lt;/a&gt; which is one of the more widely used open source Client-server software.&amp;nbsp; &lt;/p&gt; &lt;p&gt;For the server, we shall install the &lt;a href="http://www.tigris.org/servlets/OpenCollabNet"&gt;OpenCollabNet Subversion Edge&lt;/a&gt; as not only it will install the Subversion server backend, it comes with a web based administration front.&amp;nbsp; &lt;/p&gt; &lt;p&gt;For the client, we shall only cover the use of &lt;a href="http://ankhsvn.open.collab.net/downloads"&gt;askh plugin&lt;/a&gt; which integrate into VS2010 for the source control.&amp;nbsp; If you need more than source control, example to backup your documents and assets, then you should download the &lt;a href="http://tortoisesvn.net/"&gt;TortiseSVN client&lt;/a&gt;.&lt;/p&gt; &lt;h3&gt;Server – Subversion Edge&lt;/h3&gt; &lt;p&gt;Download the latest Subversion Edge installer and install on a win7 PC:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-d69sXiEY960/TjYsAXfZI0I/AAAAAAAADXU/nY1M83bgJHE/s1600-h/image23.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-I5OyyzvrqoA/TjYsCf35q1I/AAAAAAAADXY/msfUgQ4BcPA/image_thumb11%25255B1%25255D.png?imgmax=800" width="364" height="109"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-LWxHOm2kMoI/TjYsEP8Nn-I/AAAAAAAADXc/9lL8EPPFYLQ/s1600-h/image14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-mSJVG-zM5Ww/TjYsFtO5bkI/AAAAAAAADXg/7cOTfjO8zPo/image_thumb8.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-iI0cpfVEnRM/TjYsLnxL_gI/AAAAAAAADXk/WOcy5xGixLc/s1600-h/image311.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-1jf1r0mpAjk/TjYsNC_jD7I/AAAAAAAADXo/8gWTWWttP_g/image3_thumb.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-QhVaaBiPQIc/TjYsOa-EtnI/AAAAAAAADXs/PuJ_Rt9q0fw/s1600-h/image61.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-49NSX5SC2rs/TjYsQucL1SI/AAAAAAAADXw/hciYGaE6Axs/image6_thumb.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-OmkChDxltIg/TjYsUK1uaJI/AAAAAAAADX0/xG4ORr-nR3w/s1600-h/image911.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-4peLucFZhMY/TjYsWt_TiGI/AAAAAAAADX4/he8gmId33WM/image9_thumb.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Q-7u5rgWmEs/TjYsYJEcRqI/AAAAAAAADX8/DBwFuMnMldY/s1600-h/image13.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-2BaUwr3ec8k/TjYscwfxFlI/AAAAAAAADYA/j4bgMG6kdgM/image_thumb7.png?imgmax=800" width="364" height="210"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-c6QLPXlShsc/TjYsixIH2EI/AAAAAAAADYE/oEEBgmdKQBM/s1600-h/image12%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-D8p2ZnFl-_Y/TjYskLWGsRI/AAAAAAAADYI/jc_G823zSU8/image_thumb6.png?imgmax=800" width="364" height="286"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/---sxe2G4v7A/TjYslq4ULwI/AAAAAAAADYM/__yf5DrA280/s1600-h/image11%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-5X55MR47t2I/TjYsmyM5tKI/AAAAAAAADYQ/o_MxQOJAk9c/image_thumb5%25255B1%25255D.png?imgmax=800" width="364" height="238"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The installer will add two Windows services set to start automatically when&lt;br&gt;the system starts.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;CollabNet Subversion Edge - a Java-based web application that provides a browser UI for configuring and managing your Apache Subversion server.  &lt;li&gt;CollabNet Subversion Server - the actual Apache Subversion server that the management console manages for you, and that your Subversion users will access.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;strong&gt;Login page:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-FQv6k8YnOBs/TjYsseFYtCI/AAAAAAAADYU/Q6mEnIdeikA/s1600-h/image18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-2v96JQjMY9U/TjYstrQu2oI/AAAAAAAADYY/1ESm4UOnRBU/image_thumb10.png?imgmax=800" width="364" height="144"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The default administrator login is:&lt;/p&gt; &lt;ul&gt; &lt;ul&gt; &lt;li&gt;Address: &lt;a href="http://localhost:3343/csvn "&gt;http://localhost:3343/csvn &lt;/a&gt; &lt;li&gt;Username: admin  &lt;li&gt;Password: admin&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;The server is by default “Down”, click on [Start]&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-LSlwgOb91uA/TjYsvX_zAyI/AAAAAAAADYc/0gSYr8S6kLc/s1600-h/image22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-DgF6VI5K4Y0/TjYswtlyhyI/AAAAAAAADYg/OiY4lQJUNqw/image_thumb12.png?imgmax=800" width="364" height="224"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Later, we shall create a new Repository and create new users to access the repository&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-IUoDuX3sd-w/TjYs0hnK5lI/AAAAAAAADYk/9UKo_iTHJ5E/s1600-h/image30.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-RcSAhfAlMD4/TjYs1wDZu4I/AAAAAAAADYo/h2F6Uc3BYXE/image_thumb16.png?imgmax=800" width="364" height="82"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-2j21pW80Mak/TjYs2-i0b_I/AAAAAAAADYs/dD0O_hkOxrw/s1600-h/image31.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-EVbwuegxp2s/TjYs4IITYPI/AAAAAAAADYw/HZTeT8UTHqk/image_thumb17.png?imgmax=800" width="364" height="79"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Visual Studio Plugin – Ankh SVN&lt;/h3&gt; &lt;p&gt;Download the latest AnkhSVN installer and install on a win7 PC:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-gruLckCTY14/TjYs9SwGCQI/AAAAAAAADY0/AXcasiXUgPg/s1600-h/image38.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-DiVPNDD-IT0/TjYs-3Kwx4I/AAAAAAAADY4/6FBmMuP-hOo/image_thumb20.png?imgmax=800" width="364" height="286"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-WFWE61DJD20/TjYtAwRH4ZI/AAAAAAAADY8/DLho1wKJhNM/s1600-h/image42.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-LlCkZP_6IL8/TjYtDFPt5zI/AAAAAAAADZA/djsclI1A4Gc/image_thumb22.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-v1gRA5sQ_QE/TjYtGcKLDjI/AAAAAAAADZE/tt4nklsNx4I/s1600-h/image46.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-JdJTkFRrKFY/TjYtHmOmu5I/AAAAAAAADZI/-rGV3h97gbY/image_thumb24%25255B1%25255D.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Start up Visual Studio 2010 and check that the plugin has installed successfully:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-01-cDk44QFo/TjYtI8_CCPI/AAAAAAAADZM/Cd0CyDQpC-k/s1600-h/image50%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-bXXFLv4VuYI/TjYtMoqFkoI/AAAAAAAADZQ/ouva5u6w-Go/image_thumb26.png?imgmax=800" width="364" height="302"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Step 1: Server – create a new repository&lt;/h3&gt; &lt;p&gt;Before you are able to add code into the server, you need to create a new repository.&amp;nbsp; &lt;/p&gt; &lt;p&gt;For example, we have a VS2010 solution&amp;nbsp; “&lt;font color="#ff0000"&gt;WinFormsGraphics6HitTheMouse&lt;/font&gt;”.&lt;/p&gt; &lt;p&gt;Login into the server, then click on “Repositories” tab, then click on “New Repository”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-cNT3GAGla4I/TjYtPkcWarI/AAAAAAAADZU/YnD8KfbWlTQ/s1600-h/image54%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-BWyz-vrDdgQ/TjYtQ3Zk-FI/AAAAAAAADZY/pmiOz6C0HHU/image_thumb28.png?imgmax=800" width="364" height="198"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Type in the name – all in small cap and click “Create”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-E5ITPPWdprA/TjYtSM93JII/AAAAAAAADZc/CuXalYPv_So/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-GPmKm13Vj8c/TjYtURWZDyI/AAAAAAAADZg/s66Zt6YauYc/image_thumb1.png?imgmax=800" width="364" height="208"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-54RGKEj441c/TjYtckrU6NI/AAAAAAAADZk/7BW-Dml2qMo/s1600-h/image8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-vS89WMo1-WU/TjYteDKY33I/AAAAAAAADZo/Q9k_-zRnA4A/image_thumb3.png?imgmax=800" width="364" height="256"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Click on “Repository List” and take note of the “Checkout command”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-1kw6X2gVPdg/TjYtfRVrgMI/AAAAAAAADZs/njhnLBnaeZc/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-7RlPsmMInaE/TjYtg_f4y4I/AAAAAAAADZw/PsSHejpx1QU/image_thumb5.png?imgmax=800" width="364" height="194"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Step 2: VS2010 – Add the solution and project&lt;/h3&gt; &lt;p&gt;Open Visual Studio 2010 solution:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ZkvOZTZl9vE/TjYtjr-oWhI/AAAAAAAADZ0/XD-udr3ikWw/s1600-h/image16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-dUCZLWsX5dE/TjYtkx4HKJI/AAAAAAAADZ4/mSPxiCoB4TU/image_thumb7%25255B1%25255D.png?imgmax=800" width="364" height="157"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;On the menu, select File &amp;gt; Subversion &amp;gt; Add Solution to Subversion…&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-g3e-e1fEdl4/TjYtmYFMrEI/AAAAAAAADZ8/vYhORXIvo1k/s1600-h/image24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Zv1bOEmfnMs/TjYtnheJ1CI/AAAAAAAADaA/tRwlJ9jfcj4/image_thumb11.png?imgmax=800" width="364" height="192"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Refer to the server repository checkout command and copy the location as highlighted:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-maA0rqSXEic/TjYtseyP_KI/AAAAAAAADaE/G1OhgROPnJo/s1600-h/image20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-OhlynaQyENI/TjYttLIvMuI/AAAAAAAADaI/foZ7k7jXlvQ/image_thumb9%25255B1%25255D.png?imgmax=800" width="364" height="98"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Copy and paste into the Repository URL, then click on [OK]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-E73EMh-njDk/TjYtu866TuI/AAAAAAAADaM/2uOHKyYMPv0/s1600-h/image28.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-YFBKb1TFeHE/TjYtwQtPJkI/AAAAAAAADaQ/JbNnadxcDfg/image_thumb13.png?imgmax=800" width="364" height="412"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Type a message and click [OK]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-7ZljQkGtsZ0/TjYtzQObhwI/AAAAAAAADaU/dWuiEtXtASM/s1600-h/image32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Sx7BF3EuS-0/TjYt1PrbmPI/AAAAAAAADaY/JZpoOt2Dr-4/image_thumb15.png?imgmax=800" width="364" height="264"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Confirm that the action has uploaded the solution and project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Yx8RwRTfsN0/TjYt2YLeZ0I/AAAAAAAADac/sVq38FyL6Lc/s1600-h/image40.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-VrFuCgbY-9A/TjYt4ZkH92I/AAAAAAAADag/PDEp1eDnTV4/image_thumb19.png?imgmax=800" width="364" height="169"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will be asked to key in the username and password for the first time accessing the repository:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Wsoeiljo7zM/TjYt7e9jV-I/AAAAAAAADak/jC3-eubR6jI/s1600-h/image36.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-CvOlTR3m-ro/TjYt9Et4lGI/AAAAAAAADao/sCo8j8wQtKQ/image_thumb17%25255B1%25255D.png?imgmax=800" width="364" height="96"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-5ex8uaoB3i8/TjYt-ZGQlpI/AAAAAAAADas/5pNSVQUVaWQ/s1600-h/image45.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/--ERdylVk5AE/TjYt_kfSzOI/AAAAAAAADaw/6TsQpvACOgY/image_thumb22%25255B1%25255D.png?imgmax=800" width="364" height="164"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;But currently the solution folder if empty as we have yet to add the project into the repository.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-mwl1A0pXgt4/TjYuDU0Dk1I/AAAAAAAADa0/dYZvF96vKQs/s1600-h/image49.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-bbZ5hw7o3oo/TjYuEnyiREI/AAAAAAAADa4/2GEHiEniWdk/image_thumb24.png?imgmax=800" width="364" height="235"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-62am0QJm1po/TjYuF0gWIqI/AAAAAAAADa8/yCRwUuZ_vZg/s1600-h/image53.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/--4oJpssi2LQ/TjYuHWWzyhI/AAAAAAAADbA/IOnbPQYxu3k/image_thumb26%25255B1%25255D.png?imgmax=800" width="364" height="169"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select the Project and right-click &amp;gt; Project &amp;gt; Commit:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-ZKUuscuh01I/TjYuLeuUBUI/AAAAAAAADbE/DHeIMUOg0sM/s1600-h/image57.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-caZfHonL2MY/TjYuMhBz4xI/AAAAAAAADbI/6XYGaKSlNfw/image_thumb28%25255B1%25255D.png?imgmax=800" width="364" height="246"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Type a message and click [OK]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-d8qxY0ayLB4/TjYuONtH_HI/AAAAAAAADbM/4QFEdrNQHWg/s1600-h/image61%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-O9EEFUzWn0U/TjYuVM05CWI/AAAAAAAADbQ/8My1pR-7wJM/image_thumb30.png?imgmax=800" width="364" height="283"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Check that the project files has been uploaded:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-SgsnifZ3cPU/TjYuYk_m4ZI/AAAAAAAADbU/SyMMhUjr6NY/s1600-h/image65.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-bSWx86-0vEo/TjYuZ-yEujI/AAAAAAAADbY/qfHZ9zJxCrM/image_thumb32.png?imgmax=800" width="364" height="178"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Xy1zBXmPDnI/TjYubmFa1pI/AAAAAAAADbc/697TsoHjRJg/s1600-h/image69.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-9nqXU55x6Zc/TjYudKQ1LAI/AAAAAAAADbg/Cq0TvqaxdRY/image_thumb34.png?imgmax=800" width="364" height="238"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Checkout from the repository to Edit&lt;/h3&gt; &lt;p&gt;&lt;u&gt;&lt;strong&gt;Checkout for the first time by another programmer&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;Another programmer need to check out the source from the server to edit and then commit the changes to add to the repository.&lt;/p&gt; &lt;p&gt;Menu: View &amp;gt; Repository Explorer&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-lxey-kIfFWY/TjYugJ6iFQI/AAAAAAAADbk/IKpZinu2GPU/s1600-h/image73.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/--4dic3tqN04/TjYuhjD1rfI/AAAAAAAADbo/zfwTKRlb_S0/image_thumb36.png?imgmax=800" width="364" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select the solution folder, then click on ”Checkout from Subversion” icon:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-jj2VLiuQF5g/TjYujoqH71I/AAAAAAAADbs/B2fZKrXSJiI/s1600-h/image77.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-fPHG5QWntoc/TjYuk9u_i5I/AAAAAAAADbw/vSrmcuFDr68/image_thumb38.png?imgmax=800" width="364" height="188"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-hRXobOD3zac/TjYuoYkmXGI/AAAAAAAADb0/4ETzqqkmkJE/s1600-h/image81.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-t4LgvGW4MMM/TjYuquZh5yI/AAAAAAAADb4/XR_NzrzP02w/image_thumb40.png?imgmax=800" width="364" height="190"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You then open the solution as per normal for your editing.&lt;/p&gt; &lt;p&gt;For example, I added a comments below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-J93Y-NyqAbE/TjYuryvR0CI/AAAAAAAADb8/ueUBuNL4LT8/s1600-h/image85.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-QFWw5OTz0Gg/TjYutjtCa4I/AAAAAAAADcA/y1Gh-mIicY8/image_thumb42.png?imgmax=800" width="364" height="166"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-PjG0oFn0k1I/TjYu9405HVI/AAAAAAAADcE/68z78SimhOw/s1600-h/image89.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-EtTEEhyTUEw/TjYu_TZAvuI/AAAAAAAADcI/xtIQcXivlcM/image_thumb44.png?imgmax=800" width="364" height="258"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-CyeVBeTrsH4/TjYvBcf_5MI/AAAAAAAADcM/5EkRJSD7UJQ/s1600-h/image93.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-FfG99y86_vY/TjYvCTBU3wI/AAAAAAAADcQ/iCf5YscJ6YM/image_thumb46.png?imgmax=800" width="364" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Confirm that the changes have been committed to the repository:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-2f8A9HrOs4g/TjYvHOAbj8I/AAAAAAAADcU/xRNA5Ri-46E/s1600-h/image97.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-hgVLLaHKroc/TjYvJZM4BdI/AAAAAAAADcY/f8Kqtdo7fJs/image_thumb48.png?imgmax=800" width="364" height="240"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-zdWc59_S1N8/TjYvKbSkXmI/AAAAAAAADcc/1uCWc7dKhzE/s1600-h/image101.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-LYualuXP2Bo/TjYvM_hkUII/AAAAAAAADcg/s5DFwnorkN8/image_thumb50.png?imgmax=800" width="484" height="114"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;u&gt;&lt;strong&gt;Checkout subsequent time by the same programmer &lt;/strong&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;Just open the solution from local folder, then select the project, Right-click and select “Update Project to Latest Vrsion“:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-AbcF_bzmutw/TjYvSxu6-wI/AAAAAAAADck/JF0b1c88Do0/s1600-h/image105.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-_bdFnTsIY0s/TjYvUCSBMJI/AAAAAAAADco/F7mJt7Dt0zU/image_thumb52.png?imgmax=800" width="364" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then continue editing follows by Committing the changes.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-HD1_uQncPqI/TjYvV9fmh4I/AAAAAAAADcs/8weYp7H_f58/s1600-h/image109.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-FRlaW6_m1W0/TjYvXGL-Z2I/AAAAAAAADcw/dkurf-nrnIw/image_thumb53.png?imgmax=800" width="364" height="258"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That’s all for an introduction to using a source control system with Visual Studio 2010.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-2073438108487381260?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/BgEp0xRioq0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/2073438108487381260/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/source-control.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2073438108487381260?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2073438108487381260?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/BgEp0xRioq0/source-control.html" title="Source Control" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-jTDDimmRvIQ/TjYrDDg0KHI/AAAAAAAADXI/lZCnJVqCV74/s72-c/image_thumb21.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/source-control.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEACQ3Y6fSp7ImA9WhdREUo.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5132324689756942860</id><published>2011-07-31T21:26:00.001-07:00</published><updated>2011-07-31T21:26:02.815-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-31T21:26:02.815-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="deployment" /><category scheme="http://www.blogger.com/atom/ns#" term="install" /><category scheme="http://www.blogger.com/atom/ns#" term="complete" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="resource" /><category scheme="http://www.blogger.com/atom/ns#" term="embed" /><category scheme="http://www.blogger.com/atom/ns#" term="setup" /><category scheme="http://www.blogger.com/atom/ns#" term="distribute" /><title>Deployment</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1cg2JkE5YW7yu_hGV17NyG0vGe0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1cg2JkE5YW7yu_hGV17NyG0vGe0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1cg2JkE5YW7yu_hGV17NyG0vGe0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1cg2JkE5YW7yu_hGV17NyG0vGe0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;There are a few ways to let your user setup and play your game, ie to distribute your game.&lt;/p&gt; &lt;h3&gt;Copy exe file&lt;/h3&gt; &lt;p&gt;If your program consists of only one exe file, then the easiest is to locate your exe file.&amp;nbsp; Send the file to your user.&lt;/p&gt; &lt;p&gt;Locate your project folder, there will be a “bin” folder.&amp;nbsp; your program will be either in the “debug” or “release” folder depends on your setting when you build your program:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-2sSCPX2weBQ/TjYqE6pWTNI/AAAAAAAADVs/Z_bHtg_7Z6c/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-onSFnYzRC-Q/TjYqGn4vVmI/AAAAAAAADVw/OTPn1vfz8R8/image_thumb1%25255B1%25255D.png?imgmax=800" width="484" height="74"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-uDdeWux847g/TjYqH9DCASI/AAAAAAAADV0/l_mzX0gHW80/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-I5_06noeKak/TjYqMDTTI8I/AAAAAAAADV4/PC1NTiI6Efg/image_thumb3.png?imgmax=800" width="364" height="248"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Confirm that it works by copying the file onto your desktop and execute it.&lt;/p&gt; &lt;h3&gt;Create install file&lt;/h3&gt; &lt;p&gt;It looks more professional and also will check that the user has the required runtime file, we shall create a install file.&lt;/p&gt; &lt;p&gt;Select the project, right-click and select “Properties”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-Lks8T9Qpo58/TjYqN-JLHEI/AAAAAAAADV8/tYLgYtcvH1Y/s1600-h/image11.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-cJQzY3hmTSg/TjYqPpMP5EI/AAAAAAAADWA/KH8AQubmBvQ/image_thumb5%25255B1%25255D.png?imgmax=800" width="484" height="430"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select the “Publish” tab:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-S-ks4BXvr28/TjYqRhLV8PI/AAAAAAAADWE/_GQ--KAWbko/s1600-h/image19%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-6tAbTEhpDB4/TjYqUvZYUCI/AAAAAAAADWI/Tupq9t1vGDo/image_thumb9.png?imgmax=800" width="484" height="290"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In future, depending on your projects, you may need to set “Application Files…”, “Prerequisites…” and “Updates…”.&amp;nbsp; For now, we shall only set the “Options…” as follows:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-p78ewIwx3IQ/TjYqV61ezqI/AAAAAAAADWM/S1_UE8CB1FM/s1600-h/image23.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-4S7mXzqLT98/TjYqXWhLPFI/AAAAAAAADWQ/MTh2BfBszU4/image_thumb11.png?imgmax=800" width="484" height="338"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then just click [Publish Now]:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-satcOqBdZzM/TjYqZJdM-wI/AAAAAAAADWU/CIKsq4kG0Z4/s1600-h/image27.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-2D_n8pO2pTU/TjYqcIrRMdI/AAAAAAAADWY/NuiSPlcgN8U/image_thumb13.png?imgmax=800" width="484" height="292"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The publish folder will open once the process is completed:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ZKiwFiOslAA/TjYqeA3muRI/AAAAAAAADWc/vow60YyVIpY/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-4aypqzl52JQ/TjYqfUVXqqI/AAAAAAAADWg/dlAR4aGCzCY/image_thumb1.png?imgmax=800" width="484" height="148"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;These are the files required to send to your users to install onto their PC.&lt;/p&gt; &lt;p&gt;Confirm by installing it yourself, by clicking on the setup.exe, the application will start once the installation is completed:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-GDOPOyANk4I/TjYqhcxuhII/AAAAAAAADWk/LR1YeXNqkaY/s1600-h/image8%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-g8ljkeBtJSM/TjYqlKAMnII/AAAAAAAADWo/yxUtStJzDrc/image_thumb3%25255B1%25255D.png?imgmax=800" width="364" height="160"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-RGKwPXFySiU/TjYqsExDARI/AAAAAAAADWs/nT4n5Wiqt84/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-kWKNgikmPro/TjYqt5BM7EI/AAAAAAAADWw/fzlDYa9MTgw/image_thumb5.png?imgmax=800" width="364" height="247"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-5qoBfYKSydQ/TjYqvnmrNYI/AAAAAAAADW0/pXx2JE72Wio/s1600-h/image15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-wc4zxQva4MU/TjYqy7pmn-I/AAAAAAAADW4/4svn35YF6-w/image_thumb6.png?imgmax=800" width="244" height="242"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will be able to locate the application in the windows start &amp;gt; program menu:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-1qdNzMlHeJc/TjYq0iD7UGI/AAAAAAAADW8/ylzuu9jEgDk/s1600-h/image19.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-v3bOzueAG5Y/TjYq2INf8VI/AAAAAAAADXA/EWeAOB9wAK4/image_thumb8.png?imgmax=800" width="364" height="428"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That’s all for deployment.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5132324689756942860?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/uRPDDbFhx1Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5132324689756942860/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/deployment.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5132324689756942860?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5132324689756942860?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/uRPDDbFhx1Q/deployment.html" title="Deployment" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-onSFnYzRC-Q/TjYqGn4vVmI/AAAAAAAADVw/OTPn1vfz8R8/s72-c/image_thumb1%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/deployment.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYFQ308fCp7ImA9WhdSEk0.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-7342493647861432212</id><published>2011-07-17T21:10:00.001-07:00</published><updated>2011-07-20T17:11:52.374-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-20T17:11:52.374-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="add-reference" /><category scheme="http://www.blogger.com/atom/ns#" term="media-player" /><category scheme="http://www.blogger.com/atom/ns#" term="wav" /><category scheme="http://www.blogger.com/atom/ns#" term="mp3" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="music" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="audio" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Adding sound to Graphics game</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fGzwnA3jbJ-rH62CDmWYFJLJhC4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fGzwnA3jbJ-rH62CDmWYFJLJhC4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fGzwnA3jbJ-rH62CDmWYFJLJhC4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fGzwnA3jbJ-rH62CDmWYFJLJhC4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the previous blog on ball, paddle and blocks, we have left out displaying the score and playing the music sound track.&lt;/p&gt; &lt;p&gt;We have covered how to add score using DrawString(..) in the &lt;a href="http://mpgddspf.blogspot.com/2011/06/hit-mouse-game.html"&gt;Hit the mouse blog&lt;/a&gt;.&amp;nbsp; In this new blog, we shall show you how to add and play a MP3 music sound track.&lt;/p&gt; &lt;p&gt;First copy the project (&lt;a href="http://mpgddspf.blogspot.com/2011/06/paddle-ball-and-blocks.html"&gt;WinFormsGraphics8PaddleBallRows&lt;/a&gt;) to another project: WinFormsGraphics9GameMusic.&amp;nbsp; Refer to earlier blog on &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;how to copy project&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Look for a suitable MP3 file and copy and paste it into the VS project folder:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-LaOzK5H8rZ0/TiOr808WKYI/AAAAAAAADQY/ZeVm4_bAckY/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-S-ZAzr6Av1c/TiOr_tp_bzI/AAAAAAAADQc/1X1IcvDnOuo/image_thumb3.png?imgmax=800" width="364" height="241"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;No need to change the properties of the MP3 file:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-2k6Y1QUbBS8/TiOsBTldsaI/AAAAAAAADQg/3O-84ITtnjM/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-qMeDAkiIGfA/TiOsC8jEKdI/AAAAAAAADQk/QiYTHcCqz3o/image_thumb1.png?imgmax=800" width="364" height="199"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Embed resource&lt;/h3&gt; &lt;p&gt;Instead of copying the above file directly to the output folder and play it from there, we shall be adding the file into the project as resource.&lt;br&gt;Menu: Project &amp;gt; project Properties&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-k1POiVLRckY/TiOsEI97VAI/AAAAAAAADQo/bOA3cGCBBiY/s1600-h/image8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-cuvloBq9x10/TiOsF5l9EqI/AAAAAAAADQs/3YzVo4IKnwM/image_thumb3%25255B1%25255D.png?imgmax=800" width="484" height="366"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select the “Resources” tab on the left column and click on “Add Resource”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-Rh62iwVuALo/TiOsHbhsJLI/AAAAAAAADQw/-FxWDW8d92o/s1600-h/image12%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Bz-wGkMw6pI/TiOsI9dhOmI/AAAAAAAADQ0/lDEt7SB9CJM/image_thumb5.png?imgmax=800" width="484" height="316"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Browse and find the mp3 file:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-AzyYxPjgQUc/TiOtFw3ogWI/AAAAAAAADQ4/zGHMPArUmHk/s1600-h/image16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-jqstldNuimw/TiOtHqkDzLI/AAAAAAAADQ8/R0TvAq6BYsw/image_thumb7%25255B1%25255D.png?imgmax=800" width="484" height="296"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will get the following result – name of the resource is just “music”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-6iuoiY-GMoY/TiOtIgxDfmI/AAAAAAAADRA/V6Rk816kZ2k/s1600-h/image20%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-12Kko7uBzoo/TiOtJ1ofRVI/AAAAAAAADRE/h1iBBF6JMAM/image_thumb9.png?imgmax=800" width="484" height="316"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Use Windows Media Player&lt;/h3&gt; &lt;p&gt;We shall be using Windows Media Player to play the mp3.&amp;nbsp; To do so, we need to add the reference to the project before we could access to the API.&lt;/p&gt; &lt;p&gt;Right click on References and select “Add Reference”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-jOMlV9WIm-g/TiOtMXdMCsI/AAAAAAAADRI/8OS6gUiKAKA/s1600-h/image15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-KLe77l5mB3c/TiOtNblAusI/AAAAAAAADRM/Jw2adK4dOVw/image_thumb7.png?imgmax=800" width="484" height="244"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Select the “COM” tab, page down, select "”Windows Media Player – wmp.dll” and click [OK].&amp;nbsp; DLL stands for Dynamic-Link Library which is Microsoft way of providing shared libraries.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-VgBepslg1CU/TiOtOo3tx2I/AAAAAAAADRQ/MnZcWqyhnf0/s1600-h/image191.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-HDR2WF2urlc/TiOtQF3iKUI/AAAAAAAADRU/-3eTKfqOclI/image_thumb9%25255B1%25255D.png?imgmax=800" width="484" height="364"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will see that WMPLib is added into the References.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-UL1R9rqhEfA/TiOxZ8BoU2I/AAAAAAAADRY/2o469vbNTKI/s1600-h/image231.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-yJFobc5-U7Q/TiOxbAcqOyI/AAAAAAAADRc/yklPfFTD2E8/image_thumb11.png?imgmax=800" width="364" height="378"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In Form1.cs, near the top, add the following object:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add a new using statement so that later on we need not specify the full namespace for IO related classes – eg Stream, File, etc.  &lt;li&gt;Create one instance of the Media Player object.  &lt;li&gt;Set the filename to be used later.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-FF64sQ4emA4/TiOxb8tjKhI/AAAAAAAADRg/SYBRs9dzNoY/s1600-h/image39.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-_KNe4YLzph8/TiOxc_Ew1KI/AAAAAAAADRk/tp6qka4Q4Lw/image_thumb19.png?imgmax=800" width="484" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-0Oe-wS84z7Y/TiOxf_5gDhI/AAAAAAAADRo/uqD4QZnjge8/s1600-h/image71.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-D5R00mjfdf4/TiOxg_cxYiI/AAAAAAAADRs/B-qDNOvTwlo/image_thumb31.png?imgmax=800" width="484" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the Load() method, add the following code:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Use System.Reflection to read the file embedded as stream.  &lt;li&gt;Then convert the file stream into a temporary file in the same directory as the executing program.  &lt;li&gt;Set the Media Player parameters and settings.&amp;nbsp; For details on setMode, refer to &lt;a href="http://msdn.microsoft.com/en-us/library/dd564342%28v=vs.85%29.aspx"&gt;MSDN Settings.setMode&lt;/a&gt;.  &lt;li&gt;Play the mp3 file.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-6-zYM7jCb8g/TiOxhuQVqKI/AAAAAAAADRw/B-XEgx29e3U/s1600-h/image27%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-IsB2dCMcXoY/TiOxiv4EKNI/AAAAAAAADR0/kTI62BTL7GI/image_thumb12.png?imgmax=800" width="484" height="350"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-S3D1uiqDBrg/TiOxk_PkwSI/AAAAAAAADR4/wWPP_3IIGgU/s1600-h/image28.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-sU-9FUZ_VcM/TiOxlonIamI/AAAAAAAADR8/XAP3uFCgyL8/image_thumb13.png?imgmax=800" width="484" height="120"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If you build and execute now, the mp3 should play.&amp;nbsp; But when the game is over, it will not stop.&amp;nbsp; Hence we need to stop the media player:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-8yhtU7o-v5E/TiduxGQJwEI/AAAAAAAADSo/TyhcCG88o5Y/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-kigz1BSj89w/Tiduxsa7reI/AAAAAAAADSs/jY_3qLHCVu4/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="469"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We need to remove the temporary file, in case user closes the form before the game end&lt;/p&gt; &lt;p&gt;Select the form in deign view:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-pvsNyaINvNA/TiOxvkWQSiI/AAAAAAAADSI/1-GwsmKYEW4/s1600-h/image27.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-pPujorRQfag/TiOxwUVGCCI/AAAAAAAADSM/P2621h8XzgQ/image_thumb13%25255B1%25255D.png?imgmax=800" width="364" height="388"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Go to Properties window, select events and add a new “FormClosing” event:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-4PFDS6LTc7E/TiOxxpTojXI/AAAAAAAADSQ/LusRiglSCyw/s1600-h/image31.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-h0KqKo752sQ/TiOxyZWlVAI/AAAAAAAADSU/gjfDt9uIxck/image_thumb15.png?imgmax=800" width="364" height="192"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add the code to check if the temporary file exits, then delete it:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-ektqk_GxOto/TiOyOCiaYMI/AAAAAAAADSY/_4zQ4WIH0yQ/s1600-h/image35.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-yjWRg1z7Bog/TiOyO0x23QI/AAAAAAAADSc/1NvN0b8uQhg/image_thumb17.png?imgmax=800" width="484" height="124"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/--ZE81RHEHsk/TiOyP7XFd-I/AAAAAAAADSg/EsYwgADUyWE/s1600-h/image43.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-8kBTB_lQOvQ/TiOyQ0c3L6I/AAAAAAAADSk/0Tnjsw0mmz0/image_thumb21.png?imgmax=800" width="364" height="364"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If you need to play a wav file, you may just use the SoundPlayer.&amp;nbsp; Refer to &lt;a href="http://msdn.microsoft.com/en-us/library/4y171b18.aspx"&gt;MSDN on how to play wav file using SoundPlayer&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-7342493647861432212?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/Asacj3Jlg4c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/7342493647861432212/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/adding-sound-to-graphics-game.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7342493647861432212?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7342493647861432212?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/Asacj3Jlg4c/adding-sound-to-graphics-game.html" title="Adding sound to Graphics game" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-S-ZAzr6Av1c/TiOr_tp_bzI/AAAAAAAADQc/1X1IcvDnOuo/s72-c/image_thumb3.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/adding-sound-to-graphics-game.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4NSHg9fyp7ImA9WhdTF00.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5327841618316015963</id><published>2011-07-14T22:11:00.001-07:00</published><updated>2011-07-14T22:16:39.667-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-14T22:16:39.667-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="interface" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="abstract" /><title>Abstract classes &amp; Interfaces</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/H9RlFD8f1-UeC2uhHwTsr_jm__Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/H9RlFD8f1-UeC2uhHwTsr_jm__Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/H9RlFD8f1-UeC2uhHwTsr_jm__Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/H9RlFD8f1-UeC2uhHwTsr_jm__Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;An abstract class is one that does not have complete implementation while an interface has no implementation at all.&lt;/p&gt; &lt;p&gt;We cannot instantiate an abstract class or an interface, they are useful only to be inherited.&amp;nbsp; &lt;/p&gt; &lt;h3&gt;Abstract class&lt;/h3&gt; &lt;h3&gt;&lt;/h3&gt; &lt;p&gt;An abstract class may contain fields, properties and methods.&amp;nbsp; At least one of the member must be defined as abstract.&lt;/p&gt; &lt;p&gt;In the example below, only one method is abstract.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-RkNGLHH_1Mc/Th_L2KKb3ZI/AAAAAAAADPw/BB3LiOE8mFQ/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-iapEPjKp-No/Th_L2mdfBFI/AAAAAAAADP0/t9DcoNfwBvk/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="434"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-4h8mPPvQYG8/Th_L3Kb24AI/AAAAAAAADP4/5FIZo32GjS0/s1600-h/image%25255B10%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-KDjJ2UrFXko/Th_L3ucfthI/AAAAAAAADP8/mlMdeYKn1mE/image_thumb%25255B4%25255D.png?imgmax=800" width="484" height="382"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-OgToKzgUzsc/Th_L6eoyNrI/AAAAAAAADQA/e2sG40mKPLg/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-gHwqlFXY1QU/Th_L666d4ZI/AAAAAAAADQE/-yj5nGEUxck/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="202"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Another example, extracted from &lt;a href="http://www.dotnetrangers.net/2011/05/06/common-design-patterns-in-c-4-0-part4-factory-method-pattern/"&gt;external site&lt;/a&gt;.&amp;nbsp; It shows the derived classes using the “override” keyword to implement the abstract method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-tUq8xWcRe2E/Th_NNGy2JuI/AAAAAAAADQQ/k4buM329ZR8/s1600-h/image%25255B27%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-V4B26lPqhB0/Th_NNkiSctI/AAAAAAAADQU/OTCD5zSfOlw/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="845"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Interface&lt;/h3&gt; &lt;p&gt;An interface is &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt; a class.&amp;nbsp; It contains only methods without implementation.&lt;/p&gt; &lt;p&gt;It is a naming convention to start the name of an interface with a capital i as illustrated in the following example:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-KXY8SNcWK2E/Th_L7ZJAtiI/AAAAAAAADQI/UTb75GXvwYM/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-nuXC88XhWmk/Th_L72PLvUI/AAAAAAAADQM/-qWB3vDked4/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="150"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;An interface only provides the behaviours of its derived classes – for the example above: must be able to get value, must be able to compare.&lt;/p&gt; &lt;p&gt;Basically we use abstract classes or interfaces to provide a structure or a contract that their derived classes must do or provide.&lt;/p&gt; &lt;p&gt;With this we have wrapped up the key features of OOP.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5327841618316015963?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/ImsuidpGZQs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5327841618316015963/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/abstract-classes-interfaces.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5327841618316015963?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5327841618316015963?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/ImsuidpGZQs/abstract-classes-interfaces.html" title="Abstract classes &amp;amp; Interfaces" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-iapEPjKp-No/Th_L2mdfBFI/AAAAAAAADP0/t9DcoNfwBvk/s72-c/image_thumb%25255B9%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/abstract-classes-interfaces.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUMSHw6eSp7ImA9WhdTFkg.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-8542420696308366483</id><published>2011-07-14T06:27:00.001-07:00</published><updated>2011-07-14T07:04:49.211-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-14T07:04:49.211-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Access-modifier" /><category scheme="http://www.blogger.com/atom/ns#" term="protected" /><category scheme="http://www.blogger.com/atom/ns#" term="protected-internal" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="internal" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="public" /><category scheme="http://www.blogger.com/atom/ns#" term="private" /><title>Access modifiers–private, public, protected and …</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/unc88QgoYsq5s406pgATqGhkZ3I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/unc88QgoYsq5s406pgATqGhkZ3I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/unc88QgoYsq5s406pgATqGhkZ3I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/unc88QgoYsq5s406pgATqGhkZ3I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the earlier blog, we mentioned that OOP Encapsulation is achieved by using the keyword “private”.&amp;nbsp; This keyword and a few others that control the access to the members are called &lt;strong&gt;Access Modifiers&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;The more common ones are “private”, “public” and “protected”.&amp;nbsp; The less common ones are “internal” and “protected internal”.&lt;/p&gt; &lt;p&gt;The least restrictive is “public” while the most restrictive is “private”.&lt;/p&gt; &lt;p&gt;Access Modifiers can be used on class and its members, but for simplicity, we shall focus on variables in this blog.&lt;/p&gt; &lt;p&gt;We shall use the project completed earlier in the previous blog on &lt;a href="http://mpgddspf.blogspot.com/2011/07/inheritance.html"&gt;inheritance&lt;/a&gt;: ConsoleClassCharacter&lt;/p&gt; &lt;p&gt;Add the following 3 variables into Character class:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-_cLre4bK_4o/Th7utaiIZFI/AAAAAAAADOQ/O4kWyJ8opx0/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-bhOx4G8dNwI/Th7uugqrl0I/AAAAAAAADOU/UVRwta5xN4Y/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="294"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We will test their scope as follows:&lt;/p&gt; &lt;p&gt;1) we test them in Character class: all 3 variables are accessible.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-31PupKsVxNU/Th7uvYZ9rhI/AAAAAAAADOY/ArMbXehTrdE/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-5U6KJr55zp8/Th7uwhsQQYI/AAAAAAAADOc/yWF1P535F9M/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="380"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;2) We test them in one of the Derived classes – Alien class: &lt;/p&gt; &lt;ul&gt; &lt;ul&gt; &lt;li&gt;private variable: although inherited but it is not accessible&lt;/li&gt; &lt;li&gt;protected and public variables: accessible&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-t1Wlro-UueM/Th7uxUv1R4I/AAAAAAAADOg/00zASQbm98c/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-k0YnZIdx-ds/Th7uyHCkQaI/AAAAAAAADOk/PHHmkg8oCKw/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="208"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;3) We test them in another class – Program:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;private and protected variables: not accessible&lt;/li&gt; &lt;li&gt;public variables: accessible via instance field&lt;/li&gt;&lt;!--EndFragment--&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-0nPeLmWNvNI/Th7uy_jqtpI/AAAAAAAADOo/FOrGCl7Tuqc/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-0S5YHrcumng/Th7uz62_4dI/AAAAAAAADOs/1lEnavgF2tk/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="310"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;internal&lt;/h3&gt; &lt;p&gt;To test “internal”, we need to have another project with a different namespace.&amp;nbsp; Add a project: ConsoleClassCharacter&lt;font color="#ff0000"&gt;2&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-PdH2AJQpdXc/Th73Qx7mywI/AAAAAAAADOw/HbAUpAOT668/s1600-h/image%25255B25%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-wgGneja0w_8/Th73SDWDOFI/AAAAAAAADO0/IFwlmpG996c/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="252"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-umJSmQjxvvM/Th73Tc9o5AI/AAAAAAAADO4/LIBHXf65E5A/s1600-h/image%25255B24%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-sbVZ8HAR2rY/Th73UtuQE3I/AAAAAAAADO8/nPe7YaCtpT0/image_thumb%25255B12%25255D.png?imgmax=800" width="484" height="274"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-SsjKBPrVGc8/Th73Vcfr_gI/AAAAAAAADPA/8RP0WYcJR_8/s1600-h/image%25255B32%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-So_BdOK1zMo/Th73WVyauzI/AAAAAAAADPE/3iC4gUeidBg/image_thumb%25255B16%25255D.png?imgmax=800" width="364" height="264"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;To let the 2nd project to access the 1st project, we need to add reference:&lt;/p&gt; &lt;p&gt;Right click on “ConsoleClassCharacter2”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-5rsCULP_DbM/Th73XRM0dyI/AAAAAAAADPI/wVi2jOGDSq8/s1600-h/image%25255B38%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-9dTzz41_krA/Th73YSrII5I/AAAAAAAADPM/U4QOzeJ1xbk/image_thumb%25255B20%25255D.png?imgmax=800" width="484" height="286"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-2dDkgwdkrJo/Th73ZXIJ7eI/AAAAAAAADPQ/pgksDAmHspA/s1600-h/image%25255B37%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-mtGLmAVD3QM/Th73au0bwbI/AAAAAAAADPU/J2a2IQPMN5U/image_thumb%25255B19%25255D.png?imgmax=800" width="484" height="436"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We need to define the Character class as public and add the”internal” variable:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-pplzRCYgvl4/Th73bUaoGoI/AAAAAAAADPY/JkuTIhUaKnM/s1600-h/image%25255B46%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-QUoIky6VOIE/Th73cTc_CYI/AAAAAAAADPc/0JjT2puiXmQ/image_thumb%25255B24%25255D.png?imgmax=800" width="484" height="398"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;There is no difference in the main() for “public” and “internal” variable:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-TlNSqTE3GBg/Th73dGsTgyI/AAAAAAAADPg/bkRtVKRfqls/s1600-h/image%25255B50%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-n4PcvlZGtpQ/Th73eAoZ6DI/AAAAAAAADPk/cr7fSv-WQKM/image_thumb%25255B26%25255D.png?imgmax=800" width="484" height="322"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add the using statements in ConsoleClassCharacter2 - there is no difference in the main() for “public” and “internal” variable:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-uiE6tjP3h9I/Th73e6QQPVI/AAAAAAAADPo/FnuTeZYSV_4/s1600-h/image%25255B54%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-SrgwVNlyt6g/Th73f1JEj7I/AAAAAAAADPs/4Kj4_fcPnbQ/image_thumb%25255B28%25255D.png?imgmax=800" width="484" height="360"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The different? &lt;/p&gt; &lt;p&gt;“internal” variables can be used by different project but in the same solution but not outside the solution.&amp;nbsp; “public” can be used outside of the solution.&lt;/p&gt; &lt;h3&gt;internal protected&lt;/h3&gt; &lt;p&gt;“internal protected” =&amp;gt; “internal”&amp;nbsp; and “protected”:&amp;nbsp; that means it will be accessible in the same solution and also derived classes.&amp;nbsp; Scope is more than just “internal”.&lt;/p&gt; &lt;p&gt;That’s all for Access Modifiers.&amp;nbsp; Next we will cover Abstract class and Interface.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-8542420696308366483?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/7BzVAp6LuPU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/8542420696308366483/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/access-modifiersprivate-public.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8542420696308366483?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8542420696308366483?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/7BzVAp6LuPU/access-modifiersprivate-public.html" title="Access modifiers–private, public, protected and …" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-bhOx4G8dNwI/Th7uugqrl0I/AAAAAAAADOU/UVRwta5xN4Y/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/access-modifiersprivate-public.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkAEQng7cCp7ImA9WhdTFkw.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-4882506943225754798</id><published>2011-07-13T19:31:00.001-07:00</published><updated>2011-07-13T19:31:43.608-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-13T19:31:43.608-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="static" /><category scheme="http://www.blogger.com/atom/ns#" term="default-constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="method" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="field" /><title>Static Classes and static members</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BrTZhFDafkP3bsJUY3Dab_Pby-Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BrTZhFDafkP3bsJUY3Dab_Pby-Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BrTZhFDafkP3bsJUY3Dab_Pby-Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BrTZhFDafkP3bsJUY3Dab_Pby-Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;When a class is defined as static, it contains only static members (fields, properties and methods).&amp;nbsp; A static class differ from normal class in one way – it cannot be instantiated =&amp;gt; cannot use “new” keyword with instance constructors.&lt;/p&gt; &lt;p&gt;Since C# is purely OOP, there is no way to define utility functions to do simple calculation such as math’s functions.&amp;nbsp; If we define these methods in a Math class, it is quite pointless to create an object of Math before using its methods.&amp;nbsp; Hence we declare Math class as static:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-UAx-rbzjqcc/Th5Gopt297I/AAAAAAAADNc/WF20-xPa70E/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-2weu4cxbNvM/Th5Gpc9fP7I/AAAAAAAADNg/SkM5OvkvPqg/image_thumb1.png?imgmax=800" width="364" height="42"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;C# class library already define this static Math class with all its static methods, such as Round(..) method.&amp;nbsp; &lt;/p&gt; &lt;p&gt;How to use static class and its methods?&lt;/p&gt; &lt;p&gt;Just call the class name follows by a dot and then the method name:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-nw6YkGSJJXw/Th5GqKCyGfI/AAAAAAAADNk/Fk4GbdjN130/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Wl3ikUBykWA/Th5GrN-PPUI/AAAAAAAADNo/JxwXitvP5CA/image_thumb3.png?imgmax=800" width="484" height="84"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Static members&lt;/h3&gt; &lt;p&gt;A non-static class may contain static members (fields, properties or methods).&amp;nbsp; Only one copy of the static members exists regardless of the number of instances of the class are created.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Static members may be access even before the first instance is created.&amp;nbsp; Static members cannot access non-static members.&lt;/p&gt; &lt;p&gt;Use the Character class created in the previous blog to illustrate.&lt;/p&gt; &lt;p&gt;Define a static int variable count to keep track of the number of Character created.&amp;nbsp; Define a constructor to add the count by one.&amp;nbsp; A non-static constructor is also called instance constructor.&lt;/p&gt; &lt;p&gt;For the derived classes (Alien, Bandit, Cowboy &amp;amp; Pirate), since their constructors are not defined, a default constructor will be generated by the compiler.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-7vfLGA2neAE/Th5G6bPQjPI/AAAAAAAADNs/98p7X08vwWg/s1600-h/image11.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-FfIMKqof1xI/Th5G7xEKHOI/AAAAAAAADNw/w6cMQ9wB0ss/image_thumb5.png?imgmax=800" width="484" height="460"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;For example, the default constructor generated for Alien class will be as follows. “: base()” means that the parent (base) class constructor will be called.&amp;nbsp; In this case, Character() will be called.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Imagine “: base()” represent “: Character()”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-KHZpWgC5LUw/Th5G8tL7gAI/AAAAAAAADN0/aJEJtusmJjM/s1600-h/image15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-bPjsHQQc2TE/Th5G9dQT0fI/AAAAAAAADN4/ku7HQqvjBRw/image_thumb7.png?imgmax=800" width="484" height="88"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The above is only for illustration, there is no need to define the constructors for the derived classes, the default ones will do.&amp;nbsp; Next, we test it in main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-_3QsBQpoNqU/Th5U-Gz8GsI/AAAAAAAADN8/ZMhKGUs3ZcQ/s1600-h/image19.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-u1_kBW3h4Io/Th5VALcDxyI/AAAAAAAADOA/G9MbfjH9lwk/image_thumb9.png?imgmax=800" width="484" height="473"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-6j7en630n5U/Th5VBjWXU0I/AAAAAAAADOE/IimbZFFH7fA/s1600-h/image23.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-MzUkwktHTWs/Th5VDULvc1I/AAAAAAAADOI/aamGYDdPxhs/image_thumb11.png?imgmax=800" width="364" height="160"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The next section we shall discuss the Access Modifiers in details.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-4882506943225754798?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/ibFOlIQAiiY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/4882506943225754798/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/static-classes-and-static-members.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/4882506943225754798?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/4882506943225754798?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/ibFOlIQAiiY/static-classes-and-static-members.html" title="Static Classes and static members" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-2weu4cxbNvM/Th5Gpc9fP7I/AAAAAAAADNg/SkM5OvkvPqg/s72-c/image_thumb1.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/static-classes-and-static-members.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYNSH47fyp7ImA9WhdTFUg.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-2244406788791592749</id><published>2011-07-13T01:04:00.001-07:00</published><updated>2011-07-13T02:43:19.007-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-13T02:43:19.007-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="virtual" /><category scheme="http://www.blogger.com/atom/ns#" term="polymorphism" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="override" /><category scheme="http://www.blogger.com/atom/ns#" term="oop" /><title>Inheritance &amp; Polymorphism</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Kx3-21OpCO_bd2yb12IpDEZF_ZM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Kx3-21OpCO_bd2yb12IpDEZF_ZM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Kx3-21OpCO_bd2yb12IpDEZF_ZM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Kx3-21OpCO_bd2yb12IpDEZF_ZM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Another feature of OOP is inheritance.&amp;nbsp; If you have the following classes for your new game.&amp;nbsp; You will notice that there are common behaviours for these four classes. the code in one will be repeated in the rest. Is there a better to design these classes?&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Dp143f1JrEk/Th1MbRH0v4I/AAAAAAAADK0/7ZdiYP78row/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-GbQ7eTHMK8c/Th1MddvjXZI/AAAAAAAADK4/0PIkGh9-hd8/image_thumb1%25255B1%25255D.png?imgmax=800" width="484" height="174"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Yes, by using inheritance and define a common Parent class “Character”.&amp;nbsp; Then inherit from the parents and define the unique behaviours for the four classes.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-VO_fBuNGYsA/Th1MeQMLw5I/AAAAAAAADK8/3Od07wexyfU/s1600-h/image71.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-IjrrtqYoOEU/Th1NCCptwZI/AAAAAAAADLA/B42tDrxNcB0/image_thumb3.png?imgmax=800" width="484" height="292"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The phrase “Parent”, “Base” and “Super” are used inter-changeably while the phrase “Child”, “Derived”, “Sub” are used inter-changeably too.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-7_Kk8cS21_8/Th1NDEJ-RCI/AAAAAAAADLE/f-_bE2p8iwI/s1600-h/image121.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-hkTL6m_Imh0/Th1NEZ05EJI/AAAAAAAADLI/kq_d6LdHUAU/image_thumb6.png?imgmax=800" width="484" height="188"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;From &lt;a href="http://msdn.microsoft.com/en-us/library/ms173149.aspx"&gt;MSDN (Inheritance&lt;/a&gt;): When you define a class to derive from another class, the derived class implicitly gains all the members of the base class,&lt;strong&gt; except for its constructors&lt;/strong&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;But the derived class can only access to the inherited non-private members.&lt;/p&gt; &lt;p&gt;&lt;u&gt;How do you inherit in C#?&lt;/u&gt;&lt;/p&gt; &lt;p&gt;For a “Character” class and its derived “Alien” class, the code will be:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-XEYkeVmuhhQ/Th1NFjR7aDI/AAAAAAAADLM/xkDy1HyRpVc/s1600-h/image161%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-iDSGC24ppLs/Th1NMP-NS6I/AAAAAAAADLQ/TkPgeGYKjN0/image_thumb8.png?imgmax=800" width="484" height="220"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Let’s try it out.&lt;/p&gt; &lt;p&gt;Create a Console Application: &lt;strong&gt;ConsoleClassCharacter&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Add the structure for the two classes:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-I-nRnkJgrwg/Th1NNjuoAjI/AAAAAAAADLU/BWBn82A1eiY/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-cYH0thAWBLs/Th1NO4hAHjI/AAAAAAAADLY/-6XdZpfkqow/image_thumb112.png?imgmax=800" width="484" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add the Walk(), Talk() and Say() method into Character class:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-oS3yL5JP8Ic/Th1NQiYX1tI/AAAAAAAADLc/bx_t6Iwuzbo/s1600-h/image81%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-4W2cy9XSEKk/Th1NUu9oCwI/AAAAAAAADLg/wFfZ9sqQM04/image_thumb31.png?imgmax=800" width="484" height="296"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Since “Alien” class derived from “Character”, it also inherits the public methods.&amp;nbsp; Add the following code into the main() method to test:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-xQJ7adgVO00/Th1NW2N5wKI/AAAAAAAADLk/QT4piafUvyc/s1600-h/image121%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-PwVXOZ97Z3E/Th1NX47kWtI/AAAAAAAADLo/sz_vlEnqsOc/image_thumb5.png?imgmax=800" width="484" height="232"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-_Mt-2nkUvgE/Th1NZMVXUlI/AAAAAAAADLs/Xez7h0pXgpw/s1600-h/image16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-TXgCCAAuQ0w/Th1NcUbS0LI/AAAAAAAADLw/jrOyDRKNrCQ/image_thumb7.png?imgmax=800" width="364" height="116"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now, define the specific methods:&amp;nbsp; Teleport() and Hide() for Alien:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-dKy6RM4wHDg/Th1NdXKcrtI/AAAAAAAADL0/pQ06IFaS8so/s1600-h/image20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-7ByzOP2keJc/Th1NeTAfINI/AAAAAAAADL4/1kw12UEpSAs/image_thumb9.png?imgmax=800" width="484" height="218"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Test it out in the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-x3O9CXdLz_k/Th1NfQgi1KI/AAAAAAAADL8/f4YCyPJl2kI/s1600-h/image24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-4BvBmn2p4A0/Th1N2QfLspI/AAAAAAAADMA/bkLsumx9IMI/image_thumb11.png?imgmax=800" width="484" height="274"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-c7DpHMCQKi0/Th1N3kE2UgI/AAAAAAAADME/ihT1RhuXdzM/s1600-h/image281.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-9eQDApeP3Sc/Th1N5NQD3VI/AAAAAAAADMI/3J8chdLIlfY/image_thumb13.png?imgmax=800" width="364" height="142"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Polymorphism&lt;/h3&gt; &lt;p&gt;Other than Encapsulation and Inheritance, the next important feature of OOP is Polymorphism.&amp;nbsp; Polymorphism is a Greek word that means "many-shaped".&amp;nbsp; &lt;/p&gt; &lt;p&gt;From &lt;a href="http://msdn.microsoft.com/en-us/library/ms173152.aspx"&gt;MSDN (Polymorphism)&lt;/a&gt;:  &lt;p&gt;For example, suppose you have a drawing application that enables a user to create various kinds of shapes on a drawing surface. You do not know at compile time which specific types of shapes the user will create. However, the application has to keep track of all the various types of shapes that are created, and it has to update them in response to user mouse actions. You can use polymorphism to solve this problem in two basic steps:  &lt;ol&gt; &lt;li&gt;Create a class hierarchy in which each specific shape class derives from a common base class.  &lt;li&gt;Use a virtual method to invoke the appropriate method on any derived class through a single call to the base class method.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Let’s implement it using our Character class and its derived classes:&lt;/p&gt; &lt;p&gt;First complete the classes:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-REhOoiVTjKI/Th1N6Nneq5I/AAAAAAAADMM/U2ANjNsDwzI/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-BzB0S9o_40U/Th1O4149hsI/AAAAAAAADMQ/rZoEmsKWE54/image_thumb2.png?imgmax=800" width="484" height="346"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-zFBYbdRQTAw/Th1O558d_nI/AAAAAAAADMU/Frz8ynjYPh0/s1600-h/image8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-9yxMJ7qGU3g/Th1O7c2E96I/AAAAAAAADMY/SLe_FDaP4Vg/image_thumb31%25255B1%25255D.png?imgmax=800" width="484" height="204"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now, we will be using Polymorphism.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Step 1: Create a virtual Draw() method in Character, then Create the override Draw() method in the derived classes (Alien, Bandit, Cowboy &amp;amp; Pirate):&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-1ML8VgcJlCU/Th1O8YVF1SI/AAAAAAAADMc/htjqSjpqBBk/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-xpaMzv3BP8M/Th1PA8ueJUI/AAAAAAAADMg/IYxQNnj1AqI/image_thumb51.png?imgmax=800" width="484" height="414"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-lvFdmFfS6PA/Th1PBxrUh2I/AAAAAAAADMk/nVbObq2Rh5g/s1600-h/image28.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-C-hcCWp6rm4/Th1PDAHW3mI/AAAAAAAADMo/pzc14kgback/image_thumb111.png?imgmax=800" width="484" height="340"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-AXN7BHbBiks/Th1PD_hgZJI/AAAAAAAADMs/uaJ580z9FkQ/s1600-h/image29.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-tVHTuGRlFfg/Th1Qh8cl1HI/AAAAAAAADMw/JtOM33_o1Mg/image_thumb12.png?imgmax=800" width="484" height="236"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-nR4b4WkZByI/Th1QikBnD6I/AAAAAAAADM0/kG1qZrzCsgE/s1600-h/image30.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-B2iGIMaEPrQ/Th1QjkOOfzI/AAAAAAAADM4/XPnVDiuK_Hk/image_thumb131.png?imgmax=800" width="484" height="320"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-qCXzkHVEY9U/Th1QkShOy7I/AAAAAAAADM8/Q9fVKzLaMpI/s1600-h/image31.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-acTpdlwPo_0/Th1RFgFGZ8I/AAAAAAAADNA/FI03XksfXAI/image_thumb14.png?imgmax=800" width="484" height="310"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;These classes are ready to use Polymorphism to do the drawing.&amp;nbsp; We shall test it in the main() method.&lt;/p&gt; &lt;p&gt;Create a list of Character to store objects of Alien, Bandit, Cowboy &amp;amp; Pirate.&amp;nbsp; Although the list is for storing Character, derived classes may also be stored.&amp;nbsp; Then loop through the list to call the Draw() method.&amp;nbsp; The runtime know automatically which Draw() method to call, although they are stored as Character.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Ys3YiV1y5yU/Th1RGSfwbhI/AAAAAAAADNE/CnX5mfL4l_Q/s1600-h/image4%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-sogWPQvltKo/Th1RHehBCOI/AAAAAAAADNI/Aiw9nkNcUA8/image_thumb1.png?imgmax=800" width="484" height="456"&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp; Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-Y2f1ffVjUXg/Th1RIfDhEHI/AAAAAAAADNM/nQmDBAd_6O8/s1600-h/image8%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-1tvCo6Nhqw4/Th1RjFl6NuI/AAAAAAAADNQ/4Ou88XGPc30/image_thumb3%25255B1%25255D.png?imgmax=800" width="364" height="110"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the next section, we shall cover static class and static members (fields, properties or methods).&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-2244406788791592749?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/i5qU7eQsE9g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/2244406788791592749/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/inheritance.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2244406788791592749?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2244406788791592749?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/i5qU7eQsE9g/inheritance.html" title="Inheritance &amp;amp; Polymorphism" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-GbQ7eTHMK8c/Th1MddvjXZI/AAAAAAAADK4/0PIkGh9-hd8/s72-c/image_thumb1%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/inheritance.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQCSX89cSp7ImA9WhdTFU4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-7532837585000025472</id><published>2011-07-12T21:46:00.001-07:00</published><updated>2011-07-12T21:46:08.169-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-12T21:46:08.169-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="optional-parameter" /><category scheme="http://www.blogger.com/atom/ns#" term="named-parameter" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="this" /><title>Constructor and “this” keyword</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ERbFn8U80cVF8VuIdzHQq_2P4bU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ERbFn8U80cVF8VuIdzHQq_2P4bU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ERbFn8U80cVF8VuIdzHQq_2P4bU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ERbFn8U80cVF8VuIdzHQq_2P4bU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;A class definition consists the following sections:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Fields  &lt;li&gt;Properties  &lt;li&gt;Methods  &lt;li&gt;Constructors&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;A constructor is a class method that has the same name as the class.&amp;nbsp; But it differs from method as it does not have any return type.&amp;nbsp; Constructor/s are usually used to initialize values for class fields (data).&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Is32usUosRQ/Th0cbMrhC1I/AAAAAAAADI8/yIcDKHsoLS0/s1600-h/image7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-VYjGTl_BKZA/Th0cb-tPKmI/AAAAAAAADJA/Hufg7LQPiTY/image_thumb2.png?imgmax=800" width="484" height="308"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;A constructor that takes no parameters is called a default constructor.&lt;/p&gt; &lt;p&gt;For example, in the Student class below, the default constructor is “public Student()”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-QujBnUAhvCE/Th0cc_Sn6NI/AAAAAAAADJE/MWt08G3TU34/s1600-h/image3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Lz2o1ElkRt8/Th0cedbXvuI/AAAAAAAADJI/jSKiohPOvKk/image_thumb1.png?imgmax=800" width="484" height="448"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When a class does not contain any constructor, the C# compiler will automatically add a &lt;strong&gt;hidden&lt;/strong&gt; default constructor (that does nothing) for you:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-TlB-_nPJKqw/Th0cfTOfqgI/AAAAAAAADJM/gnON9BiNJBs/s1600-h/image71.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Rg_wu7FxRNs/Th0cgtD7YCI/AAAAAAAADJQ/rl8aQqZpmRc/image_thumb3.png?imgmax=800" width="484" height="124"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Let’s try it out.&lt;/p&gt; &lt;p&gt;Create a Console Application:&lt;strong&gt; ConsoleClassStudent&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Add a Student class with 2 fields and 2 properties.&amp;nbsp; Then use the Student class in the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-y3pIjD9vFzk/Th0chVNPkbI/AAAAAAAADJU/-6EnYoYrom0/s1600-h/image11.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-lgAcpS60NoY/Th0ci0UWnHI/AAAAAAAADJY/Zm7BqjRy6Nw/image_thumb5%25255B1%25255D.png?imgmax=800" width="484" height="456"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and run the above program:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-wUc-DQvGIbs/Th0cmdS1hDI/AAAAAAAADJc/-vC8h9qUprc/s1600-h/image15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-ZfkIK3r35ns/Th0coIEQQaI/AAAAAAAADJg/NM8DZoF7E_U/image_thumb7.png?imgmax=800" width="364" height="118"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify to add a default constructor:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-5TFCJkiPvgw/Th0co4SRhkI/AAAAAAAADJk/_d1jL5k3wBw/s1600-h/image22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-M94-IeRoZfQ/Th0cqCtrrgI/AAAAAAAADJo/jh80U8KTG4A/image_thumb10.png?imgmax=800" width="484" height="378"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and run:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-iGazc83Ca0Q/Th0fF9Ib1YI/AAAAAAAADJs/0hJg38iyLyc/s1600-h/image26%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Rq8n9gxLOvA/Th0fHdwha2I/AAAAAAAADJw/LGf9uMs6lf8/image_thumb12.png?imgmax=800" width="364" height="132"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Constructor Overloading&lt;/h3&gt; &lt;p&gt;Constructor overloading is similar to &lt;a href="http://mpgddspf.blogspot.com/2011/05/methods-4-overloading-optional.html"&gt;method overloading&lt;/a&gt;.&amp;nbsp; You may define a few constructor with different parameters.&lt;/p&gt; &lt;p&gt;For example, you may want the default value of age to be 10 and name to be “none.&amp;nbsp; Prior to optional parameters in C# 4.0, you will need to use Constructor Overloading to define at least four constructors (we will talk about the keyword “this” in the next section):&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-Gy5AQImoJuU/Th0fIjcdzlI/AAAAAAAADJ0/QmQXlAjSIms/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-QBpTZUVwdQI/Th0fKZMZzLI/AAAAAAAADJ4/7mvAS1VEGkg/image_thumb1%25255B1%25255D.png?imgmax=800" width="484" height="595"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Test it out by changing the parameters in the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-diJ7LfCpP-g/Th0fOdWwByI/AAAAAAAADJ8/1qj9a0mpITo/s1600-h/image8%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-zz_7w_e36Dc/Th0fP-uSNyI/AAAAAAAADKA/fkA2k0tqufI/image_thumb3%25255B1%25255D.png?imgmax=800" width="484" height="140"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Optional and named parameters&lt;/h3&gt; &lt;p&gt;Similar to &lt;a href="http://mpgddspf.blogspot.com/2011/05/methods-4-overloading-optional.html"&gt;optional and named parameters for method&lt;/a&gt;, instead of using constructor overloading to allow different parameters, we may use optional parameters by defining their default values in the constructor:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-Za5Qy1Dw6RQ/Th0fQp8UFTI/AAAAAAAADKE/QNum4O625UQ/s1600-h/image12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-pEfsKCo53Is/Th0fRt3NCTI/AAAAAAAADKI/6UHs7M-yqb8/image_thumb5.png?imgmax=800" width="484" height="108"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then we may use optional parameters in the main() method to use the constructor:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-aLnyuvznqDI/Th0hXWkMrRI/AAAAAAAADKM/wcRc-9CzS1o/s1600-h/image29.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-atgSERE2YTI/Th0hYhS4yEI/AAAAAAAADKQ/4-c-OG9TcEo/image_thumb12%25255B1%25255D.png?imgmax=800" width="484" height="142"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-8QKTfuHpdOk/Th0hZlFiGoI/AAAAAAAADKU/To0RynXXHeA/s1600-h/image30.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-vhjWcH6Yoko/Th0hcQp7wZI/AAAAAAAADKY/OZ9W5od4y-o/image_thumb13.png?imgmax=800" width="484" height="142"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-kBvZ5aTJZkg/Th0h5gm1GmI/AAAAAAAADKc/dRvHYqIt8G0/s1600-h/image31.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-rB9K473kHeg/Th0h6umZuEI/AAAAAAAADKg/ct6xiAtxOgY/image_thumb14.png?imgmax=800" width="484" height="142"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-eTB_CpEKlc4/Th0h8iwMFJI/AAAAAAAADKk/emVZMSJg7XQ/s1600-h/image32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-TEXW1wjCJxM/Th0h-vOXKZI/AAAAAAAADKo/eefNKjEfq7w/image_thumb15.png?imgmax=800" width="484" height="140"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and run the above cases to see the results.&lt;/p&gt; &lt;h3&gt;“this” keyword&lt;/h3&gt; &lt;p&gt;The “this” keyword refers to the current object.&amp;nbsp; It is usually used when there are two variables of the same name such as the example below.&amp;nbsp; &lt;/p&gt; &lt;p&gt;“this.age” refers to age that belongs to current object while “age” refers to the parameter.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Ew4ToQ-NRrY/Th0itPztbfI/AAAAAAAADKs/eTZYdzY13f4/s1600-h/image36.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-RK2ht2iDDgw/Th0jDpE-7qI/AAAAAAAADKw/x31soy1mnKU/image_thumb17.png?imgmax=800" width="484" height="350"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the next blog, we will cover inheritance.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-7532837585000025472?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/7CQNdo89lnE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/7532837585000025472/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/constructor-and-this-keyword.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7532837585000025472?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7532837585000025472?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/7CQNdo89lnE/constructor-and-this-keyword.html" title="Constructor and “this” keyword" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-VYjGTl_BKZA/Th0cb-tPKmI/AAAAAAAADJA/Hufg7LQPiTY/s72-c/image_thumb2.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/constructor-and-this-keyword.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEHSHk_eip7ImA9WhdTFE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-8103300287072618392</id><published>2011-07-10T19:12:00.001-07:00</published><updated>2011-07-11T19:10:39.742-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-11T19:10:39.742-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="overloading" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="property" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="method" /><category scheme="http://www.blogger.com/atom/ns#" term="getter" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="setter" /><category scheme="http://www.blogger.com/atom/ns#" term="beginner" /><category scheme="http://www.blogger.com/atom/ns#" term="oop" /><title>Object Oriented Programming (OOP)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Hc4-PvTTvGv1Sug7C9msUWJM72Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hc4-PvTTvGv1Sug7C9msUWJM72Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Hc4-PvTTvGv1Sug7C9msUWJM72Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hc4-PvTTvGv1Sug7C9msUWJM72Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Why use OOP when we are already comfortable with what we have learnt?&lt;/p&gt; &lt;p&gt;We mentioned in &lt;a href="http://mpgddprog.blogspot.com/2011/03/what-is-programming-in-nutshell.html"&gt;“What is programming in a nutshell”&lt;/a&gt;: it is important for us to pick up problem solving skill before we use a programming language to apply the solution to a problem.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-CJyDYN1Q2H8/ThpQmDFLhvI/AAAAAAAADEA/T5ziuVOtKwY/s1600-h/image54.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-8B3gkANNHXU/ThpQnzTPKnI/AAAAAAAADEE/o_DXnEyBhe0/image_thumb27.png?imgmax=800" width="484" height="222"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;OOP provides another way of solving problems – analyse the problem and then apply objects to solve the problem.&amp;nbsp; &lt;/p&gt; &lt;p&gt;For example, in designing a tile-based game, OOP design may be something like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-_vB-7H496Gc/ThpQpPsofGI/AAAAAAAADEI/iCfMUF_VCkc/s1600-h/image%25255B5%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-qNj7kpKtIpA/ThpQqxS9PtI/AAAAAAAADEM/lgQxUeO3MgY/image_thumb%25255B2%25255D.png?imgmax=800" width="484" height="292"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this blog, we shall cover how C# allows us to apply OOP concept, starting with a empty class.&lt;/p&gt; &lt;h3&gt;Creating a class&lt;/h3&gt; &lt;p&gt;Create a Console Application: ConsoleClassShape&lt;/p&gt; &lt;p&gt;There are two ways to add a new class:&lt;/p&gt; &lt;p&gt;1. Solution windows: Right-click the project &amp;gt; Add &amp;gt; Class&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-Lqm2qVQt3As/ThpQvWdWZ7I/AAAAAAAADEQ/rxJNyy--NNE/s1600-h/image4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-7pYkHORs4DI/ThpQw2-3p6I/AAAAAAAADEU/ykx3i4wTQNI/image_thumb2.png?imgmax=800" width="484" height="166"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;2. Add the class in the Program.cs file inself.&amp;nbsp; &lt;/p&gt; &lt;p&gt;For simplicity,we will use the 2nd way in this blog.&amp;nbsp; Add the following below the closing curly bracket that belongs to “class Program”.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-YtrtKoVjJjA/ThpQx3UAWyI/AAAAAAAADEY/M1kie5fCQ10/s1600-h/image41%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5m7FrQ6HrAY/ThpQy0qy-OI/AAAAAAAADEc/5ENFZGIMQ38/image_thumb1%25255B1%25255D.png?imgmax=800" width="484" height="244"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Although this is just a empty class, we are able to use it already:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-RiyN3x5SRg4/ThpRfHIEMiI/AAAAAAAADEg/fOBBL-UdSBk/s1600-h/image8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-yhEIjCJoa9Y/ThpRhBKghvI/AAAAAAAADEk/u9qwZmxxdJg/image_thumb3.png?imgmax=800" width="484" height="296"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice that after you type “rect.”, there are a few methods already available.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-rH-kRz3WHe8/ThpRiAcTndI/AAAAAAAADEo/cY-iOPqL0KE/s1600-h/image15%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-hw9rFcHYpyw/ThpRjC2VMMI/AAAAAAAADEs/X_pe3Dp1Kw0/image_thumb6.png?imgmax=800" width="484" height="300"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and run:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-E5PMWd0-gmU/ThpR9xiYqzI/AAAAAAAADEw/qiOr6xmbY0A/s1600-h/image16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-Jb32iT062eE/ThpR_FGSunI/AAAAAAAADE0/bGeXfHDUwC4/image_thumb7.png?imgmax=800" width="364" height="158"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the above code, we have use the “new” keyword and also the default constructor “Rectangle()”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-QEzirvodM8A/ThpSANXReZI/AAAAAAAADE4/--5DD2jq-vE/s1600-h/image50.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-QgMGDZVcS0w/ThpSBbKPQHI/AAAAAAAADE8/nA53i6vkN7c/image_thumb25.png?imgmax=800" width="364" height="229"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The variable “rect” is also referred to as an &lt;strong&gt;instance&lt;/strong&gt; or an &lt;strong&gt;object&lt;/strong&gt;.&lt;/p&gt; &lt;h3&gt;Encapsulation using accessors&lt;/h3&gt; &lt;p&gt;We shall now define a few variables in the Rectangle class:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-jlov1r_SzSg/ThpSasMhyyI/AAAAAAAADFA/eAPi7SUfDKo/s1600-h/image20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-_eWw04NRYZ8/ThpSb4tx6RI/AAAAAAAADFE/WRtEMw5BhuM/image_thumb9.png?imgmax=800" width="484" height="120"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then we shall access these variables from the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-T3-naMYcKMw/ThpSc0aS2WI/AAAAAAAADFI/auKPvdYF2pc/s1600-h/image24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-w_CYDLR7q7s/ThpSdyL0zAI/AAAAAAAADFM/Ym3RPvlY7CI/image_thumb11.png?imgmax=800" width="484" height="220"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice that “rect.count” gives an error, since “count” is defined as “private” in the Rectangle class, “count” can only be accessed from inside the class but not outside.&amp;nbsp; The private members (variables, methods and others) are used internally only.&lt;/p&gt; &lt;p&gt;Correct the error:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-VS2-EB-C6KA/ThpSkjDpaoI/AAAAAAAADFQ/tywesxrbKmA/s1600-h/image31.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Ix1pabmyEXk/ThpSlwGwcSI/AAAAAAAADFU/eJJbYpW3mOI/image_thumb14.png?imgmax=800" width="484" height="248"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and run:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-zWpCgU_7ZQ8/ThpSndiCgoI/AAAAAAAADFY/AmNwD8sb4cw/s1600-h/image32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-WW1DW15vJ48/ThpSomv4XOI/AAAAAAAADFc/6H9gkun13Vk/image_thumb15.png?imgmax=800" width="364" height="150"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Use Properties instead of public variables&lt;/h3&gt; &lt;p&gt;It is a bad practice to expose variables as public, since there is no way to stop users from setting invalid values into these variables and cause unwanted results.&lt;/p&gt; &lt;p&gt;We shall learn how to create Properties:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;change width and height to “private”  &lt;li&gt;create a property “Width”, then add its “set” and “get”  &lt;li&gt;create a property “Height”, then add its “set” and “get”&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-LqwaQCsXqZQ/ThpSvpuwIRI/AAAAAAAADFg/49xJovYlX30/s1600-h/image39%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Eq60bvbU3kY/ThpSwfgwuBI/AAAAAAAADFk/u9H3rL_JL4U/image_thumb18.png?imgmax=800" width="484" height="302"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-71SEjAIMH7Y/ThpSxd-CAVI/AAAAAAAADFo/j5-bMzHc5qY/s1600-h/image40.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-0nIhEByG2Tc/ThpSyH9zCaI/AAAAAAAADFs/NnonVj-TmlA/image_thumb19%25255B1%25255D.png?imgmax=800" width="484" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Use these properties in the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-OQYF3uiZGgE/ThpTGSJ7eVI/AAAAAAAADFw/DyIf1DEMjXU/s1600-h/image44.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-7n7305qa8Qg/ThpTHR0dOkI/AAAAAAAADF0/0Aza_ELzCVc/image_thumb21.png?imgmax=800" width="484" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It looks almost the same as before, except that for the capital W and H.&amp;nbsp; We will cover the advantage of using properties later, for now, let’s play around by removing the “set” and/or “get” for the properties.&lt;/p&gt; &lt;p&gt;If you comment out the “set” and “get” for Width:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-BsraeTAUWHI/ThpTNskwzdI/AAAAAAAADF4/5o2_s_mjhJM/s1600-h/image48.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-gm42De35Wa8/ThpTPDF5jYI/AAAAAAAADF8/Nh-emqeMv8g/image_thumb23.png?imgmax=800" width="484" height="336"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will get the following errors:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-GCfXyWkkKLU/ThpTQqEqQqI/AAAAAAAADGA/dfhl_jLOeis/s1600-h/image52.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-fIrI2VtPrZk/ThpTRzMJ3uI/AAAAAAAADGE/O--JO5rS8h4/image_thumb251.png?imgmax=800" width="484" height="260"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If you just comment out one of them:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-6igSEBiV1pU/ThpTU_7zG8I/AAAAAAAADGI/7Ud3ugraqi8/s1600-h/image59.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-nu-6VxS-v1A/ThpTWGTFeoI/AAAAAAAADGM/9I5Ai6LIwEY/image_thumb28.png?imgmax=800" width="484" height="338"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will get only one error:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-_F9ITaf66Gw/ThpTXPR-pjI/AAAAAAAADGQ/bmzv7mS5kXE/s1600-h/image60.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-lItNlCpQd78/ThpTYVYFiiI/AAAAAAAADGU/pL4YQ4jl80U/image_thumb29.png?imgmax=800" width="484" height="262"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The above “fooling” around shows us the following relationships:&lt;/p&gt; &lt;p&gt;“rect.Width = 20;”&amp;nbsp; ==&amp;gt; Width’s set&lt;/p&gt; &lt;p&gt;“Console.WriteLine(“Width is “ + rect.Width + …”&amp;nbsp; ==&amp;gt; Width’s get&lt;/p&gt; &lt;p&gt;Now we shall set a break point and step into the program to have a better understanding.&amp;nbsp; But first, we need to change the default option:&lt;/p&gt; &lt;p&gt;Tool &amp;gt; Options&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-LVKUoWhO4ik/ThpTbUNdyKI/AAAAAAAADGY/K0UeiS71BVs/s1600-h/image41%25255B1%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-Y0MRzEkrlHg/ThpTiPx9O3I/AAAAAAAADGc/CixV5uLpeDc/image_thumb1.png?imgmax=800" width="364" height="349"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Debugging &amp;gt; General &amp;gt; Uncheck “Step over properties …”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-Ju7MafhyPfg/ThpTjwBLP1I/AAAAAAAADGg/W6QANJDfWoc/s1600-h/image9.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-F4f3r_tzmCY/ThpTlAPjrMI/AAAAAAAADGk/XHhAi_3pbZw/image_thumb4.png?imgmax=800" width="484" height="324"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Set a break point at “rect.Width = 20;”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-GcaBErr36Qo/ThpTpRQy4wI/AAAAAAAADGo/kpuyOrdOjtA/s1600-h/image14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-nssgzzl9qgM/ThpTqX1qXzI/AAAAAAAADGs/gX9HfEJVzn0/image_thumb71.png?imgmax=800" width="484" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Start Debugging, then click on “Step Into” or F11:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-cxkD9XiQdiU/ThpTrB0KBAI/AAAAAAAADGw/IUT21Zwgn3w/s1600-h/image18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-2W1cgWVvJmo/ThpTsO48cZI/AAAAAAAADG0/NVI9ltpwnIo/image_thumb91.png?imgmax=800" width="364" height="62"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When the step through reach the Width property, hover over “value” and you will see the value “20”. That means “value” is like a input parameter that is automatically filled by the compiler with a value, from the right side of the equal sign.&amp;nbsp; &lt;/p&gt; &lt;p&gt;So for “rect.Width = 20;”&amp;nbsp; “value” will be given a value of 20.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-qhVw02Ib7Nk/ThpV6PMBkpI/AAAAAAAADG4/EFNo81F855Q/s1600-h/image22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-nv5x8Wsq7Zw/ThpV7jvbDzI/AAAAAAAADG8/gBOqqUwXWrs/image_thumb111.png?imgmax=800" width="364" height="182"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When the step through reach the following line, it will enter the “get” code:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-2pf5SzNgMSI/ThpV869vnUI/AAAAAAAADHA/qPr7iuNS97I/s1600-h/image38.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-E3pJVpR4N2k/ThpV-P6NANI/AAAAAAAADHE/QzHmqwsXo6Q/image_thumb19.png?imgmax=800" width="484" height="212"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-03SvGXWaGdM/ThpXnqygdzI/AAAAAAAADHI/WspKcY5-1mQ/s1600-h/image37.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-199eygr4TWU/ThpXosmddCI/AAAAAAAADHM/2iYqxGUR86c/image_thumb181.png?imgmax=800" width="484" height="240"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Similarly, for “rect.Height”, it will jump to Height property “get” code.&lt;/p&gt; &lt;p&gt;So far there is no checking of the validity of value in the “get” code for these Properties. There is a short cut way to define Properties that do not need to check its private corresponding variables (Width with width, Height with height):&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ywRZhKH5RKA/ThpXpnmkLbI/AAAAAAAADHQ/vdlmx11aGJM/s1600-h/image42.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-nxMtWKlIr0c/ThpXrfDLj5I/AAAAAAAADHU/oCDZTn9LbB0/image_thumb211.png?imgmax=800" width="484" height="332"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We will undo and revert to the full version and add validity check:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-YpHI3BiF9mE/Thpb8yElbZI/AAAAAAAADHY/TLyIikqCllw/s1600-h/image46.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Oi1rDS3lTKw/Thpb-FxoRDI/AAAAAAAADHc/FtO_SWBBT2E/image_thumb231.png?imgmax=800" width="484" height="304"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We may also add checking into the “get” code to do processing before returning the result.&lt;/p&gt; &lt;p&gt;As an exercise, try it yourself to define two more Properties – Area and Perimeter (both with no “set” code, only “get” code).&amp;nbsp; Implement the logic to make use of the width and height given above.&amp;nbsp; Use the main() method to test the additional code.&lt;/p&gt; &lt;h3&gt;Methods&lt;/h3&gt; &lt;p&gt;In a class, on top of Fields and Properties, we may also define Methods.&lt;/p&gt; &lt;p&gt;We may define private methods to be used internally.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-MYKVxvOAPxA/Thusz7r2AyI/AAAAAAAADH0/jz6lkOavY14/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-ciEhDCr-Lts/Thus1idjVJI/AAAAAAAADH4/du6T92UHBxg/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="176"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Then modify the Properties to call the method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-O9Xn4B_w_Y0/Thus22xP1KI/AAAAAAAADH8/RgvfmqGC0YU/s1600-h/image%25255B14%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-YHteLxoZoJA/Thus4mc4BQI/AAAAAAAADIA/tGIBUvV8HSw/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="280"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-fsxvLMVPMxM/Thus7z0X1tI/AAAAAAAADIE/ayeHDEFuClQ/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-H3XfUpvEdLg/Thus9XewVjI/AAAAAAAADII/Nz0zBgzWYBE/image_thumb%25255B6%25255D.png?imgmax=800" width="484" height="220"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The Area and Perimeter properties no longer need to perform the calculation.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-SbDUyoiGihw/Thus-W-42GI/AAAAAAAADIM/yIYi1kIAd3g/s1600-h/image%25255B16%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-3auI4JJB--k/Thus_ZsQGDI/AAAAAAAADIQ/EtieElMwaJw/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="252"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We may also define public methods to be used by external:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-b4wo6EM7FUQ/ThutDJ15FHI/AAAAAAAADIU/AflT3Gsv8zk/s1600-h/image%25255B20%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-VBGDUIHGevs/ThutEU9idgI/AAAAAAAADIY/haxFcBaANB0/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="138"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And test the method in the main() method:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-0JQSKfDXVDc/ThutF8THgnI/AAAAAAAADIc/PKB71qWIGZE/s1600-h/image%25255B24%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-4D1ZUSCF9DU/ThutHR-tNDI/AAAAAAAADIg/7BVZtsj0FM4/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="336"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We may also have a few methods with the same name and return type, but take in different parameters – this is called Method Overloading and it is covered in an earlier blog (&lt;a href="http://mpgddspf.blogspot.com/2011/05/methods-4-overloading-optional.html"&gt;Methods: Overloading, optional parameter &amp;amp; default value and named parameter&lt;/a&gt;) &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-8103300287072618392?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/36fVlt1BZvg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/8103300287072618392/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/object-oriented-programming-oop.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8103300287072618392?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8103300287072618392?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/36fVlt1BZvg/object-oriented-programming-oop.html" title="Object Oriented Programming (OOP)" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-8B3gkANNHXU/ThpQnzTPKnI/AAAAAAAADEE/o_DXnEyBhe0/s72-c/image_thumb27.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/object-oriented-programming-oop.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUGSX49fyp7ImA9WhZaGE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-7080584780333946662</id><published>2011-07-04T20:23:00.001-07:00</published><updated>2011-07-04T20:23:48.067-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-04T20:23:48.067-07:00</app:edited><title>Makeup lessons</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YuLPl43vDY30_1Ah-kSCsHv3axM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YuLPl43vDY30_1Ah-kSCsHv3axM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YuLPl43vDY30_1Ah-kSCsHv3axM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YuLPl43vDY30_1Ah-kSCsHv3axM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Going through the following material:&lt;/p&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn02.html"&gt;Learn C# Programming Tutorial Lesson 2 - Variables and Constants&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn03.html"&gt;Learn C# Programming Tutorial Lesson 3 - Decisions&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn04.html"&gt;Learn C# Programming Tutorial Lesson 4 - Loops&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn05.html"&gt;Learn C# Programming Tutorial Lesson 5 - Arrays&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn06.html"&gt;Learn C# Programming Tutorial Lesson 6 - Methods&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.learn-programming.za.net/programming_cs_learn07.html"&gt;Learn C# Programming Tutorial Lesson 7 - Working with Strings&lt;/a&gt;&lt;/li&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-7080584780333946662?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/HR7z_LPPTbI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/7080584780333946662/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/makeup-lessons.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7080584780333946662?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7080584780333946662?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/HR7z_LPPTbI/makeup-lessons.html" title="Makeup lessons" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/makeup-lessons.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUEMQX88fCp7ImA9WhZaGE8.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-8722715236986833099</id><published>2011-07-04T16:54:00.001-07:00</published><updated>2011-07-04T16:54:40.174-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-04T16:54:40.174-07:00</app:edited><title>Timetable from Jul to Sep 2011</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vk5i9iAAMR-CQ9LmBrt7ByBUF1A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vk5i9iAAMR-CQ9LmBrt7ByBUF1A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vk5i9iAAMR-CQ9LmBrt7ByBUF1A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vk5i9iAAMR-CQ9LmBrt7ByBUF1A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-awTyVMfjXiU/ThJSvDdFmzI/AAAAAAAADDo/I4oGqnu9lmw/s1600-h/image%25255B6%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-MuitbGzpsGk/ThJSv2jyfxI/AAAAAAAADDs/t1MZed3i_AE/image_thumb%25255B4%25255D.png?imgmax=800" width="484" height="296"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-8722715236986833099?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/Rgxrute4k2c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/8722715236986833099/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/07/timetable-from-jul-to-sep-2011.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8722715236986833099?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/8722715236986833099?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/Rgxrute4k2c/timetable-from-jul-to-sep-2011.html" title="Timetable from Jul to Sep 2011" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-MuitbGzpsGk/ThJSv2jyfxI/AAAAAAAADDs/t1MZed3i_AE/s72-c/image_thumb%25255B4%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/07/timetable-from-jul-to-sep-2011.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYER38_cCp7ImA9WhZUFk4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-1915596601753637839</id><published>2011-06-09T08:08:00.001-07:00</published><updated>2011-06-09T08:08:26.148-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-09T08:08:26.148-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="block" /><category scheme="http://www.blogger.com/atom/ns#" term="ball" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="list" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="arrays" /><category scheme="http://www.blogger.com/atom/ns#" term="paddle" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Paddle, ball and blocks</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TCSIyTW-UzsimcJkY2Lt8cTluJg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TCSIyTW-UzsimcJkY2Lt8cTluJg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TCSIyTW-UzsimcJkY2Lt8cTluJg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TCSIyTW-UzsimcJkY2Lt8cTluJg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This tutorial is built on: &lt;a href="http://mpgddspf.blogspot.com/2011/06/paddle-and-ball.html"&gt;Ball and Paddle&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Copy the project into a new project in Windows File Explorer. &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;Steps listed here&lt;/a&gt;. Rename the folder, solution and project name to: WinFormsGraphics9PaddleBallBlocks&lt;/p&gt; &lt;p&gt;Add new class level variables for the blocks:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Array to store the blocks location: Point[]&lt;/li&gt; &lt;li&gt;Size for the blocks – just one will do, as we assume all the blocks are of the same size&lt;/li&gt; &lt;li&gt;List of rectangles for the blocks – we could use ArrayList as well since these two can be use to add and remove items flexibly.&amp;nbsp; But List is recommended because it is TYPE-safe (meaning you can only put in one type of object – for this case, only Rectangle – as indicated in the &amp;lt; … &amp;gt;)&amp;nbsp; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-N-SgrfUkUcE/TfDgxz7HncI/AAAAAAAADCQ/Sm-ee1e3lGw/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-D_FoKkpjAvk/TfDg0HKRWqI/AAAAAAAADCU/4Vlmvcci6m0/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="292"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Modify Form1_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Define the blocks size&lt;/li&gt; &lt;li&gt;Calculate the number of blocks possible, then subtract &lt;strong&gt;2&lt;/strong&gt; to give more space on both size.&amp;nbsp; If you want more space, just subtract more&lt;/li&gt; &lt;li&gt;Calculate the offset on both sides&lt;/li&gt;&lt;/ul&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Y0bitg99h4I/TfDg3gfkEVI/AAAAAAAADCY/TUbOpYATlh8/s1600-h/image%25255B20%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-9DDVlzkfmyk/TfDg57CESfI/AAAAAAAADCc/t6yZktw_jUo/image_thumb%25255B10%25255D.png?imgmax=800" width="364" height="254"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt; &lt;li&gt;Declare and assign values for the blocks location and rects&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-yBeDuLG-WQ8/TfDg8AaXxVI/AAAAAAAADCg/KkKeVV44yKU/s1600-h/image%25255B14%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-MKPGcJYpQDM/TfDg-QFTceI/AAAAAAAADCk/KNstdHOvaJI/image_thumb%25255B6%25255D.png?imgmax=800" width="484" height="322"&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/-S4A2nv0LStg/TfDg_5PQZkI/AAAAAAAADCo/w9iLonfubAs/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-87BJ4cwBX2U/TfDhCs5Rj0I/AAAAAAAADCs/PXxP5K1exLE/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="302"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;Modify timer1_Tick() – to draw the blocks rects by using foreach loop:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-bYompBtpl5I/TfDhETw-i7I/AAAAAAAADCw/Ap_kXb5U8h8/s1600-h/image%25255B27%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-YMiQNIuK8DQ/TfDhGzkXWMI/AAAAAAAADC0/SqOdtj0erPQ/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="392"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-k3J4VKmCmGc/TfDhTHsh3LI/AAAAAAAADC4/S1hTrPwRGsQ/s1600-h/image%25255B28%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Wx31NSWbJQI/TfDhXlcztLI/AAAAAAAADC8/yL8gTIH9qWI/image_thumb%25255B14%25255D.png?imgmax=800" width="484" height="408"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build and execute – to check if the blocks are drawn correctly:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-hWZMfr8onl0/TfDhZsvhuII/AAAAAAAADDA/oL3ZJdAhrlw/s1600-h/image%25255B32%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-8fxGGWw5nsE/TfDhbZ4miYI/AAAAAAAADDE/SFiS8Q4fXbU/image_thumb%25255B16%25255D.png?imgmax=800" width="304" height="478"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Finally, modify timer1_Tick() to add the collision processing:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Use reverse looping (from the back to the front) and check if there is any collision between the ball and the blocks.&amp;nbsp; When there is collision, remove the block collided. The List automatically renumber the blocks after one block is removed.&amp;nbsp; Using reverse looping will not be affected after the renumbering.&amp;nbsp; &lt;/li&gt; &lt;li&gt;Check for end of game when all blocks are removed (Count == 0)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-35pdBqOEVkI/TfDhfUNytNI/AAAAAAAADDI/-V3vP0OX9to/s1600-h/image%25255B36%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-HzAvPSS4PoA/TfDhhHixZoI/AAAAAAAADDM/22JUJj0H54M/image_thumb%25255B17%25255D.png?imgmax=800" width="484" height="392"&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/-OuStPjK9S8Y/TfDhiOvzN6I/AAAAAAAADDQ/PvO3nrX4_rU/s1600-h/image%25255B43%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-5e8n-fmPsUM/TfDh0cnU80I/AAAAAAAADDU/OwBXGHrpV8k/image_thumb%25255B20%25255D.png?imgmax=800" width="484" height="362"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-uaPxsHX2MIA/TfDh2qfLNUI/AAAAAAAADDY/AzSOW99fDjw/s1600-h/image%25255B44%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-K1AfcefnX6s/TfDh3lWi6wI/AAAAAAAADDc/DKlDZJTEyDA/image_thumb%25255B21%25255D.png?imgmax=800" width="484" height="340"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-CcoH3cHl2kY/TfDh4rSfc2I/AAAAAAAADDg/r9xaIe65pB4/s1600-h/image%25255B48%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-nTnWV73kYVI/TfDh6JcZuYI/AAAAAAAADDk/wV2PDZcnEic/image_thumb%25255B23%25255D.png?imgmax=800" width="304" height="478"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That is all for now on graphics related games.&amp;nbsp; We shall be moving onto classes and objects, before we return to use the new concepts on simple games.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-1915596601753637839?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/OHW4kTkgcGw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/1915596601753637839/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/paddle-ball-and-blocks.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1915596601753637839?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1915596601753637839?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/OHW4kTkgcGw/paddle-ball-and-blocks.html" title="Paddle, ball and blocks" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-D_FoKkpjAvk/TfDg0HKRWqI/AAAAAAAADCU/4Vlmvcci6m0/s72-c/image_thumb%25255B3%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/paddle-ball-and-blocks.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04CRHo7eSp7ImA9WhZUFU4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-6958642851113952656</id><published>2011-06-08T04:15:00.001-07:00</published><updated>2011-06-08T04:19:25.401-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-08T04:19:25.401-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="dog" /><category scheme="http://www.blogger.com/atom/ns#" term="cat" /><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="collision" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Mouse, Cat and Dogs</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PTUDQZrbj38iqbHKFfozRBqrd8E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PTUDQZrbj38iqbHKFfozRBqrd8E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PTUDQZrbj38iqbHKFfozRBqrd8E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PTUDQZrbj38iqbHKFfozRBqrd8E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This tutorial is built on the previous one: &lt;a href="http://mpgddspf.blogspot.com/2011/06/ball-and-big-square-paddle.html"&gt;Ball and Big Square Paddle&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Copy the project into a new project in Windows File Explorer. &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;Steps listed here&lt;/a&gt;. Rename the folder, solution and project name to: WinFormsGraphics8MouseCatDogs&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ndtg0XuQ-w0/Te9Y4Po1k-I/AAAAAAAAC_g/xqLhyrzIlzQ/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-v7SfBCDmh2Q/Te9Y5XWeldI/AAAAAAAAC_k/eHSUdmhgH7Y/image_thumb%25255B1%25255D.png?imgmax=800" width="364" height="190"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this tutorial, we shall convert the ball into a mouse and the square paddle into a cat.&amp;nbsp; Then we will change the processing for collision between the cat and mouse, instead of bouncing off, the mouse will be transported to another location.&lt;/p&gt; &lt;h3&gt;Rename ball to mouse and paddle to cat&lt;/h3&gt; &lt;p&gt;In Form1.cs, move the cursor to the top of the page. Menu – Edit &amp;gt; Find and Replace &amp;gt; Quick Replace&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-VX1TrIkyNBY/Te9Y6o4cZtI/AAAAAAAAC_o/qyW6-0Jho0o/s1600-h/image%25255B16%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-B2a8QXtIV04/Te9Y7gkIwRI/AAAAAAAAC_s/dE8vJ_U9Zig/image_thumb%25255B8%25255D.png?imgmax=800" width="484" height="320"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Find what: ball, Replace with: mouse, Then click on “Find Next” follows by “Replace”&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-88PMKXs7Fgk/Te9Y8lUhCII/AAAAAAAAC_w/Vs7l8p2nHaU/s1600-h/image%25255B27%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Exd6tHqt3H4/Te9Y90rIo_I/AAAAAAAAC_0/THuka9K07yA/image_thumb%25255B13%25255D.png?imgmax=800" width="304" height="395"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Click on “Replace” until all variable names or comments are replaced.&lt;/p&gt; &lt;p&gt;Do &lt;strong&gt;&lt;u&gt;NOT&lt;/u&gt;&lt;/strong&gt; change the namespace:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ssGo42Xe9-g/Te9Y-jUrKEI/AAAAAAAAC_4/v5JFF1jK2HA/s1600-h/image%25255B30%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-okDXYRACHQE/Te9Y_kha0iI/AAAAAAAAC_8/6Kagh7OIfqc/image_thumb%25255B16%25255D.png?imgmax=800" width="364" height="160"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Repeat the above steps to replace “paddle” by “cat”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-_dk6kEdRWI0/Te9ZAZTsJjI/AAAAAAAADAA/ndDoP395W84/s1600-h/image%25255B28%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-RKirUbYnVA0/Te9ZBd81Z4I/AAAAAAAADAE/cxuerbEEHHQ/image_thumb%25255B14%25255D.png?imgmax=800" width="304" height="397"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute to confirm that everything runs as before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-yI71eVdC-2c/Te9ZCZSDmII/AAAAAAAADAI/dS8U1bI_8_k/s1600-h/image%25255B37%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-0YdbS4HRJ8I/Te9ZDW55yoI/AAAAAAAADAM/AIxNV37kiN4/image_thumb%25255B19%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Add Images&lt;/h3&gt; &lt;p&gt;Google for suitable images of mouse, cat and dog.&amp;nbsp; Copy these images into the project.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-6UGyR458AAw/Te9ZEC7kqII/AAAAAAAADAQ/P7T6eS5JdYI/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-2AtJWoMFoRU/Te9ZFJ8-meI/AAAAAAAADAU/l6EALKZUkWU/image_thumb%25255B3%25255D.png?imgmax=800" width="364" height="256"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the “Copy to Output Directory” property of these images to “Copy Always”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-BtgoMS4udPs/Te9ZGIbDHdI/AAAAAAAADAY/GAtUL4raEHY/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-6voeT7v61og/Te9ZHTApZOI/AAAAAAAADAc/eglO3uHGC5U/image_thumb%25255B5%25255D.png?imgmax=800" width="364" height="202"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-EUdGZZjLv5g/Te9ZIG_g9aI/AAAAAAAADAg/MgGWgR-XYxA/s1600-h/image%25255B65%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-rQYb6x86kAc/Te9ZJKxFN7I/AAAAAAAADAk/NrUmx--sbOg/image_thumb%25255B32%25255D.png?imgmax=800" width="364" height="206"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-mt7t0EMbMak/Te9ZJ4XPgCI/AAAAAAAADAo/PExJtrgdlFs/s1600-h/image%25255B69%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-mFeA0inhk5c/Te9ZLFmt6hI/AAAAAAAADAs/7Cgwz2za9Bs/image_thumb%25255B34%25255D.png?imgmax=800" width="364" height="234"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add new class level variables:&lt;/p&gt;         &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-I8k93eAd0F0/Te9ZL-WdFeI/AAAAAAAADAw/cwmRq9HiFTA/s1600-h/image%25255B41%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-zRjKRCltyz0/Te9ZNMltIXI/AAAAAAAADA0/C-LuchQDsx0/image_thumb%25255B21%25255D.png?imgmax=800" width="484" height="324"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify Form1_Load() to load the images of mouse and cat:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-cKbHke4cz58/Te9ZNxolL8I/AAAAAAAADA4/Cobe0BxF5rA/s1600-h/image%25255B45%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-sJF03NpI0aA/Te9ZPcZiiYI/AAAAAAAADA8/qyf2fAi9RU4/image_thumb%25255B23%25255D.png?imgmax=800" width="484" height="304"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;*** You need to use the name of your images instead of “mouse.jpg” and “cat.jpg” ***&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-yy_MQx1OoaU/Te9ZQnkF-zI/AAAAAAAADBA/JBYkgvN_vu0/s1600-h/image%25255B56%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-y0atm_rsQCU/Te9ZRtZ86KI/AAAAAAAADBE/21xRf2ZSjyc/image_thumb%25255B27%25255D.png?imgmax=800" width="364" height="205"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-RGHy7o2HxRw/Te9ZSQXdOTI/AAAAAAAADBI/AK2JsxRiCjk/s1600-h/image%25255B57%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-gbVbUtdRDWs/Te9ZTiwDzcI/AAAAAAAADBM/PZF__Da7ldk/image_thumb%25255B28%25255D.png?imgmax=800" width="364" height="204"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;Modify timer1_Tick() to draw the images:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-x69CA6J8pp0/Te9ZUb4oi4I/AAAAAAAADBQ/bjRDxYmef1E/s1600-h/image%25255B61%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-FvwPi9jQLds/Te9ZVx6pD4I/AAAAAAAADBU/rA7bDHT-bGM/image_thumb%25255B30%25255D.png?imgmax=800" width="484" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-N4PRHvln07o/Te9ZXhWjTvI/AAAAAAAADBY/NW3H4IAcDuM/s1600-h/image%25255B73%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-Uj9BTRm0TSU/Te9Za8heRAI/AAAAAAAADBc/EMA8F2RyKIo/image_thumb%25255B36%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;h3&gt;Transport the mouse&lt;/h3&gt; &lt;p&gt;Now we shall change the collision processing to transport the mouse to another location.&amp;nbsp; We shall use a simple logic here.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Pr0QeHocBYM/Te9ZcMOf2LI/AAAAAAAADBg/BTkhhGrMQyQ/s1600-h/image%25255B76%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-aPhNi5B3__M/Te9ZlOofTDI/AAAAAAAADBk/9-pWmwz8f1A/image_thumb%25255B37%25255D.png?imgmax=800" width="244" height="225"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Remove the existing processing for collision between mouse and cat&lt;/li&gt; &lt;li&gt;Add new processing&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-bSf1AhB2qBU/Te9ZmcVgajI/AAAAAAAADBo/xsvnwyXGShE/s1600-h/image%25255B92%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-O5ZEMozVomk/Te9ZngnGs6I/AAAAAAAADBs/yJV53rSJhOs/image_thumb%25255B43%25255D.png?imgmax=800" width="484" height="290"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-1y1j2M7ehtk/Te9ZpLwhpzI/AAAAAAAADBw/L015-uH3yOQ/s1600-h/image%25255B93%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-N3uLbR2DFpk/Te9Zrqxjt4I/AAAAAAAADB0/XJebeZMv1fg/image_thumb%25255B44%25255D.png?imgmax=800" width="484" height="388"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-uVU1BL9w-rU/Te9ZtJgz2YI/AAAAAAAADB4/RhmvVS9L5lc/s1600-h/image%25255B94%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-_n4C4sJ7d4o/Te9ZukNNvPI/AAAAAAAADB8/qEff4LrZyjs/image_thumb%25255B45%25255D.png?imgmax=800" width="484" height="328"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-b_8U6BlA-D8/Te9ZweRiqZI/AAAAAAAADCA/3P3FjBMXTug/s1600-h/image%25255B95%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-s6jZ8nxh734/Te9ZyDiru0I/AAAAAAAADCE/noHRmApMCv4/image_thumb%25255B46%25255D.png?imgmax=800" width="484" height="288"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-ldLiE33XBco/Te9Z0H3NZHI/AAAAAAAADCI/bISsHLvhLNw/s1600-h/image%25255B99%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-I36jrBiO6Us/Te9Z1B3oGXI/AAAAAAAADCM/QfgMUzmm5G8/image_thumb%25255B48%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;What we provided here is a very simple logic and it has a critical loop hole (when the cat catches the mouse very near the centre of the form).&amp;nbsp; We shall leave it to the reader to use a better logic to transport the mouse.&lt;/p&gt; &lt;p&gt;As an exercise, we shall leave it to the reader to add score and time limit.&amp;nbsp; (refer to the &lt;a href="http://mpgddspf.blogspot.com/2011/06/hit-mouse-game.html"&gt;Hit the Mouse tutorial&lt;/a&gt;)&lt;/p&gt; &lt;p&gt;We shall also leave it to the reader to add two dogs to move (randomly) in the space.&amp;nbsp; Once done, add AI into one of the dog to move towards the cat.&amp;nbsp; &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-6958642851113952656?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/umM_g-EaqBE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/6958642851113952656/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/mouse-cat-and-dogs.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/6958642851113952656?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/6958642851113952656?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/umM_g-EaqBE/mouse-cat-and-dogs.html" title="Mouse, Cat and Dogs" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-v7SfBCDmh2Q/Te9Y5XWeldI/AAAAAAAAC_k/eHSUdmhgH7Y/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/mouse-cat-and-dogs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYDSXwyfCp7ImA9WhZUFEg.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5609283576666111180</id><published>2011-06-07T07:16:00.001-07:00</published><updated>2011-06-07T07:16:18.294-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-07T07:16:18.294-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="bounding" /><category scheme="http://www.blogger.com/atom/ns#" term="collision" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Ball and Big Square Paddle</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sfPQwgesq0CiMcfJws75hzMYU80/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sfPQwgesq0CiMcfJws75hzMYU80/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sfPQwgesq0CiMcfJws75hzMYU80/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sfPQwgesq0CiMcfJws75hzMYU80/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This tutorial is built on the previous one: &lt;a href="http://mpgddspf.blogspot.com/2011/06/paddle-and-ball.html"&gt;Paddle and Ball&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Copy the project into a new project in Windows File Explorer. &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;Steps listed here&lt;/a&gt;. Rename the folder, solution and project name to: WinFormsGraphics7PaddleBall&lt;font color="#ff0000"&gt;2&lt;/font&gt;.&lt;/p&gt; &lt;p&gt;In the previous tutorial, the paddle is short and wide, hence we use only one engulfing bounding rectangle to detect collision.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-YJHVU_vzhJQ/Te4xk6ehCUI/AAAAAAAAC94/kOkbBKYMJoo/s1600-h/image%25255B6%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-7qcjNVgO9B0/Te4xtOZQ78I/AAAAAAAAC98/LVBwMgtysQs/image_thumb%25255B2%25255D.png?imgmax=800" width="354" height="78"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-7eufxUK1-V8/Te4x5PFzypI/AAAAAAAAC-A/0S6bFcMklUo/s1600-h/image%25255B2%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-QCCDaJYXB_M/Te4x7TmWd3I/AAAAAAAAC-E/GpioL1oW4W8/image_thumb.png?imgmax=800" width="244" height="69"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this tutorial, we will change the paddle to be a square with 4 bounding rectangles at its sides:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-EYIYS5D5qR4/Te4x89LQ5DI/AAAAAAAAC-I/fClMVQPATq8/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-zmkia3ggRVM/Te4x-hdUzLI/AAAAAAAAC-M/b9PFcoiGADY/image_thumb%25255B3%25255D.png?imgmax=800" width="244" height="241"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify the class level variables:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add paddleSpeedY since now the square paddle is able to move in Y direction.&amp;nbsp; Set the initial default value to zero (stationary)&lt;/li&gt; &lt;li&gt;Rename the original bounding Location, Size and Rect to bounding Top Location, Size and Rect&lt;/li&gt; &lt;li&gt;Add bounding Bottom, Left and Right Location Size and Rect &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-AHrBWcyG_H8/Te4yBOGbksI/AAAAAAAAC-Q/GLgLRFjjMR4/s1600-h/image%25255B13%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-0BpJ68HcBbw/Te4yFMYh2GI/AAAAAAAAC-U/csMTal3G-gE/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="330"&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Modify the Form1_Load():&lt;/p&gt; &lt;ul&gt; &lt;ul&gt; &lt;li&gt;Rename the original bounding Location, Size and Rect to bounding Top Location, Size and Rect&lt;/li&gt; &lt;li&gt;Add bounding Bottom, Left and Right Location Size and Rect to something like the picture below:&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-JyVnms1G03U/Te4yGsyO4JI/AAAAAAAAC-Y/di6Fgy1KmTg/s1600-h/image%25255B26%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-mRgIO39jiuw/Te4yIy9NZpI/AAAAAAAAC-c/uGywR6wSZRw/image_thumb%25255B11%25255D.png?imgmax=800" width="244" height="241"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt; &lt;ul&gt;&lt;!--EndFragment--&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-TTm-mA-rebU/Te4yKprxsqI/AAAAAAAAC-g/7Pg1p4i7b_o/s1600-h/image%25255B20%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-l1QPakqSsmE/Te4yM2i_icI/AAAAAAAAC-k/YE3X5XRUsV4/image_thumb%25255B8%25255D.png?imgmax=800" width="484" height="226"&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/-66nK7JUwtGY/Te4yOpwfTHI/AAAAAAAAC-o/3At76kvGbPM/s1600-h/image%25255B22%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-3ign7jgqppw/Te4yQp7jRQI/AAAAAAAAC-s/D820eLW5XT4/image_thumb%25255B10%25255D.png?imgmax=800" width="484" height="338"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;Modify the Form1_KeyDown() and KeyUp():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add Keys.W and Keys.S processing to change the paddleSpeedY&lt;/li&gt; &lt;li&gt;When Key is up, set the paddleSpeedY to zero&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-SB9MEI9EKnw/Te4yR3sqiLI/AAAAAAAAC-w/7bX0r2GJoCw/s1600-h/image%25255B30%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Np7dTicFAbU/Te4yU5V8RZI/AAAAAAAAC-0/7rBRBo_vbmo/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="412"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Modify the collision between ball and bounding rect, to check all 4 bounding rects.&amp;nbsp; Different from the earlier flat paddle that does not get reflected, this time, both the ball and the square paddle will reflect each other&lt;/li&gt; &lt;li&gt;Moves all 4 bounding rects&lt;/li&gt; &lt;li&gt;For debugging purpose, draw all 4 bounding rects&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-iWOnE5cFdec/Te4yWWSAcpI/AAAAAAAAC-4/PoC-_t3udRA/s1600-h/image%25255B43%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-5dHigzw-NNI/Te4yZTQ1xqI/AAAAAAAAC-8/RLvyaIv2Lww/image_thumb%25255B18%25255D.png?imgmax=800" width="484" height="272"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-Yz5Xidnc1Gg/Te4ybPhAXsI/AAAAAAAAC_A/0k4EwYO6Ftw/s1600-h/image%25255B44%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Zc36eg3We-8/Te4yeG_HpuI/AAAAAAAAC_E/pufT_GnsWy8/image_thumb%25255B19%25255D.png?imgmax=800" width="484" height="398"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/-DwpOZzfQ5Nk/Te4yfxA46cI/AAAAAAAAC_I/JGqmkqLzqNU/s1600-h/image%25255B45%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-dEtfMS1rDbQ/Te4yinzOEpI/AAAAAAAAC_M/1GNGW9pDx8w/image_thumb%25255B20%25255D.png?imgmax=800" width="484" height="210"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-HeAjr-0N8Uo/Te4ylehp1gI/AAAAAAAAC_Q/inJhWv-k4Y4/s1600-h/image%25255B46%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-sVcI0DqJRII/Te4ynqB-BaI/AAAAAAAAC_U/2QO-MtoySKI/image_thumb%25255B21%25255D.png?imgmax=800" width="484" height="414"&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-IE3eitMPjKU/Te4ypW4tQxI/AAAAAAAAC_Y/C9gm2J86P0Q/s1600-h/image%25255B50%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Ad6TqEzlQ4Y/Te4yrkWO6yI/AAAAAAAAC_c/r4xXAkmygX0/image_thumb%25255B23%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Happy that it works as it should be?&amp;nbsp; We shall move to another tutorial by changing the ball to a mouse and the square paddle to a cat, for a game of cat catches mouse.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5609283576666111180?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/OglOEAVDMOM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5609283576666111180/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/ball-and-big-square-paddle.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5609283576666111180?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5609283576666111180?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/OglOEAVDMOM/ball-and-big-square-paddle.html" title="Ball and Big Square Paddle" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-7qcjNVgO9B0/Te4xtOZQ78I/AAAAAAAAC98/LVBwMgtysQs/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/ball-and-big-square-paddle.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8GRHgzeSp7ImA9WhZUFE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5231435495489124111</id><published>2011-06-07T02:27:00.001-07:00</published><updated>2011-06-07T02:27:05.681-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-07T02:27:05.681-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ball" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="paddle" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><category scheme="http://www.blogger.com/atom/ns#" term="beginner" /><title>Paddle and Ball</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TLkJUtDlVoGdBXB10LyjOTZ5ozU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TLkJUtDlVoGdBXB10LyjOTZ5ozU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TLkJUtDlVoGdBXB10LyjOTZ5ozU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TLkJUtDlVoGdBXB10LyjOTZ5ozU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This tutorial is built on the previous tutorial: &lt;a href="http://mpgddspf.blogspot.com/2011/06/bouncing-ball.html"&gt;Bouncing ball&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Copy the project into a new project in Windows File Explorer.&amp;nbsp; &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;Steps listed here&lt;/a&gt;.&amp;nbsp; Rename the folder, solution and project name to: WinFormsGraphics7PaddleBall.&lt;/p&gt; &lt;p&gt;Change the default interval for the timer1 to &lt;font color="#ff0000"&gt;5 ms&lt;/font&gt;:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-CwjpfCik1TQ/Te3ukF-tzsI/AAAAAAAAC74/OTV-KVT0cvQ/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-YAb6YmJ7fdM/Te3uk0ArykI/AAAAAAAAC78/-1vDhpKFWvI/image_thumb%25255B1%25255D.png?imgmax=800" width="364" height="248"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Draws Paddle and Bounding Rectangle&lt;/h3&gt; &lt;p&gt;Modify the class level variables:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add paddleSpeedX (since paddle only move in horizontal direction, no need Speed in Y direction).&amp;nbsp; Set it to default zero for the start to be stationary&lt;/li&gt; &lt;li&gt;Add paddle Location, Size and Rect&lt;/li&gt; &lt;li&gt;Add bounding rectangle Location, Size and Rect.&amp;nbsp; This bounding rectangle is to be used to check collision around the boundary of the paddle to avoid scenario whereby the speed is too fast and the ball get into the paddle before the collision is detected.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-HURjGblJ08c/Te3uloXqZRI/AAAAAAAAC8A/MCi4zhY6ikI/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-UaHyDN2AmHk/Te3umFypBsI/AAAAAAAAC8E/8yX-NL_qTaE/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="224"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify the Form1_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Define the paddle Rect using its Location and Size&lt;/li&gt; &lt;li&gt;Define the bounding Rect using its Location and Size.&amp;nbsp; Notice the calculation of the location and size to based on that of the paddle so that this bounding rect surround the paddle&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-qXDnPPtKNNE/Te3um-W0waI/AAAAAAAAC8I/Rr2RZK_uAiI/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-lK1tsE7Y6P0/Te3unzGRPLI/AAAAAAAAC8M/HcZ0uwh3GiM/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="380"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Modify the timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Draw the paddle rect and the bounding rect&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-t5rXwKlAOT0/Te3uors3t0I/AAAAAAAAC8Q/cbLYebOUTWg/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-idAMG_WWfb4/Te3upMJdrNI/AAAAAAAAC8U/AahOyQcieso/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="354"&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/-xKsfWFPwJqY/Te3upwPTu3I/AAAAAAAAC8Y/MGjhKUUQcCc/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-r-KOsWtw89o/Te3uqyUjD7I/AAAAAAAAC8c/15VasGFjdlw/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="178"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build and execute – observe the bounding rect surrounding the paddle&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-ldx8s7oHn0c/Te3ur-MzdCI/AAAAAAAAC8g/OhJDRgEUfVg/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-nIHpLjhS4eM/Te3usZgHsnI/AAAAAAAAC8k/s1-115WdqVc/image_thumb%25255B11%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;Moves the Paddle and Bounding Rectangle&lt;/h3&gt; &lt;p&gt;From the Properties Window, create the Form1_KeyDown()&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-LOTJXdWkPpA/Te3utIpc9lI/AAAAAAAAC8o/NgsxOApjALQ/s1600-h/image%25255B34%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-XUD5XmaJT_E/Te3utw_aNNI/AAAAAAAAC8s/jbnLWBHRLlI/image_thumb%25255B16%25255D.png?imgmax=800" width="364" height="218"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;add the following code:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;When user press A: set paddleSpeedX to –2&amp;nbsp; (move to the left)&lt;/li&gt; &lt;li&gt;When user press D: set paddleSpeedX to 2 (move to the right)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-1Mdv9l8ihrI/Te3uuh_cDiI/AAAAAAAAC8w/vDa779AYuV8/s1600-h/image%25255B27%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Y_6vv0BTcaw/Te3uveX4FuI/AAAAAAAAC80/SftihckAFfg/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="214"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If you want the paddle to stop when you leave the keys, add the Form1_KeyUp():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Set the paddleSpeedX to zero (stop moving)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-Cd4MCCSGTlo/Te3uv3EHMFI/AAAAAAAAC84/jiXE-uC1u6o/s1600-h/image%25255B39%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-XCLYzyyIUa4/Te3uwueHdzI/AAAAAAAAC88/rQNuFnltyaY/image_thumb%25255B19%25255D.png?imgmax=800" width="484" height="82"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the Properties Window, remember to set KeyPreview to True:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-65HqOQIj1t0/Te3uxNQSk8I/AAAAAAAAC9A/CzbjphJMDFE/s1600-h/image%25255B35%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-BIYaV8-OnCs/Te3ux2mYM0I/AAAAAAAAC9E/7O8Y-e59ijU/image_thumb%25255B17%25255D.png?imgmax=800" width="364" height="202"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;Modify the timer_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Check collision of paddle with left and right walls and change the direction (by multiplying its speed with –1)&lt;/li&gt; &lt;li&gt;Move the paddle by adding its location with the distance travelled&amp;nbsp; (assume time equals to 1, then distance travelled = speed x time, distance travelled = speed)&lt;/li&gt; &lt;li&gt;Move the bounding rect by the same distance.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-7oqBXnIzZ6M/Te3uynyqJ1I/AAAAAAAAC9I/GpOKf7xVyIc/s1600-h/image%25255B47%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-1Ymuga7jLT0/Te3uzL-v9lI/AAAAAAAAC9M/Od4LaFBQF7g/image_thumb%25255B23%25255D.png?imgmax=800" width="484" height="420"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-VyYLLqAVEA4/Te3uz15-WDI/AAAAAAAAC9Q/AXMYtZObUdo/s1600-h/image%25255B63%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-kIIf3GDpMYE/Te3u0f_vEWI/AAAAAAAAC9U/F6poVALGwVI/image_thumb%25255B31%25255D.png?imgmax=800" width="484" height="344"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – press the A and D keys to move the paddle:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-xb5RnqCin9Y/Te3u1EvqeOI/AAAAAAAAC9Y/QMZbXUaYsUs/s1600-h/image%25255B43%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-3nn_zlM8dzU/Te3u1riMrkI/AAAAAAAAC9c/m-qP5mRoHWE/image_thumb%25255B21%25255D.png?imgmax=800" width="364" height="336"&gt;&lt;/a&gt;&lt;/p&gt;     &lt;h3&gt;Checks Collision between ball and paddle&lt;/h3&gt; &lt;p&gt;Modify the timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Using the IntersectWith() method, check the collision between ball and paddle.&amp;nbsp; Since Paddle has very thin height, we assume that the collision is only from the top of the bottom and change the ballSpeedY for the ball and not the ballSpeedX.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-82kzZ1oWWuk/Te3u2EbFLDI/AAAAAAAAC9g/6mPPA8brYGI/s1600-h/image%25255B70%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-0l4xsuRYfZQ/Te3u220bcYI/AAAAAAAAC9k/UjxiiUUF0S4/image_thumb%25255B34%25255D.png?imgmax=800" width="484" height="410"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-Re25StupzoU/Te3u3jsxmnI/AAAAAAAAC9o/yQBhwIu5kOU/s1600-h/image%25255B71%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-RGsiX7YJUXk/Te3u4rOzNTI/AAAAAAAAC9s/G31y1WvSaKk/image_thumb%25255B35%25255D.png?imgmax=800" width="484" height="412"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build and execute – test out the collision between the ball and the paddle:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-yFqok58YCq8/Te3u5INYUoI/AAAAAAAAC9w/7O5X9yKfpHs/s1600-h/image%25255B75%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-_TXvIIcJ-Lc/Te3u5388O0I/AAAAAAAAC90/dwVMYsL1wM4/image_thumb%25255B37%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That is all for this tutorial.&amp;nbsp; In the next one, we shall change the paddle to a square shape and made changes from one engulfing bounding rect to 4 small bounding rects on its 4 sides.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5231435495489124111?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/rTyyTCNfo5E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5231435495489124111/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/paddle-and-ball.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5231435495489124111?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5231435495489124111?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/rTyyTCNfo5E/paddle-and-ball.html" title="Paddle and Ball" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-YAb6YmJ7fdM/Te3uk0ArykI/AAAAAAAAC78/-1vDhpKFWvI/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/paddle-and-ball.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UASH8yfSp7ImA9WhZUFE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5132869159931336931</id><published>2011-06-07T00:17:00.001-07:00</published><updated>2011-06-07T00:20:49.195-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-07T00:20:49.195-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ide" /><category scheme="http://www.blogger.com/atom/ns#" term="improvement" /><category scheme="http://www.blogger.com/atom/ns#" term="slow" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="vs2010" /><category scheme="http://www.blogger.com/atom/ns#" term="fix" /><title>VS 2010 starts very slowly and need a reset</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vL6wO3BjvJ_h2DLd3pCeqD1vRGU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vL6wO3BjvJ_h2DLd3pCeqD1vRGU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vL6wO3BjvJ_h2DLd3pCeqD1vRGU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vL6wO3BjvJ_h2DLd3pCeqD1vRGU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;After working on many projects in VS2010, if you notice that it takes a long time to open an existing project, try the following steps to reset the user data:&lt;/p&gt; &lt;p&gt;1. Windows &amp;gt; Start &amp;gt; All Program &amp;gt; Microsoft Visual Studio 2010 &amp;gt; Visual Studio Tools: Select Visual Studio Command Prompt&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-J4Xvn0Exonc/Te3Qd_uKj0I/AAAAAAAAC7g/KYzHrc-xoQE/s1600-h/image%25255B6%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-d7n0XFSmqxY/Te3Qe9LvqDI/AAAAAAAAC7k/m-KHLLyW_XA/image_thumb%25255B2%25255D.png?imgmax=800" width="364" height="246"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;2. Type “devenv /resetuserdata” and enter&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-JMGoG5KkF5A/Te3QgFd9gRI/AAAAAAAAC7w/Ae4kFlKygNM/s1600-h/image%25255B8%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-q-tTJmM5Zlc/Te3Qg2-D2BI/AAAAAAAAC70/C1gJzx4oIgU/image_thumb%25255B4%25255D.png?imgmax=800" width="484" height="198"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That’s all.&amp;nbsp; Restart the VS2010 to confirm the speed improvement.&lt;/p&gt; &lt;p&gt;Another blog points to VMware addon to VS2010 as the culprit:&lt;/p&gt; &lt;p&gt;&lt;a title="http://www.devtopics.com/visual-studio-2010-slowdown-vmdebugger-is-the-culprit/" href="http://www.devtopics.com/visual-studio-2010-slowdown-vmdebugger-is-the-culprit/"&gt;http://www.devtopics.com/visual-studio-2010-slowdown-vmdebugger-is-the-culprit/&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5132869159931336931?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/UUQ9HhRA478" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5132869159931336931/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/vs-2010-starts-very-slowly-and-need.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5132869159931336931?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5132869159931336931?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/UUQ9HhRA478/vs-2010-starts-very-slowly-and-need.html" title="VS 2010 starts very slowly and need a reset" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-d7n0XFSmqxY/Te3Qe9LvqDI/AAAAAAAAC7k/m-KHLLyW_XA/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/vs-2010-starts-very-slowly-and-need.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcARno9fSp7ImA9WhZUEEU.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-1014035699989177454</id><published>2011-06-02T22:47:00.001-07:00</published><updated>2011-06-02T22:47:27.465-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T22:47:27.465-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="arrays" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Hit the Mouse–expand with Arrays</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wLpIl6UCDSXWdKe6ByPaBWgibl8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wLpIl6UCDSXWdKe6ByPaBWgibl8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wLpIl6UCDSXWdKe6ByPaBWgibl8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wLpIl6UCDSXWdKe6ByPaBWgibl8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the previous tutorial, we managed to get one mouse on the screen.&amp;nbsp; The game will be more fun if we have more mouse on the screen.&amp;nbsp; Of course we could add the more mice by manually adding code at all places for the one mouse we did earlier.&amp;nbsp; But to be more efficient, we will explore the use of Arrays to expand the game.&lt;/p&gt; &lt;p&gt;First copy the project to another project: WinFormsGraphics6HitTheMouseArray.&amp;nbsp; Refer to earlier blog on &lt;a href="http://mpgddspf.blogspot.com/2011/04/how-to-copy-vs-project.html"&gt;how to copy project&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Move the various code to the top and make the following changes:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Add a new variable to indicate the number of mouse: int numMouse&lt;/li&gt; &lt;li&gt;Create a Point Array: Point[] pt&lt;font color="#ff0000"&gt;s&lt;/font&gt;&amp;nbsp;&amp;nbsp; &amp;lt;= take note of the “s” at the end of the variable name, this is to indicate that this variable consists of a list of items&lt;/li&gt; &lt;li&gt;Create a Rectangle Array: Rectangle[] rect&lt;font color="#ff0000"&gt;s&lt;/font&gt;&lt;/li&gt; &lt;li&gt;Create a random num Array: int[] selectedNum&lt;font color="#ff0000"&gt;s&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-EZvwOPer8co/Teh1KYHKw7I/AAAAAAAAC6g/-gS2tPc7Yx8/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-4hvNImQAZh0/Teh1LGHREAI/AAAAAAAAC6k/t_XtZdKG4LE/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="270"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Update the fromHTM_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Define the Points in the Point Array&lt;/li&gt; &lt;li&gt;Determine the number of mouse from the Points in the above array&lt;/li&gt; &lt;li&gt;Create the Rectangle Array&lt;/li&gt; &lt;li&gt;Define the Rectangles in the Rectangle Array&lt;/li&gt; &lt;li&gt;Create the random number Array&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-SOptEl3uLIg/Teh1MB0BeoI/AAAAAAAAC6o/mCpYhAvtEt4/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-sDhsR4qWsOo/Teh1Mzvp2QI/AAAAAAAAC6s/vN2vZ9ev6IY/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="370"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Update the frmHTM_Paint():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Loop through the number of mouse, check for each random number: if 0, draw the mouse at the particular location; otherwise, draw the rectangle&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-KegeXwx-GlA/Teh1NrYKNWI/AAAAAAAAC6w/9AfjN2B-LhU/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-NiiZj5dj1JU/Teh1Ot5QTII/AAAAAAAAC60/TroSauyYKxQ/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="350"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Update the timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Loop through the number of mouse, generate a new random number for each mouse&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-pUempcriTM4/Teh1PUtd-cI/AAAAAAAAC64/o0SP8a9zvJQ/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-hPBQaK9dQG0/Teh1QOj3zsI/AAAAAAAAC68/2bfALDIK0hg/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="254"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Update the frmHTM_MouseDown():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Loop through the number of mouse, check if the mouse click is within the rectangle and that the particular mouse is drawn on the screen (random number is zero)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-s7lHbMrEiO4/Teh1Qw3aw7I/AAAAAAAAC7A/krY-JP8OOiU/s1600-h/image%25255B22%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-1sWi9UVgOgk/Teh1Rrfd3VI/AAAAAAAAC7E/fBGmbNuSPKo/image_thumb%25255B10%25255D.png?imgmax=800" width="484" height="304"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – click on the mouse to get score.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-xa4cjVYHpEQ/Teh1SQepQDI/AAAAAAAAC7I/q6BtSUKVPeU/s1600-h/image%25255B34%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-a0EvTJJj_gY/Teh1TBzPioI/AAAAAAAAC7M/I_g3stwRxm0/image_thumb%25255B16%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now to add a new mouse, we only need to change one place – by adding a new location for the mouse:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-FZy9eEkeWLQ/Teh1TktQBDI/AAAAAAAAC7Q/YZJHMOy-J2Q/s1600-h/image%25255B29%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-5s45HYoE3sg/Teh1UqDFmAI/AAAAAAAAC7U/Q6CUDZVm1is/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="172"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-D-N_dhk5TSU/Teh1VP4D52I/AAAAAAAAC7Y/8nDY2NUY8x8/s1600-h/image%25255B33%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-URUGQBEcFtM/Teh1WPZdmEI/AAAAAAAAC7c/MULbaqjQcBs/image_thumb%25255B15%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this tutorial, we learn how to use a simple prototype with one mouse and change it to use Arrays so as to scale for expansion to many more mice.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-1014035699989177454?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/lglLDM4Wh6s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/1014035699989177454/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/hit-mouseupgrade-with-arrays.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1014035699989177454?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1014035699989177454?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/lglLDM4Wh6s/hit-mouseupgrade-with-arrays.html" title="Hit the Mouse–expand with Arrays" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-4hvNImQAZh0/Teh1LGHREAI/AAAAAAAAC6k/t_XtZdKG4LE/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/hit-mouseupgrade-with-arrays.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08FQnk4fyp7ImA9WhZUEEs.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-2474606190895633307</id><published>2011-06-02T19:56:00.001-07:00</published><updated>2011-06-02T19:56:53.737-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T19:56:53.737-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Hit the Mouse Game</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BaeZl-ZnKBF4os6bB7uq0xov_t4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BaeZl-ZnKBF4os6bB7uq0xov_t4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BaeZl-ZnKBF4os6bB7uq0xov_t4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BaeZl-ZnKBF4os6bB7uq0xov_t4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is the all time favourite game in Arcade games centre.&amp;nbsp; Mouse coming out of holes at random timing and you score by hitting on it.&lt;/p&gt; &lt;p&gt;Create a new project: WinFormsGraphics6HitTheMouse.&amp;nbsp; Add a timer to the form and name the form as frmHTM.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-7wIM-cC0mjQ/TehNGByPAPI/AAAAAAAAC5U/ziD6cUETevo/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-RpxVhX4yvyo/TehNHzNVLII/AAAAAAAAC5Y/_0kWWPbWXmk/image_thumb%25255B1%25255D.png?imgmax=800" width="364" height="356"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Look for a suitable 50x50 mouse graphics, eg mouse.jpg.&lt;/p&gt; &lt;p&gt;Copy and paste into the project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-mwS7OToOfpU/TehNJsz_15I/AAAAAAAAC5c/0ZSuEHLtYtQ/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-GV9P9-Iftwk/TehNLreEeOI/AAAAAAAAC5g/QLmzg50dZqY/image_thumb%25255B5%25255D.png?imgmax=800" width="364" height="156"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Change the property of the newly added mouse.jpg to “Copy to Output Directory”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-KhJN3n0a3Iw/TehNM-dKTXI/AAAAAAAAC5k/ecNzOetmWrs/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-N3D4wrEgjJM/TehNOl3qnvI/AAAAAAAAC5o/pfOAMyBMOkw/image_thumb%25255B7%25255D.png?imgmax=800" width="364" height="230"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;From the Properties window, add the following methods: frmHTM_Load(), frmHTM_Paint(), timer1_Tick() and frmHTM_MouseDown().&lt;/p&gt; &lt;p&gt;Add the following class level variables:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-lJ52R9AJi-4/TehNPRO_wWI/AAAAAAAAC5s/Pgnwj_RWM3M/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-lcMzHwuZJgo/TehNQjcC5wI/AAAAAAAAC5w/nAlhRh40xKA/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="166"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into frmHTM_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;create a new bitmap with the mouse.jpg&lt;/li&gt; &lt;li&gt;set the location where the mouse will appear&lt;/li&gt; &lt;li&gt;start the timer&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-ER4fJSbutRo/TehNRo6VtcI/AAAAAAAAC50/Od1kRmEvZCI/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-u0UdWxOQWDs/TehNTBAHXFI/AAAAAAAAC54/HzbObOzmqLE/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="138"&gt;&lt;/a&gt;&lt;/p&gt;      &lt;p&gt;Add code into frmHTM_Paint():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;get the surface to draw on&lt;/li&gt; &lt;li&gt;clear the surface to white&lt;/li&gt; &lt;li&gt;draw the score onto the surface&lt;/li&gt; &lt;li&gt;for selectedNum = 0, draw the mouse; otherwise, draw a blank rectangle&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-vXOrpSg6qPc/TehNUV-z4fI/AAAAAAAAC58/C3EaDHPGM04/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-wkSN02kCqeY/TehNV28kH8I/AAAAAAAAC6A/WcRVIr7Qlkg/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="324"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;get a random number from 0 to 4&lt;/li&gt; &lt;li&gt;invalidate to get the form to call the frmHTM_Paint() to redraw itself&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-t80fq1KFufI/TehNWtILRPI/AAAAAAAAC6E/65wolr5L-NM/s1600-h/image%25255B27%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-_ty-QnJBsn0/TehNX2npufI/AAAAAAAAC6I/XIkkUwsjWOM/image_thumb%25255B13%25255D.png?imgmax=800" width="484" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into frmHTM_MouseDown():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;get the mouse location&lt;/li&gt; &lt;li&gt;check that the mouse is within the rectangle and selectedNum is zero (meaning a mouse is drawn on the screen now at that location) =&amp;gt; the mouse has been hit and hence update the score by 1&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-wjaflZa_R_g/TehNZWYtNDI/AAAAAAAAC6M/Tu7oQs-JrQg/s1600-h/image%25255B31%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-u9VBh4Q-fLw/TehNaoJO21I/AAAAAAAAC6Q/rYDWoKEhz_A/image_thumb%25255B15%25255D.png?imgmax=800" width="484" height="234"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – Hit the mouse to see the score updated.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-u4gNbzfW6_4/TehNbilAkSI/AAAAAAAAC6U/s4fAIrbYBOY/s1600-h/image%25255B35%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-pOORDpN-Z7c/TehNc0CJsdI/AAAAAAAAC6Y/MHx48USUFnE/image_thumb%25255B17%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;That is all for now.&amp;nbsp; For the next tutorial, we will improve on this project to use Array and add more mice.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-2474606190895633307?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/tLD8pfVuIQ0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/2474606190895633307/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/hit-mouse-game.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2474606190895633307?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2474606190895633307?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/tLD8pfVuIQ0/hit-mouse-game.html" title="Hit the Mouse Game" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-RpxVhX4yvyo/TehNHzNVLII/AAAAAAAAC5Y/_0kWWPbWXmk/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/hit-mouse-game.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UNR3k5eCp7ImA9WhZUEE8.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-2119497376278144195</id><published>2011-06-02T07:34:00.001-07:00</published><updated>2011-06-02T07:34:56.720-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T07:34:56.720-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="moving" /><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="rectangle" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Rectangle swopping</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sejeAqO5hbxS_RoqIB2Tr5C6PX0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sejeAqO5hbxS_RoqIB2Tr5C6PX0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sejeAqO5hbxS_RoqIB2Tr5C6PX0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sejeAqO5hbxS_RoqIB2Tr5C6PX0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This blog will show you how to use C# graphics to create two rectangles with different colours.&amp;nbsp; A button upon clicked will swop the two rectangles.&amp;nbsp; For extra, we will learn how to draw a rectangle that move with the mouse and how to detect one rectangle inside another.&lt;/p&gt; &lt;p&gt;Create a new project: WinFormsGraphics5RectRect. Add a button. Name the form: frmRectRect and the button: btnSwop.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-QogXCGnIP00/Teee6iyMJDI/AAAAAAAAC3k/xJBckQ_nq-o/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-i0tzY7Dqr6s/Teee829orKI/AAAAAAAAC3o/U0yANKm3KXI/image_thumb%25255B1%25255D.png?imgmax=800" width="364" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add the frmRectRect_Load(), frmRectRect_Paint() and btnSwop_Click().&lt;/p&gt; &lt;p&gt;Add class level variables:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-dF85D4ryW40/Teee-MC3dvI/AAAAAAAAC3s/wxCWhSa7pHY/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-aqoZrKTVyzU/Teee_i8I7GI/AAAAAAAAC3w/K9y3VtyTQ_4/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="204"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Add code into frmRectRect_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;get the width and height of the form surface&lt;/li&gt; &lt;li&gt;set the location, width and height for the two rectangles&lt;/li&gt; &lt;li&gt;set the two pens&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-FIdUBevof8M/TeefBNl9T6I/AAAAAAAAC30/GCuy0pDdda0/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-y6c7q5iZj7I/TeefDZHZqSI/AAAAAAAAC34/M1CSH12ERkc/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="342"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into frmRectRect_Paint():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;draw the two rectangles&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/--5kJukkFJFs/TeefEyylhtI/AAAAAAAAC38/ivVbxmklSFg/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-pW9LOfInwj4/TeefHHlAjmI/AAAAAAAAC4A/0wl3nN8ej9E/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="108"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Add code into btnSwop_Click():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Swop the two rectangles&lt;/li&gt; &lt;li&gt;invalidate to inform the form to call _Paint() method to redraw itself&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-qkZ9y0IroY0/TeefIajQqUI/AAAAAAAAC4E/D83vFs5_d1g/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-jD6u1uQmrys/TeefJuFhYnI/AAAAAAAAC4I/JC-7q0rYZKw/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="188"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – click on the “Swop” button.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-AJJteM-AUqI/TeefK-860RI/AAAAAAAAC4M/jDHDHDiQ7qM/s1600-h/image%25255B26%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-wT3YnTEVJP0/TeefMZP3yFI/AAAAAAAAC4Q/sJGxLucjZe8/image_thumb%25255B12%25255D.png?imgmax=800" width="244" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-A3wcf3-CYHs/TeefNg5HMRI/AAAAAAAAC4U/pffx4kYfzfI/s1600-h/image%25255B29%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-NRG287lwpQo/TeefPF_jtcI/AAAAAAAAC4Y/KlLHLsHhpMo/image_thumb%25255B13%25255D.png?imgmax=800" width="244" height="226"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now for the extra.&lt;/p&gt; &lt;p&gt;Add code into frmRectRect_MouseMove():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;detect the location of the mouse&lt;/li&gt; &lt;li&gt;set the location and size of the rectangle to follow the mouse&lt;/li&gt; &lt;li&gt;set the colour of pen1 based on the condition whether rect1 contains mouseRect, if true, set to penBlack, if false, set to penBlue.&amp;nbsp; The long form will be as follow:&lt;/li&gt;&lt;/ul&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-0yycdAzOCSQ/TeefQHRMkTI/AAAAAAAAC4c/SJpCGCwTSyc/s1600-h/image%25255B37%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Fi2u1TGFaR4/TeefRq5B00I/AAAAAAAAC4g/dVU6wAi-2UY/image_thumb%25255B17%25255D.png?imgmax=800" width="364" height="115"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;ul&gt; &lt;li&gt;set the colour of pen2 based on the condition whether rect2 contains mouseRect, if true, set to penBlack, if false, set to penRed&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-5qw0u31SKa4/TeefTH5NVKI/AAAAAAAAC4k/M7Sy_jXKz6E/s1600-h/image%25255B33%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-YBXvXrH2awk/TeefVDD5yLI/AAAAAAAAC4o/8YFAeypuLMk/image_thumb%25255B15%25255D.png?imgmax=800" width="484" height="294"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Also modify the frmRectRect_Paint():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;draw the mouse rectangle&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-wxByjA8OkPY/TeefXbvPl1I/AAAAAAAAC4s/cm7LXBr0ZRg/s1600-h/image%25255B41%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-DBp6ViI1gX8/TeefY_iz44I/AAAAAAAAC4w/up5mOY9ncAc/image_thumb%25255B19%25255D.png?imgmax=800" width="484" height="150"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-HzP5Vj9qg3Y/TeefaVInSXI/AAAAAAAAC40/XCgS-RU1L6M/s1600-h/image%25255B44%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-gqkXssoAs64/TeefcNdECVI/AAAAAAAAC44/7B558CFg00I/image_thumb%25255B20%25255D.png?imgmax=800" width="244" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-QZW7MO4jtLo/TeefeD-eHYI/AAAAAAAAC48/fBtwiFBWlwM/s1600-h/image%25255B47%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-wJbuNghhu4Y/Teeff26xOoI/AAAAAAAAC5A/kbxa9ZsnPGI/image_thumb%25255B21%25255D.png?imgmax=800" width="244" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-duv8-hFGMdw/TeefhZ-D2OI/AAAAAAAAC5E/89E3VvOvIS0/s1600-h/image%25255B50%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-2Byv-SILNCA/TeefjOwCKhI/AAAAAAAAC5I/GXZZPxgE0Jo/image_thumb%25255B22%25255D.png?imgmax=800" width="244" height="226"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this tutorial, we learnt how to swop two rectangles, draw a moving rectangle and check when a rectangle is inside another one.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-2119497376278144195?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/xH_LM9VRNRs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/2119497376278144195/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/rectangle-swopping.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2119497376278144195?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/2119497376278144195?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/xH_LM9VRNRs/rectangle-swopping.html" title="Rectangle swopping" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/-i0tzY7Dqr6s/Teee829orKI/AAAAAAAAC3o/U0yANKm3KXI/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/rectangle-swopping.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIAQ3Y7cSp7ImA9WhZUEEs.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-7406635515708855248</id><published>2011-06-02T07:05:00.001-07:00</published><updated>2011-06-02T19:35:42.809-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T19:35:42.809-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="swipe" /><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="ball" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Bouncing ball</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/c0OcBEx1vcrtLusq0Uda5pzJJwc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c0OcBEx1vcrtLusq0Uda5pzJJwc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/c0OcBEx1vcrtLusq0Uda5pzJJwc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c0OcBEx1vcrtLusq0Uda5pzJJwc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In this blog, we shall go through a simple C# tutorial to create a bouncing ball.&amp;nbsp; For extra, we add the interaction with the Mouse to give the swipe effect.&lt;/p&gt; &lt;p&gt;Create a new project: WinFormsGraphics4ball.&amp;nbsp; Add a timer to the Form:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-DFuiqdsNk04/TeeYVCjwQdI/AAAAAAAAC2c/PNLvSmwa56w/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-lTJF4rZR4bg/TeeYWZZzA-I/AAAAAAAAC2g/WIK2UiI3j8g/image_thumb%25255B1%25255D.png?imgmax=800" width="354" height="382"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Using the Properties windows, add the following methods: Form1_Load(), Form1_Paint() and timer1_Tick().&lt;/p&gt; &lt;p&gt;Add the following class level variables:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-zLfi5InD6HA/TeeYXQ__0bI/AAAAAAAAC2k/lE1-Tw44yQs/s1600-h/image%25255B15%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-bCaVdKZqs20/TeeYYSIyZvI/AAAAAAAAC2o/OmfssXj_f8U/image_thumb%25255B7%25255D.png?imgmax=800" width="484" height="262"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add the following codes into the Form1_Load():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;w and h: width and height of the form surface  &lt;li&gt;create a bitmap image of the same size as the form surface  &lt;li&gt;set the location, size and rectangle for the ball  &lt;li&gt;draw the ball onto the bitmap surface  &lt;li&gt;start the timer&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-M0XZAYmsrJU/TeeYZbn4PzI/AAAAAAAAC2s/vS2epHAVRCI/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-D1YURCil5a4/TeeYaiiC_AI/AAAAAAAAC2w/Nas7KJ2jKxE/image_thumb%25255B5%25255D.png?imgmax=800" width="484" height="292"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into Form1_Paint():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;draw the bitmap image into the form surface&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-EmdYfudQz5Q/TeeYbpN4pCI/AAAAAAAAC20/liCrYlyzGJY/s1600-h/image%25255B19%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-hIR9jytCmXU/TeeYclHQD4I/AAAAAAAAC24/wMb-WaW96d4/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="102"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code into the timer1_Tick():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;using (… ) {&amp;nbsp;&amp;nbsp;&amp;nbsp; } will let the runtime knows that the object created in the using statement no longer required after the ending “}”  &lt;li&gt;check the location of ball, change its speed at the edges.&amp;nbsp; Since the reference is the top left corner, we need to take care of the right and bottom edge by subtracting the offset  &lt;li&gt;change the location of ball by adding the distance travelled.&amp;nbsp;&amp;nbsp; (distance = speed x time, assuming time is “1”, then distance travelled will be equal to speed)  &lt;li&gt;clear the bitmap image  &lt;li&gt;draw the ball onto the bitmap image  &lt;li&gt;invalidate to inform the form to call the Form1_Paint() to re-draw&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-TBeugkpGad4/TeeYdot3nsI/AAAAAAAAC28/eKVVfkGzRPw/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-VG0TrNQ3FxA/TeeYfN4XmTI/AAAAAAAAC3A/bT8yFbJPkEY/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="426"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-6gt5Yv-KKqA/TeeYgE-AqhI/AAAAAAAAC3E/XLrfozfO7vA/s1600-h/image%25255B28%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-mmjtsWEhTUw/TeeYhDvZd1I/AAAAAAAAC3I/QFfc3z9_Vxk/image_thumb%25255B14%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Extra: add interaction with mouse to give the swipe effect.&amp;nbsp; Add the Form1_MouseDown() and Form1_MouseUP().&lt;/p&gt; &lt;p&gt;Add code for Form1_MouseDown():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;check that it is the first time when the mouse down is detected  &lt;li&gt;get this location (X and Y) where mouse just click down&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-PxZw7Dy_UfE/TeeYiDD5hsI/AAAAAAAAC3M/4jrYF19zuzE/s1600-h/image%25255B32%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-HN-18o8nWOk/TeeYjUulaCI/AAAAAAAAC3Q/JlsKMO8dJKU/image_thumb%25255B16%25255D.png?imgmax=800" width="484" height="190"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Add code for Form1_MouseUp():&lt;/p&gt; &lt;ul&gt; &lt;li&gt;get the location when the mouse is released  &lt;li&gt;use the start and end location in a simple formula (by trial and error) to set the speed of the ball&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-SNZx5UOxpxo/TeeYkAB8zhI/AAAAAAAAC3U/6jnCuXZ0Yao/s1600-h/image%25255B36%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Cgba8p8Ja6A/TeeYlWRekrI/AAAAAAAAC3Y/Pbiq6T92oKE/image_thumb%25255B18%25255D.png?imgmax=800" width="484" height="244"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – click the mouse, hold as you swipe for a distance and release:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-nTroRvCINSE/TeeYmWc0-pI/AAAAAAAAC3c/DZNryD72tHA/s1600-h/image%25255B40%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-CXv-u248sY8/TeeYntQY7EI/AAAAAAAAC3g/NFGCdi8OtN4/image_thumb%25255B20%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;For those more adventurous, you may try out the following code in timer1_Tick(),&amp;nbsp; to give the gravity effect to the ball:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-p7jAa6T_3mo/TehIeYXENWI/AAAAAAAAC5M/K_nNgTmNtEo/s1600-h/image%25255B8%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-oZ6I14HZf7U/TehIfVL17tI/AAAAAAAAC5Q/B8STBpxMzCY/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="306"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a simple ball bouncing exercise.&amp;nbsp; We shall add on in another later blog to 1) add paddle and 2) add blocks to be hit and scored.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-7406635515708855248?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/254pTvhSc8k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/7406635515708855248/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/06/bouncing-ball.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7406635515708855248?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/7406635515708855248?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/254pTvhSc8k/bouncing-ball.html" title="Bouncing ball" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-lTJF4rZR4bg/TeeYWZZzA-I/AAAAAAAAC2g/WIK2UiI3j8g/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/06/bouncing-ball.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEINRH47cSp7ImA9WhZVGU0.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-5404812472609003418</id><published>2011-05-31T22:36:00.001-07:00</published><updated>2011-05-31T22:36:35.009-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-31T22:36:35.009-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="bitmap" /><category scheme="http://www.blogger.com/atom/ns#" term="game" /><title>Draw to Image before updating form surface</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/g5MFgq5ZB-v7b5eu5ptCMrMh2gE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g5MFgq5ZB-v7b5eu5ptCMrMh2gE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/g5MFgq5ZB-v7b5eu5ptCMrMh2gE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g5MFgq5ZB-v7b5eu5ptCMrMh2gE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the previous blog, we draw directly onto the form surface:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-i8bM38GqUn8/TeXPwTenxzI/AAAAAAAAC1s/2aWhrUfI1ZI/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-u5PPiJO1v_g/TeXPxOyPKvI/AAAAAAAAC1w/3LP3_AGPcj4/image_thumb%25255B1%25255D.png?imgmax=800" width="484" height="92"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When we resize, the drawing is affected.&amp;nbsp; The way to keep the drawing is to draw to a bitmap image (in the memory) and then draw this bitmap image to the surface.&amp;nbsp; Since the bitmap image contains the drawing and will not be affected by the form resizing:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-IsuK21VzpXY/TeXPxrCU3II/AAAAAAAAC10/Dg3gbYTrv5o/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-_qCN1jtWpG4/TeXPye4mc4I/AAAAAAAAC14/QowQ6LHAzEw/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="192"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Create a new WinForms app: WinFormsGraphics3bmp.&lt;/p&gt; &lt;p&gt;Add the Form1_Load and _Paint methods as follows:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-zOS8GBEgukg/TeXPyzHp7pI/AAAAAAAAC18/lSca6K__hx8/s1600-h/image%25255B20%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-8FMvmmEzkOc/TeXPzQPZIkI/AAAAAAAAC2A/wc-QoGj7RWw/image_thumb%25255B8%25255D.png?imgmax=800" width="484" height="196"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-aCEW6sPOJk4/TeXP1mmdw0I/AAAAAAAAC2E/S5DHH-jJF8M/s1600-h/image%25255B21%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-LpkFdnEcwFY/TeXP2eFTgyI/AAAAAAAAC2I/wKqT8QOFgRg/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="150"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-mxRSLWP7HAQ/TeXP29pKayI/AAAAAAAAC2M/VgYpglqllvQ/s1600-h/image%25255B22%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-HskfbKYhCFI/TeXP3S5sMYI/AAAAAAAAC2Q/JkhRM8g1SYk/image_thumb%25255B10%25255D.png?imgmax=800" width="484" height="268"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-H2an05kvrtg/TeXP4L0LP8I/AAAAAAAAC2U/rBjERcfrink/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-kLS843qCgzY/TeXP4aI-l2I/AAAAAAAAC2Y/jQF_ZwPEH-s/image_thumb%25255B11%25255D.png?imgmax=800" width="484" height="90"&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;The init() method can be re-used later to re-draw the grids after clearing.&lt;/p&gt; &lt;p&gt;Continue this exercise by adding the Form1_MouseDown, _MouseUp, _MouseMove and _KeyDown methods to make it works as per previous blog.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-5404812472609003418?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/kJup98AYKqo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/5404812472609003418/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/05/draw-to-image-before-updating-form.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5404812472609003418?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/5404812472609003418?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/kJup98AYKqo/draw-to-image-before-updating-form.html" title="Draw to Image before updating form surface" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-u5PPiJO1v_g/TeXPxOyPKvI/AAAAAAAAC1w/3LP3_AGPcj4/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/05/draw-to-image-before-updating-form.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcAQno7eip7ImA9WhZVGE4.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-1258075530663542657</id><published>2011-05-31T02:27:00.001-07:00</published><updated>2011-05-31T02:27:23.402-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-31T02:27:23.402-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mouse" /><category scheme="http://www.blogger.com/atom/ns#" term="graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="drawing" /><category scheme="http://www.blogger.com/atom/ns#" term="keypress" /><title>Drawing App using Graphics</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2AzzYFazhi0i57SpgiZSJgfK56o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2AzzYFazhi0i57SpgiZSJgfK56o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2AzzYFazhi0i57SpgiZSJgfK56o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2AzzYFazhi0i57SpgiZSJgfK56o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We will made use of what we just learnt on &lt;a href="http://www.homeandlearn.co.uk/csharp/csharp_s15p1.html"&gt;drawing lines, rectangles and filling the shapes with colour&lt;/a&gt;.&amp;nbsp; We shall create a drawing application that listen to mouse down, move and up as well as Keys.A, B and C.&lt;/p&gt; &lt;p&gt;Create a new program: WindowsApplicationGraphics2drawing.&lt;/p&gt; &lt;p&gt;Use the Solution Window Events to create the Form1_Load and _Paint method, then add the following code:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-XLrh0r57nPg/TeS0TbrpRhI/AAAAAAAAC0s/jpuVxTMVT1o/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-qhZwcYAwkeQ/TeS0UBqAAzI/AAAAAAAAC0w/j1wU2evwadg/image_thumb%25255B3%25255D.png?imgmax=800" width="484" height="260"&gt;&lt;/a&gt;&lt;a href="http://lh3.ggpht.com/-1huv-dAvolM/TeS0U9DX4QI/AAAAAAAAC00/G1GMSg3qoTo/s1600-h/image%25255B10%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-3W_5KwyDOBI/TeS0VppzSbI/AAAAAAAAC04/g8Oqomh50lo/image_thumb%25255B4%25255D.png?imgmax=800" width="484" height="332"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute the partially completed program and you will get the following grids being drawn.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-b4GeiX4evz8/TeS0WVBF-dI/AAAAAAAAC08/jSajsQwoMfQ/s1600-h/image%25255B11%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-N06Dd-4Yxc8/TeS0XCz2msI/AAAAAAAAC1A/xIt1oaXJomE/image_thumb%25255B5%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Continue to add the code for Form1_MouseDown, _MouseMove and _MouseUp:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-j5_2SljHxTo/TeS0XknvS6I/AAAAAAAAC1E/SiUUly7_IUI/s1600-h/image%25255B21%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-0809rLQG9-E/TeS0YdDlRLI/AAAAAAAAC1I/oE4rUKf-2eM/image_thumb%25255B9%25255D.png?imgmax=800" width="484" height="264"&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/-mfH9f93Xm74/TeS0ZDBMLEI/AAAAAAAAC1M/NlIw0MOMFXg/s1600-h/image%25255B22%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-cudUOXnbFCw/TeS0ZoMdVGI/AAAAAAAAC1Q/6P8NcqaBuJU/image_thumb%25255B10%25255D.png?imgmax=800" width="484" height="172"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute – use the mouse to draw on the surface:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-BikfskCOm04/TeS0aQhRU2I/AAAAAAAAC1U/ioQFYscv1E0/s1600-h/image%25255B23%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Q136RhRDokQ/TeS0bN1tEhI/AAAAAAAAC1Y/b5lqNIYBURo/image_thumb%25255B11%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt;      &lt;p&gt;Continue to add code for Form1_KeyDown:&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;(Remember to set the “KeyPreview” property to true)&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-X9aO4cXtsS4/TeS0bvKujQI/AAAAAAAAC1c/pVDng_iifdw/s1600-h/image%25255B30%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-W3R0e1iC51A/TeS0c0xkQkI/AAAAAAAAC1g/9NUF9wm45UU/image_thumb%25255B14%25255D.png?imgmax=800" width="484" height="312"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Build and execute, use Keys A, B and C to change colour.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-YQ22j9ur2to/TeS0dasz35I/AAAAAAAAC1k/zYEbnx7mXR8/s1600-h/image%25255B31%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-1xFaIb3P_u8/TeS0ejoM6_I/AAAAAAAAC1o/2TGRO2R887w/image_thumb%25255B15%25255D.png?imgmax=800" width="364" height="337"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You will notice some odd behaviours when you minimize or re-size the form.&amp;nbsp; We will solve the problem by drawing on a bitmap and use it to output to the surface.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-1258075530663542657?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/lKyMKbJ5THA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/1258075530663542657/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/05/drawing-app-using-graphics.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1258075530663542657?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/1258075530663542657?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/lKyMKbJ5THA/drawing-app-using-graphics.html" title="Drawing App using Graphics" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-qhZwcYAwkeQ/TeS0UBqAAzI/AAAAAAAAC0w/j1wU2evwadg/s72-c/image_thumb%25255B3%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/05/drawing-app-using-graphics.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8CRnw5eyp7ImA9WhZVEkQ.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-6775864388982316779</id><published>2011-05-24T21:14:00.001-07:00</published><updated>2011-05-24T21:14:27.223-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-24T21:14:27.223-07:00</app:edited><title>Exercise using ArrayList</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VbKdHASxoIaTe26zZQdH-GsvZsc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VbKdHASxoIaTe26zZQdH-GsvZsc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VbKdHASxoIaTe26zZQdH-GsvZsc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VbKdHASxoIaTe26zZQdH-GsvZsc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Use the following for the exercise 15.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_BTzuSFCPfIw/TdyB_mKQRiI/AAAAAAAAC0c/v2SGWs6QN7Q/s1600-h/image%5B7%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_BTzuSFCPfIw/TdyCEIr7e6I/AAAAAAAAC0g/JhmT_ZJ8yW4/image_thumb%5B3%5D.png?imgmax=800" width="484" height="486"&gt;&lt;/a&gt;&lt;a href="http://lh6.ggpht.com/_BTzuSFCPfIw/TdyCFVLEiYI/AAAAAAAAC0k/N2ijVq-Wq38/s1600-h/image%5B8%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_BTzuSFCPfIw/TdyCH4Y7oTI/AAAAAAAAC0o/cyxljel9ntY/image_thumb%5B4%5D.png?imgmax=800" width="484" height="128"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-6775864388982316779?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/-e7TLmKPI9o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/6775864388982316779/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/05/exercise-using-arraylist.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/6775864388982316779?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/6775864388982316779?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/-e7TLmKPI9o/exercise-using-arraylist.html" title="Exercise using ArrayList" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_BTzuSFCPfIw/TdyCEIr7e6I/AAAAAAAAC0g/JhmT_ZJ8yW4/s72-c/image_thumb%5B3%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/05/exercise-using-arraylist.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8AQX8zeSp7ImA9WhZVEkQ.&quot;"><id>tag:blogger.com,1999:blog-7595121951178860321.post-442271950444285259</id><published>2011-05-24T20:40:00.001-07:00</published><updated>2011-05-24T20:40:40.181-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-24T20:40:40.181-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="strings" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="replace" /><category scheme="http://www.blogger.com/atom/ns#" term="dictionary" /><title>Another Collection Class: Dictionary&lt;T,T&gt;</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PHAtCQPPw4TxLF8uHMGdUhuPsO8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PHAtCQPPw4TxLF8uHMGdUhuPsO8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PHAtCQPPw4TxLF8uHMGdUhuPsO8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PHAtCQPPw4TxLF8uHMGdUhuPsO8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;When we need to have constant lookup of key to value, Dictionary class is what we need.&lt;/p&gt; &lt;p&gt;For example:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_BTzuSFCPfIw/Tdxv_NkXPSI/AAAAAAAACz8/YWuYK2eDWcY/s1600-h/image%5B3%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_BTzuSFCPfIw/TdxwCmICzSI/AAAAAAAAC0A/IQ1vqFTXtbU/image_thumb%5B1%5D.png?imgmax=800" width="364" height="114"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When you look up “mistak”, the value you will get “mistake” and so on.&lt;/p&gt; &lt;p&gt;The syntax is Dictionary&amp;lt;type,type&amp;gt; where type is int, char, string, etc.&lt;/p&gt; &lt;p&gt;How you declare:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_BTzuSFCPfIw/TdxwHiS8nUI/AAAAAAAAC0E/hZA8EWhzOzc/s1600-h/image%5B7%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_BTzuSFCPfIw/TdxwOhuGTVI/AAAAAAAAC0I/t7cs3eGwt7Q/image_thumb%5B3%5D.png?imgmax=800" width="484" height="24"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;or a shorter way using “var”:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_BTzuSFCPfIw/Tdx6HeupwTI/AAAAAAAAC0M/kRKAeCSYGSU/s1600-h/image%5B11%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_BTzuSFCPfIw/Tdx6JmpSG0I/AAAAAAAAC0Q/V1PlobOO3O0/image_thumb%5B5%5D.png?imgmax=800" width="484" height="30"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;A full example is listed below:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_BTzuSFCPfIw/Tdx6LWxoIGI/AAAAAAAAC0U/uIrcHOETVVo/s1600-h/image%5B15%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_BTzuSFCPfIw/Tdx6NjU5UEI/AAAAAAAAC0Y/_-R0WE8onUY/image_thumb%5B7%5D.png?imgmax=800" width="484" height="320"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7595121951178860321-442271950444285259?l=mpgddspf.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareProgrammingFundamentals/~4/3WjcryMpzFA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://mpgddspf.blogspot.com/feeds/442271950444285259/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://mpgddspf.blogspot.com/2011/05/another-collection-class-dictionary.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/442271950444285259?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7595121951178860321/posts/default/442271950444285259?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareProgrammingFundamentals/~3/3WjcryMpzFA/another-collection-class-dictionary.html" title="Another Collection Class: Dictionary&amp;lt;T,T&amp;gt;" /><author><name>PUAH Hock Leng@SG</name><uri>http://www.blogger.com/profile/02843067645232677846</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_BTzuSFCPfIw/TdxwCmICzSI/AAAAAAAAC0A/IQ1vqFTXtbU/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://mpgddspf.blogspot.com/2011/05/another-collection-class-dictionary.html</feedburner:origLink></entry></feed>

