<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>I Love that New Syntax Smell : Windows Forms</title><link>http://blogs.msdn.com/arich/archive/category/3043.aspx</link><description>A set of samples, featuring sample conversions and original samples for Windows Forms, written in Whidbey C++.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Windows Forms III - Dynamic Layout</title><link>http://blogs.msdn.com/arich/archive/2004/02/05/68276.aspx</link><pubDate>Thu, 05 Feb 2004 19:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:68276</guid><dc:creator>arich</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/arich/comments/68276.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arich/commentrss.aspx?PostID=68276</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;I'm not going to belabor my blog with yet another code explanation.&amp;nbsp; I've converted the dynamic layout example (found &lt;A href="http://samples.gotdotnet.com/quickstart/winforms/"&gt;here&lt;/A&gt;) from C# to C++.&amp;nbsp; It isn't especially interesting, but it is good groundwork for later examples and projects.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Get the code!&lt;/STRONG&gt;&amp;nbsp; You can download this dynamic layout example &lt;A href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=f0ff706b-3814-47b4-b5b6-7663c91f282e"&gt;here&lt;/A&gt;.&amp;nbsp; As usual, both old and new syntax versions are included.&amp;nbsp; And, as usual, if the old syntax version doesn't seem to compile, please let me know.&amp;nbsp; The comments section on the sample download page has a note about avoiding a compiler warning.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=68276" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arich/archive/tags/snippets/default.aspx">snippets</category><category domain="http://blogs.msdn.com/arich/archive/tags/Windows+Forms/default.aspx">Windows Forms</category></item><item><title>Hello World from Windows Forms, MK II.</title><link>http://blogs.msdn.com/arich/archive/2004/01/22/61972.aspx</link><pubDate>Fri, 23 Jan 2004 00:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:61972</guid><dc:creator>arich</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/arich/comments/61972.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arich/commentrss.aspx?PostID=61972</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;Now that we've gotten our feet wet, it's time to try something a bit more complicated.&amp;nbsp; We'll include a TextBox and&amp;nbsp;a Button in this example, and also take a quick look at how we wire up events on actions like button clicks.&amp;nbsp; I'm going to be skipping the explanation for code that we've already seen, and just concentrating on the new stuff.&amp;nbsp; As always, scroll down for the sample download.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;HR id=null&gt;
&lt;/P&gt;&lt;FONT face=Arial size=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &lt;SPAN style="COLOR: blue"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; HelloWorldForm : &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; Form {&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;private&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Button ^button1;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;TextBox ^textBox1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;FONT face=Arial&gt;Our HelloWorldForm now has two &lt;FONT face="Courier New" color=#0000ff&gt;private&lt;/FONT&gt; members, &lt;FONT face="Courier New"&gt;button1&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;textBox1&lt;/FONT&gt;.&amp;nbsp; The UI elements they represent should be fairly obvious.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;HelloWorldForm() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//allocate the private members&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1 = &lt;SPAN style="COLOR: blue"&gt;gcnew&lt;/SPAN&gt; Button;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;textBox1 = &lt;SPAN style="COLOR: blue"&gt;gcnew&lt;/SPAN&gt; TextBox;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Set up the Form&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Text = "Hello Windows Forms World";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;AutoScaleBaseSize = System::Drawing::Size(5, 13);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ClientSize = System::Drawing::Size(392, 117);&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;FONT face=Arial&gt;Here's the start of the default constructor, where all the basic setup for this form takes place.&amp;nbsp; We &lt;FONT face="Courier New" color=#0000ff&gt;gcnew&lt;/FONT&gt; our two private members, and we start setting up the form.&amp;nbsp; I didn't go into this much last time, but what is happening here may not be totally obvious.&amp;nbsp; &lt;FONT face="Courier New"&gt;Text&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;AutoScaleBaseSize&lt;/FONT&gt;, and the other members we'll see are members of &lt;FONT face="Courier New"&gt;HelloWorldForm&lt;/FONT&gt;'s parent type, &lt;FONT face="Courier New"&gt;System::Windows::Forms::Form&lt;/FONT&gt;.&amp;nbsp; To check out the various members of this type, head&amp;nbsp;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsformmemberstopic.asp"&gt;here&lt;/A&gt;.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;FONT face=Arial&gt;Basically, we're setting up the form to have a client area size of 392x117 pixels.&amp;nbsp; This is the default size, which is resizeable (based on whether or not you wish to allow this).&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;FONT face=Arial&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Set the minimum form size to the client size + the height of the title bar&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MinimumSize = System::Drawing::Size(392, (117 + SystemInformation::CaptionHeight));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Set the default button on the Form&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;AcceptButton=button1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;It should be plainly obvious what the first line does.&amp;nbsp; The reason we use the &lt;FONT face="Courier New"&gt;CaptionHeight&lt;/FONT&gt; property is that the height of the caption bar (where the program icon, maximize and close buttons, etc. are displayed) can change, depending especially on the font the user has set their default program title to.&amp;nbsp; &lt;FONT face="Courier New"&gt;AcceptButton&lt;/FONT&gt; is the default button on a form that is pressed when the user hits the Enter key.&amp;nbsp; (There's also a &lt;FONT face="Courier New"&gt;CancelButton&lt;/FONT&gt;, which is what is pressed when the user hits the Esc key.)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Create the button&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1-&amp;gt;Location = Point(256, 64);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1-&amp;gt;Size = System::Drawing::Size(120, 40);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1-&amp;gt;TabIndex = 2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1-&amp;gt;Text = "Click Me!";&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;Here, we're simply populating our &lt;FONT face="Courier New"&gt;button1&lt;/FONT&gt; with various useful attributes.&amp;nbsp; The position for &lt;FONT face="Courier New"&gt;Location&lt;/FONT&gt; is based on the upper left-hand corner of the form (which is 0,0).&amp;nbsp; In this case, our button's upper left-hand corner is 256 pixels right and 64 pixels down from that origin.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Register the event handler&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;button1-&amp;gt;Click += &lt;SPAN style="COLOR: blue"&gt;gcnew&lt;/SPAN&gt; System::EventHandler(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;, &amp;amp;HelloWorldForm::button1_Click);&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;This is probably the most interesting single line of code in this example.&amp;nbsp; We're probably all aware that Windows is an event-based world.&amp;nbsp; The program sits out there, and waits for user input - whether it be striking a key on the keyboard, or some form of mouse movement.&amp;nbsp; So, we have to be able to wire up function calls to actions the user could perform.&amp;nbsp; We call these actions &lt;STRONG&gt;events&lt;/STRONG&gt;.&amp;nbsp; &lt;FONT face="Courier New"&gt;System::Windows::Forms::Button::Click&lt;/FONT&gt; is one such event.&amp;nbsp; (Actually, &lt;FONT face="Courier New"&gt;Click&lt;/FONT&gt; is an event that &lt;FONT face="Courier New"&gt;Button&lt;/FONT&gt; inherits from a common base class, &lt;FONT face="Courier New"&gt;System::Windows::Forms::Control&lt;/FONT&gt;.)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;We can wire up a function to handle an event by using the &lt;FONT face="Courier New"&gt;+=&lt;/FONT&gt; operator.&amp;nbsp; This allows us to add multiple handlers to a single event (which can be very useful).&amp;nbsp; We pass a &lt;FONT face="Courier New" color=#0000ff&gt;this&lt;/FONT&gt; pointer and a pointer to the handler function to the &lt;FONT face="Courier New"&gt;EventHandle&lt;/FONT&gt;r constructor, and add&amp;nbsp;that&amp;nbsp;temporary object&amp;nbsp;to the &lt;FONT face="Courier New"&gt;Click&lt;/FONT&gt; event.&amp;nbsp;&amp;nbsp;Now, when the user clicks &lt;FONT face="Courier New"&gt;button1&lt;/FONT&gt;, the function &lt;FONT face="Courier New"&gt;button1_Click&lt;/FONT&gt; will be called!&amp;nbsp; (The definition of this function is below.)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT face=Arial&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Create the text box&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;textBox1-&amp;gt;Text = "Hello Windows Forms World";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;textBox1-&amp;gt;TabIndex = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;textBox1-&amp;gt;Size = System::Drawing::Size(360, 20);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;textBox1-&amp;gt;Location = Point(16, 24);&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;More property set-up, this time for our &lt;FONT face="Courier New"&gt;TextBox&lt;/FONT&gt;.&amp;nbsp; The &lt;FONT face="Courier New"&gt;TabIndex&lt;/FONT&gt; property that you see here (and on &lt;FONT face="Courier New"&gt;button1&lt;/FONT&gt;)&amp;nbsp;represents the order that the controls are focused on, with multiple presses of the Tab key.&amp;nbsp; The focus starts on whatever control has &lt;FONT face="Courier New"&gt;TabIndex&lt;/FONT&gt; 1, and, with subsequent presses of Tab, will cycle through the different controls in order.&amp;nbsp; When the last &lt;FONT face="Courier New"&gt;TabIndex&lt;/FONT&gt; is reached, we loop around to the first again.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Add the controls to the form&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Controls-&amp;gt;Add(button1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Controls-&amp;gt;Add(textBox1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;Finally, we need to &lt;FONT face="Courier New"&gt;Add&lt;/FONT&gt; our two controls to &lt;FONT face="Courier New"&gt;HelloWorldForm&lt;/FONT&gt;'s &lt;FONT face="Courier New"&gt;Controls&lt;/FONT&gt;.&amp;nbsp; Up to this point, the controls have been merely classes that happened to be members of our form.&amp;nbsp; When you hook them up by &lt;FONT face="Courier New"&gt;Add&lt;/FONT&gt;ing them, they become visible, clickable objects inside the UI.&amp;nbsp; This is important to remember, if you don't register your control, it simply won't be visible, and you'll be left wondering why.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;protected&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Dispose(&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; disposing)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MessageBox::Show("Disposed!");&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;} &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt;(Exception^ e) {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Form::Dispose(disposing);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;I wouldn't have shown you the &lt;FONT face="Courier New"&gt;Dispose&lt;/FONT&gt; function again, except that this time, I'm using &lt;FONT face="Courier New"&gt;MessageBox::Show&lt;/FONT&gt; to pop up a standard Windows dialog while I'm disposing the class, to demonstrate exactly when &lt;FONT face="Courier New"&gt;Dispose&lt;/FONT&gt; gets called.&amp;nbsp; This is bad design, however, as you typically don't want anything in a &lt;FONT face="Courier New"&gt;Dispose&lt;/FONT&gt; function that doesn't need to be there.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;private&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; button1_Click(Object^ sender, EventArgs^ evArgs) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MessageBox::Show(String::Concat("Text is: '", textBox1-&amp;gt;Text, "'"));&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;};&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;Here's &lt;FONT face="Courier New"&gt;button1_Click&lt;/FONT&gt;, the function that is wired up to our button's &lt;FONT face="Courier New"&gt;Click&lt;/FONT&gt; event.&amp;nbsp; It also uses &lt;FONT face="Courier New"&gt;MessageBox::Show&lt;/FONT&gt; to pop up a Windows dialog, with the text of whatever is in our &lt;FONT face="Courier New"&gt;TextBox&lt;/FONT&gt;.&amp;nbsp; We also close out our class here.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; main() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Application::Run(&lt;SPAN style="COLOR: blue"&gt;gcnew&lt;/SPAN&gt; HelloWorldForm);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;And, last but not least, our &lt;FONT face="Courier New"&gt;main&lt;/FONT&gt; function.&amp;nbsp; Still not flashy, it does the same thing it did in our first example.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;
&lt;HR id=null&gt;
&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;&lt;STRONG&gt;Whew, that was longer.&lt;/STRONG&gt;&amp;nbsp; Yes, it was, but it also did a whole lot more, and without too much additional code.&amp;nbsp; Next time, we'll be looking at the power of Windows Forms dynamic layout.&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt"&gt;&lt;STRONG&gt;Get the files.&lt;/STRONG&gt;&amp;nbsp; You can get the sample &lt;A href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=9fb9045e-a754-4f92-a549-72f20dcb0931"&gt;here&lt;/A&gt;.&amp;nbsp; This contains two files, hwf2.cpp, and hwf2OS.cpp.&amp;nbsp; Hwf2 is the complete code sample above, and hwf2OS.cpp is the Managed Extensions version of it.&amp;nbsp; As always, if something doesn't compile properly, or you have questions, please post a comment.&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=61972" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arich/archive/tags/snippets/default.aspx">snippets</category><category domain="http://blogs.msdn.com/arich/archive/tags/Windows+Forms/default.aspx">Windows Forms</category></item><item><title>Hello World from Windows Forms!</title><link>http://blogs.msdn.com/arich/archive/2004/01/21/61371.aspx</link><pubDate>Wed, 21 Jan 2004 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:61371</guid><dc:creator>arich</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/arich/comments/61371.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arich/commentrss.aspx?PostID=61371</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;It begins...&lt;/STRONG&gt; This will be a new series of articles.&amp;nbsp; I'll start with some ports of existing samples (from &lt;A href="http://samples.gotdotnet.com/quickstart/winforms/"&gt;here&lt;/A&gt;), and move into some original material.&amp;nbsp; I want to take a Managed C++ (and specifically a Whidbey C++) approach to Windows Forms, and investigate what exactly we can do with this powerful library.&amp;nbsp; I've created a seperate post category (+&lt;A href="http://blogs.msdn.com/arich/category/3043.aspx/rss"&gt;RSS&lt;/A&gt;) for this special set of samples, in case you want to track this set of articles specially.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;On to the first sample, the ever-traditional Hello, World.&amp;nbsp; As always, the link for the sample is at the bottom.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;HR id=null&gt;
&lt;/P&gt;&lt;FONT face=Arial size=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;#using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &amp;lt;System.Windows.Forms.dll&amp;gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;#using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &amp;lt;System.dll&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;#using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &amp;lt;System.Drawing.dll&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; System;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt; &lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; System::Windows::Forms;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;FONT face=Arial&gt;We start by &lt;FONT face="Courier New" color=#0000ff&gt;#using&lt;/FONT&gt; a few new dll's.&amp;nbsp; System.Windows.Forms.dll contains most of the important forms classes, System.dll includes some important basic types, and System.Drawing.dll contains some additional important types.&amp;nbsp; A few &lt;FONT face="Courier New" color=#0000ff&gt;using namespace&lt;/FONT&gt; declarations will help cut down on typing.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;&lt;FONT face=Arial&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; &lt;SPAN style="COLOR: blue"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; SimpleHelloWorld : &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; Form {&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;SimpleHelloWorld(){&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Text = "Hello, World.";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;}&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;};&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Here, I've declared a new &lt;FONT face="Courier New" color=#0000ff&gt;ref class&lt;/FONT&gt;, &lt;FONT face="Courier New"&gt;SimpleHelloWorld&lt;/FONT&gt;, inherited from the type &lt;FONT face="Courier New"&gt;System::Windows::Forms::Form&lt;/FONT&gt;.&amp;nbsp; I override &lt;FONT face="Courier New"&gt;Form&lt;/FONT&gt;'s default constructor with one of my own, that sets the &lt;FONT face="Courier New"&gt;Text&lt;/FONT&gt; property to, surprise, &amp;#8220;Hello, World.&amp;#8221;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; main(){&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Application::Run(&lt;SPAN style="COLOR: blue"&gt;gcnew&lt;/SPAN&gt; SimpleHelloWorld);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Here's my main function.&amp;nbsp; I make a call to System::Windows::Forms::Application::Run, and pass it an instance of my SimpleHelloWorld class.&amp;nbsp; The Application::Run function will block until the form passed to it is closed.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;
&lt;HR id=null&gt;
&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;STRONG&gt;That's it?&lt;/STRONG&gt;&amp;nbsp; It is undoubtedly simpler than many Windows applications you've seen in the past.&amp;nbsp; No HWNDs, no fancy CoCreateInstances, not even a WinMain!&amp;nbsp; It looks just like a lot of other simple C++ programs you've seen in the past, except this one creates a real window.&amp;nbsp; Yes, it may be a simplistic window with no features, but we're on our way.&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal dir=ltr style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;STRONG&gt;Get the files.&lt;/STRONG&gt;&amp;nbsp; You can get the files &lt;A href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=1c4518ac-4293-4035-b380-6e81b20c6b43"&gt;here&lt;/A&gt;.&amp;nbsp; This contains two files, hwf.cpp and hwfOS.cpp.&amp;nbsp; Hwf.cpp is the code sample above, in Whidbey C++, and hwfOS.cpp is the Managed Extensions version of it.&amp;nbsp; I don't have an install of VC.NET 2003 handy, so please post a comment if it doesn't compile or work properly.&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=61371" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arich/archive/tags/snippets/default.aspx">snippets</category><category domain="http://blogs.msdn.com/arich/archive/tags/Windows+Forms/default.aspx">Windows Forms</category></item></channel></rss>