PageRenderTime 71ms CodeModel.GetById 39ms RepoModel.GetById 0ms app.codeStats 0ms

/Languages/IronPython/Samples/WinFormsMapPoint/readme.htm

https://github.com/jdhardy/ironpython
HTML | 946 lines | 946 code | 0 blank | 0 comment | 0 complexity | acaeb70ddff96300866a3b9a2ab170e6 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type"
  5. content="text/html; charset=iso-8859-1">
  6. <title>IronPython Windows Forms Tutorial</title>
  7. <link rel="stylesheet" type="text/css" href="../Samples.css">
  8. <style type="text/css">
  9. .style1 {
  10. font-size: x-large;
  11. }
  12. </style>
  13. </head>
  14. <body lang="EN-US">
  15. <div class="Section1">
  16. <p class="Title1">IronPython Windows Forms Tutorial</p>
  17. <p class="style1">From Empty Window to MapPoint Client</p>
  18. <p class="Title2"><small><small><small>Contributor: Martin Schray</small></small>
  19. </small><br>
  20. </p>
  21. <hr>
  22. <p class="CopyrightText">Information in this document is subject to
  23. change without notice. The example companies, organizations, products,
  24. people, and events depicted herein are fictitious. No association with
  25. any real company, organization, product, person or event is intended or
  26. should be inferred. Complying with all applicable copyright laws is the
  27. responsibility of the user. Without limiting the rights under
  28. copyright, no part of this document may be reproduced, stored in or
  29. introduced into a retrieval system, or transmitted in any form or by
  30. any means (electronic, mechanical, photocopying, recording, or
  31. otherwise), or for any purpose, without the express written permission
  32. of Microsoft Corporation.</p>
  33. <p class="CopyrightText">&nbsp;</p>
  34. <p class="CopyrightText">Microsoft may have patents, patent
  35. applications, trademarked, copyrights, or other intellectual property
  36. rights covering subject matter in this document. Except as expressly
  37. provided in any written license agreement from Microsoft, the
  38. furnishing of this document does not give you any license to these
  39. patents, trademarks, copyrights, or other intellectual property.</p>
  40. <p class="CopyrightText">
  41. &nbsp;</p>
  42. <p class="CopyrightText">&copy; Microsoft Corporation. All rights
  43. reserved.</p>
  44. <p class="CopyrightText">&nbsp;</p>
  45. <p class="CopyrightText">Microsoft, MS-DOS, MS, Windows, Windows NT,
  46. MSDN, Active Directory, BizTalk, SQL Server, SharePoint, Outlook,
  47. PowerPoint, FrontPage, Visual Basic, Visual C++, Visual J++, Visual
  48. InterDev, Visual SourceSafe, Visual C#, Visual J#,&nbsp; and Visual
  49. Studio are either registered trademarks or trademarks of Microsoft
  50. Corporation in the U.S.A. and/or other countries.</p>
  51. <p class="CopyrightText">&nbsp;</p>
  52. <p class="CopyrightText">Other product and company names herein may be
  53. the trademarks of their respective owners.</p>
  54. <hr>
  55. <p class="CopyrightText">
  56. &nbsp;</p>
  57. <p class="CopyrightText">This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  58. copy of the license can be found in the License.html file at the root of this distribution. If
  59. you cannot locate the Apache License, Version 2.0, please send an email to
  60. ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  61. by the terms of the Apache License, Version 2.0.</p>
  62. <p class="CopyrightText">&nbsp;</p>
  63. <p class="Body">&nbsp;</p>
  64. <p class="contentsheading"> Prerequisites</p>
  65. <p class="body"> The prerequisites to successfully run this application
  66. are:</p>
  67. <ul>
  68. <li class="normal">IronPython 2.6 distribution
  69. <ul>
  70. <li>If you are new to IronPython, please go over the tutorial
  71. that comes with this distribution</li>
  72. <li>Download from
  73. <a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=12482">here</a></li>
  74. </ul>
  75. </li>
  76. </ul>
  77. <p class="Body">&nbsp;</p>
  78. <p class="ContentsHeading">Contents</p>
  79. <p class="Toc1">Tutorial 1: <a href="#T1">Building Windows Forms
  80. applications</a></p>
  81. <p class="Toc2">Exercise 1: <a href="#T1.1">Building Interesting
  82. Windows Forms Applications</a></p>
  83. <p class="Toc3">Task 1: <a href="#T1.1.1">Create an Empty Windows
  84. Forms Application</a></p>
  85. <p class="Toc3">Task 2: <a href="#T1.1.2">Add Controls to a Windows
  86. Forms Application</a></p>
  87. <p class="Toc3">Task 3: <a href="#T1.1.3">Add Controls that Work
  88. Together</a></p>
  89. <p class="Toc3">Task 4: <a href="#T1.1.4">Add Non-visible Components
  90. to the Form</a></p>
  91. <p class="Toc3">Task 5: <a href="#T1.1.5">Use Layout Panels to
  92. Automatically Layout Controls</a></p>
  93. <p class="Toc3">Task 6: <a href="#T1.1.5">Add a Web Browser to the Form</a></p>
  94. <p class="Toc3">Task 7: <a href="#T1.1.7">Displaying a Map Picture
  95. with Data from MapPoint</a></p>
  96. <p class="Toc3">Task 8: <a href="#T1.3.2">Add Route-finding to the Map
  97. Application</a></p>
  98. <p class="Body">&nbsp;</p>
  99. <p class="Body">&nbsp;</p>
  100. </div>
  101. <h1><a name="T1">Tutorial 1: Building Windows Forms Applications</a></h1>
  102. <p class="Body">In this tutorial we interactively build a Windows
  103. Form.&nbsp; We will look at eight Windows Forms Applications that
  104. progress from a Windows Form window with just a title to an application
  105. that uses the MapPoint web service.&nbsp; We will discuss the Windows
  106. Forms code so that you understand within each task what the IronPython
  107. code is doing.&nbsp; However, though the applications are relatively
  108. small, there's enough code that you won't want to type it into the
  109. IronPython console.&nbsp; Each task will simply direct you to run the
  110. application from a Windows cmd.exe window, as you would launch any
  111. Python script.</p>
  112. <p class="Body">Estimated time to complete this tutorial: <b>40 minutes</b></p>
  113. <p class="Body">The objective of this tutorial is to familiarize you
  114. with more Windows Forms features using IronPython.</p>
  115. <ul>
  116. <li>
  117. <p class="Body"><a href="#T1.1">Building Interesting Windows Forms
  118. Applications</a></p>
  119. </li>
  120. </ul>
  121. <h2><a name="T1.1">Exercise 1: Building Interesting Windows Forms
  122. Applications</a></h2>
  123. <p class="Body">The goal of this exercise is to provide some simple
  124. examples of IronPython Windows Forms applications.&nbsp; The first few
  125. tasks will be quite simple and lack any real sophistication, but
  126. provide the building blocks for building more complete UI as you
  127. progress through the tasks.&nbsp; Some of the tasks build on the code
  128. from previous tasks, but each task provides full source code and is
  129. meant to run as a complete example. </p>
  130. <p class="Body">The tasks that use MapPoint Web Services require the
  131. MapPointWebServicesProject.dll.&nbsp; Task 7 contains an extra step
  132. that tells you how to build this DLL.</p>
  133. <p class="Body">&nbsp;</p>
  134. <h3><a name="T1.1.1">Task 1: Create an Empty Windows Forms Application
  135. (FormV1.py)</a></h3>
  136. <p class="Body">Task 1 creates an empty Windows form and sets the
  137. window title of the form.&nbsp; The first three lines of code are the
  138. required imports.&nbsp; We need to add a reference to
  139. System.Windows.Forms, and then we can import all the names from it into
  140. our module.</p>
  141. <p class="Body">The class FormV1 inherits from
  142. System.Windows.Forms.Form, so that it has all the default behaviors of
  143. a form.&nbsp; The __init__ method is used to set the forms window
  144. title.&nbsp; Finally, we invoke Application.Run to launch our form into
  145. action. </p>
  146. <p class="Body">&nbsp;</p>
  147. <p class="Code-Highlighted">import clr<br>
  148. clr.AddReference("System.Windows.Forms")<br>
  149. from System.Windows.Forms import *<br>
  150. <br>
  151. &nbsp;&nbsp;&nbsp; class FormV1(Form):<br>
  152. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  153. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  154. self.Text = 'Hello World'<br>
  155. <br>
  156. Application.Run(FormV1())</p>
  157. <p class="Body">&nbsp;</p>
  158. <p class="Step">1. Now let's try the Windows Form application by
  159. launching the IronPython script from a cmd.exe window:</p>
  160. <p class="TypedExample">ipyw.exe winforms\formV1.py</p>
  161. <p class="Step">Note, we're using the ipyw.exe executable instead of
  162. the ipy.exe.&nbsp; Ipyw.exe launches the Windows Forms application and
  163. returns control to the cmd.exe it was launched from since the Windows
  164. Form application executes independently.</p>
  165. <p class="Step">You should see the following window pop up on your
  166. screen:</p>
  167. <p class="Step">&nbsp;</p>
  168. <p class="Step">
  169. <img src="winforms/FormV1.jpg" border="0" height="300" width="300"></p>
  170. <p class="Body">&nbsp;</p>
  171. <h3>Task 2: <a name="T1.1.2">Add Controls to A Windows Forms
  172. Application (formV2.py)</a></h3>
  173. <p class="Body">Task 2 creates a Windows form, sets the window title of
  174. the form, adds our first control (a Button), and hooks up the Click of
  175. the button to display a MessageBox when the Button is clicked.&nbsp; We
  176. show the new lines of code highlighted below.&nbsp; As in the previous
  177. task, the first three lines of code are the required imports.&nbsp; We
  178. need to add a reference to System.Windows.Forms, and then we can import
  179. from it to bring all the names from that module into ours.</p>
  180. <p class="Body">The class FormV2 inherits from
  181. System.Windows.Forms.Form, so that it has all the default behaviors of
  182. a form.&nbsp; The __init__ method is used set up instances of our
  183. form.&nbsp; First we set the Form's title (self.Text).</p>
  184. <p class="Body">Now for the new code.&nbsp; We create a Button with the
  185. text 'Message', and we set its location.&nbsp; Third we hook the
  186. Button's Click event so that when the button is clicked the
  187. OnMsgButtonClick method is called.&nbsp; Then we add the Button to the
  188. form's list of controls.</p>
  189. <p class="Body">Next we define OnMsgButtonClick, which takes two
  190. arguments.&nbsp; OnMsgButtonClick simply calls MessageBox.Show to show
  191. a classic message box pop up.</p>
  192. <p class="Body">Lastly, we invoke Application.Run to launch our form
  193. into action.</p>
  194. <p class="Body">&nbsp;</p>
  195. <p class="Code-Background">import clr<br>
  196. clr.AddReference("System.Windows.Forms")<br>
  197. from System.Windows.Forms import *<br>
  198. <br>
  199. &nbsp;&nbsp;&nbsp; class FormV2(Form):<br>
  200. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):</p>
  201. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  202. self.Text = 'Hello World'<br>
  203. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  204. msgButton = Button(Text='Message', Left =20, Top=20)<br>
  205. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  206. msgButton.Click += self.OnMsgButtonClick<br>
  207. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  208. self.Controls.Add(msgButton)<br>
  209. <br>
  210. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnMsgButtonClick(self,
  211. *args):<br>
  212. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  213. MessageBox.Show("Hello World")<br>
  214. &nbsp;</p>
  215. <p class="Code-Background">Application.Run(FormV2())</p>
  216. <p class="Body">&nbsp;</p>
  217. <p class="Step">1. Now let's try the Windows Form application by
  218. launching the IronPython script from a cmd.exe window:</p>
  219. <p class="TypedExample">ipyw.exe winforms\formV2.py</p>
  220. <p class="Step"><br>
  221. </p>
  222. <p class="Step">You should see the following window pop up on your
  223. screen:</p>
  224. <p class="Body">&nbsp;</p>
  225. <p class="Body">
  226. <img src="winforms/FormV2.jpg" border="0" height="300" width="300"></p>
  227. <p class="Body">&nbsp;</p>
  228. <p class="Body">When you click the Button, you will see the following
  229. window:</p>
  230. <p class="Body">
  231. <img src="winforms/FormV2-1.jpg" border="0" height="107" width="104"></p>
  232. <p class="Body">&nbsp;</p>
  233. <h3>Task 3:&nbsp; <a name="T1.1.3">Add Controls that Work Together
  234. (formV3.py)</a></h3>
  235. <p class="Body">Task 3 creates a Windows form, sets the window title of
  236. the form, adds a Label, Textbox, and a Button.&nbsp; We hook up the
  237. Click of the button to display a MessageBox when the Button is clicked,
  238. but in this task we use the text from the Textbox.&nbsp; As in the
  239. previous tasks, the first three lines of code are the required
  240. imports.&nbsp; We need to add a reference to System.Windows.Forms, and
  241. then we can import from it to bring all the names from that module into
  242. ours.</p>
  243. <p class="Body">The class FormV3 inherits from
  244. System.Windows.Forms.Form so that it has all the default behaviors of a
  245. form.&nbsp; The __init__ method is used to set up instances of our
  246. form.&nbsp; First we set the Form's title (self.Text).</p>
  247. <p class="Body">Now for the new code (highlighted below).&nbsp; We
  248. create a Label and add it to the form's controls.&nbsp; Then we create
  249. a TextBox, and set its location before adding it to the form's
  250. controls.&nbsp; A reference (self.txtMessage) to the TextBox is kept so
  251. that in OnMsgButtonClick we can get the Text from the TextBox.</p>
  252. <p class="Body">As before, we create a Button with the text
  253. 'Message'.&nbsp; We make it visible and set its location (which is
  254. slightly lower down in the form in this task).&nbsp; We hook the
  255. Button's Click event up so that when the button is clicked the
  256. OnMsgButtonClick method is called.&nbsp; Then we add the Button to the
  257. form's list of controls. </p>
  258. <p class="Body">Next we define OnMsgButtonClick, which takes two
  259. arguments.&nbsp; OnMsgButtonClick simply calls MessageBox.Show to
  260. display the text in the TextBox in a classic message box pop up.</p>
  261. <p class="Body">Lastly, we invoke Application.Run to launch our form. </p>
  262. <p class="Body">&nbsp;</p>
  263. <p class="Code-Background">import clr<br>
  264. clr.AddReference("System.Windows.Forms")<br>
  265. from System.Windows.Forms import *<br>
  266. <br>
  267. &nbsp;&nbsp;&nbsp; class FormV3(Form):<br>
  268. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  269. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  270. self.Text = 'Hello World'</p>
  271. <p class="Code-Background">&nbsp;</p>
  272. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  273. # Create Label<br>
  274. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  275. self.Controls.Add(Label(Text='Enter Message:'))</p>
  276. <p class="Code-Highlighted">&nbsp;</p>
  277. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  278. # Create TextBox<br>
  279. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  280. self.txtMessage = TextBox(Left=100)<br>
  281. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  282. self.Controls.Add(self.txtMessage)</p>
  283. <p class="Code-Highlighted">&nbsp;</p>
  284. <p class="Code-Background">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  285. # Create Button<br>
  286. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  287. msgButton = Button(Text='Message', Left =20, Top=25)<br>
  288. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  289. msgButton.Click += self.OnMsgButtonClick<br>
  290. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  291. self.Controls.Add(msgButton)<br>
  292. <br>
  293. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnMsgButtonClick(self,
  294. *args):</p>
  295. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  296. MessageBox.Show(self.txtMessage.Text,"Message")<br>
  297. &nbsp;</p>
  298. <p class="Code-Background">Application.Run(FormV3())</p>
  299. <p class="Body">&nbsp;</p>
  300. <p class="Step">1. Now let's try the Windows Form application by
  301. launching the IronPython script from a cmd.exe window:</p>
  302. <p class="TypedExample">ipyw.exe winforms\formV3.py</p>
  303. <p class="Step"><br>
  304. </p>
  305. <p class="Step">You should see the following window pop up on your
  306. screen:</p>
  307. <p class="Body">&nbsp;</p>
  308. <h3><img src="winforms/FormV3.jpg" border="0" height="300" width="300"></h3>
  309. <p class="Body">&nbsp;</p>
  310. <h3>Task 4:&nbsp; <a name="T1.1.4">Add Non-visible Components to the
  311. Form (formV4.py)</a></h3>
  312. <p class="Body">Task 4 has the same basic UI that task 3 had which was
  313. a form with a Label, TextBox, and a Button.&nbsp; The difference is
  314. that we begin to use non-visible components in task 4.&nbsp; Components
  315. allow us to add objects that don't necessarily have a visual
  316. representation.&nbsp; For example, a Timer is a component that doesn't
  317. appear visibly on the form.&nbsp; In task 4 we will use a NotifyIcon to
  318. allow our application to appear in the system tray and ContextMenuStrip
  319. to give NotifyIcon a right-click menu.&nbsp; Our first few lines of
  320. code now have a few additions since we need to access and import the
  321. System.Drawing namespace.&nbsp; We need the System.Drawing namespace to
  322. access the Icon class.&nbsp; The Icon class is used to associate an
  323. icon file with our NotifyIcon.</p>
  324. <p class="Body">The good news is that the code to set the form's title,
  325. as well as create the Label, TextBox, and Button are the same as Task
  326. 3.&nbsp; Now let's get to the new code.&nbsp; Before we can add the
  327. Components to our form we must create the components container to hold
  328. them.&nbsp; Next we will create the ContextMenuStrip as well as the
  329. ContextMenuItem and add them (the ContextMenuStrip holds
  330. ContextMenuItems).&nbsp; Next we setup the ContextMenuItem's click
  331. event to call the OnExitClick method, which will close our
  332. application.&nbsp; Having setup the ContextMenuStrip and it's
  333. ContextMenuItem, we turn our attention to the NotifyIcon.&nbsp; We
  334. setup the NotifyIcon and associate the ContextMenuStrip with the
  335. NotifyIcon.&nbsp; The OnMsgButtonClick method displays the text in the
  336. TextBox just as in task 3.&nbsp; Next we define our OnExitClick method
  337. which closes the form to exit the application.&nbsp; This is followed by
  338. the definition of OnNotifyIconExit used to remove the notify icon after the
  339. application is closed. Lastly, we invoke Application.Run to launch our
  340. form into action. </p>
  341. <blockquote>
  342. <p class="Code-Background">import clr<br>
  343. clr.AddReference("System.Windows.Forms")<br>
  344. from System.Windows.Forms import *<br>
  345. clr.AddReference("System.Drawing")<br>
  346. from System.Drawing import *<br>
  347. import System<br>
  348. from System import *<br>
  349. <br>
  350. &nbsp;&nbsp;&nbsp; class FormV4(Form):<br>
  351. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  352. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  353. self.Text = 'Hello World'<br>
  354. <br>
  355. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  356. Create Label<br>
  357. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  358. self.Controls.Add(Label(Text='Enter Message:'))<br>
  359. <br>
  360. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  361. Create TextBox<br>
  362. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  363. self.txtMessage = TextBox(Left=100)<br>
  364. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  365. self.Controls.Add(self.txtMessage)<br>
  366. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
  367. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  368. Create Button<br>
  369. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  370. msgButton = Button(Text='Message', Left =20, Top=25)<br>
  371. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  372. msgButton.Click += self.OnMsgButtonClick<br>
  373. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  374. self.Controls.Add(msgButton)<br>
  375. &nbsp;</p>
  376. <p class="Code-Highlighted"> <br>
  377. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  378. Create Component Container <br>
  379. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  380. self._components = System.ComponentModel.Container()<br>
  381. <br>
  382. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # <br>
  383. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  384. Add component - ContextMenu<br>
  385. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  386. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  387. self._contextMenuStrip1 = ContextMenuStrip(self._components)<br>
  388. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  389. self._exitToolStripMenuItem = ToolStripMenuItem(Text='Exit')<br>
  390. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  391. self._contextMenuStrip1.Items.Add(self._exitToolStripMenuItem)<br>
  392. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  393. self._exitToolStripMenuItem.Click += self.OnExitClick<br>
  394. <br>
  395. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  396. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  397. add Component - NotifyIcon<br>
  398. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  399. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  400. self._notifyIcon1 =
  401. NotifyIcon(self._components,Visible=True,Text='Test')<br>
  402. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  403. self._notifyIcon1.Icon = Icon("Winforms\\app.ico")<br>
  404. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  405. self._notifyIcon1.ContextMenuStrip = self._contextMenuStrip1<br>
  406. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  407. self.Closed += self.OnNotifyIconExit<br>
  408. &nbsp;</p>
  409. <p class="Code-Background"> <br>
  410. &nbsp;&nbsp;&nbsp;&nbsp; def OnMsgButtonClick(self, *args):<br>
  411. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  412. MessageBox.Show(self.txtMessage.Text,"Message")<br>
  413. &nbsp;</p>
  414. <p class="Code-Highlighted"> <br>
  415. &nbsp;&nbsp;&nbsp;&nbsp; def OnExitClick(self, *args):<br>
  416. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.Close()<br><br>
  417. &nbsp;&nbsp;&nbsp;&nbsp; def OnNotifyIconExit(self, *args):<br>
  418. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._notifyIcon1.Dispose()<br>
  419. &nbsp;</p>
  420. <p class="Code-Background"> <br>
  421. Application.Run(FormV4())<br>
  422. &nbsp;</p>
  423. </blockquote>
  424. <p class="Step">1. Now let's try the Windows Form application by
  425. launching the IronPython script from a cmd.exe window:</p>
  426. <p class="TypedExample">ipyw.exe winforms\formV4.py</p>
  427. <p class="Step"><br>
  428. </p>
  429. <p class="Step">You should see the following window pop up on your
  430. screen:</p>
  431. <p class="Step">&nbsp;</p>
  432. <p class="Body"><img src="WinForms/FormV4.jpg" border="0"></p>
  433. <p class="Body">&nbsp;</p>
  434. <p class="Step">Additionally you should see the following icon in your
  435. system tray.&nbsp; If you place your mouse over the icon the text
  436. 'test' will appear.&nbsp; If you right click on the icon the context
  437. menu will appear.&nbsp; Selecting 'Exit' will cause the application to
  438. close.</p>
  439. <span style="font-size: 12pt; font-family: 'Times New Roman',serif;">
  440. <img src="WinForms/FormV4-1.JPG" border="0" height="45" width="60">&nbsp;&nbsp;&nbsp;&nbsp;
  441. <img src="WinForms/FormV4-2.JPG" border="0" height="48" width="111"></span>
  442. <p class="Body">&nbsp;</p>
  443. <h3>Task 5:&nbsp; <a name="T1.1.5">Use Layout Panels to Automatically
  444. Layout Controls (formV5.py)</a></h3>
  445. <p class="Body">Task 5 has the same basic UI that task 4 had which was
  446. a form with a Label, TextBox, and Button.&nbsp; Task 5 also includes
  447. the NotifyIcon, ContextMenuStrip, and ContextMenuItem components.&nbsp;
  448. The big change in task 5 is that we begin to use layout panels to make
  449. it easier to layout controls.&nbsp; For example, in task 4 we had to go
  450. through the effort of setting the location of the Label, TextBox, and
  451. Button.&nbsp; Typically it takes some trial and error to make sure the
  452. controls are placed correctly.&nbsp; Instead, we use a FlowLayoutPanel
  453. to automatically place the controls.&nbsp; As the name implies the
  454. controls are flowed as space allows.</p>
  455. <p class="Body">The best way to illustrate this is an example.&nbsp;
  456. Notice that in the image on the left below that there is not enough
  457. room to display all the controls horizontally, so they are stacked to
  458. fit vertically.&nbsp; In the image on the right below there is enough
  459. space to horizontally place all the controls so the FlowLayout Panel
  460. does so.&nbsp; So the FlowLayoutPanel can actually reposition controls
  461. as the form resizes.&nbsp;&nbsp;&nbsp; </p>
  462. <p class="Body">Other than the order in which the controls are created,
  463. the only different lines of code from the previous task are creating
  464. the FlowLayoutPanel and adding the controls to it.&nbsp; Also, we add
  465. the FlowLayoutPanel to the Form's controls.</p>
  466. <p class="Body">&nbsp;</p>
  467. <p class="Body"><img src="WinForms/FormV5-1.jpg" border="0">&nbsp;&nbsp;&nbsp;
  468. <img src="WinForms/FormV5-2.jpg" border="0" height="300" width="315"></p>
  469. <p class="Body">&nbsp;</p>
  470. <p class="Code-Background">import clr<br>
  471. clr.AddReference("System.Windows.Forms")<br>
  472. clr.AddReference("System.Drawing")<br>
  473. from System.Windows.Forms import *<br>
  474. from System.Drawing import *<br>
  475. import System<br>
  476. from System import *<br>
  477. <br>
  478. &nbsp;&nbsp;&nbsp; class FormV5(Form):<br>
  479. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  480. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  481. self.Text = 'Hello World'</p>
  482. <p class="Code-Background">&nbsp;</p>
  483. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  484. self.txtMessage = TextBox()<br>
  485. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  486. msgButton = Button(Text='Message')<br>
  487. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  488. msgButton.Click += self.OnmsgButtonClick<br>
  489. <br>
  490. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # <br>
  491. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  492. Create FlowPanelLayout and add controls<br>
  493. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  494. <br>
  495. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  496. self._flowLayoutPanel1 = FlowLayoutPanel(Dock = DockStyle.Fill)<br>
  497. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  498. self._flowLayoutPanel1.Controls.Add(Label(Text='Enter Message:'))<br>
  499. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  500. self._flowLayoutPanel1.Controls.Add(self.txtMessage)<br>
  501. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  502. self._flowLayoutPanel1.Controls.Add(msgButton)<br>
  503. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  504. self.Controls.Add(self._flowLayoutPanel1)<br>
  505. &nbsp;</p>
  506. <p class="Code-Background">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  507. self._components = System.ComponentModel.Container()<br>
  508. <br>
  509. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # <br>
  510. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  511. Add component - ContextMenu<br>
  512. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  513. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  514. self._contextMenuStrip1 = ContextMenuStrip(self._components)<br>
  515. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  516. self._exitToolStripMenuItem = ToolStripMenuItem(Text='Exit')<br>
  517. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  518. self._exitToolStripMenuItem.Click += self.OnExitClick<br>
  519. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  520. self._contextMenuStrip1.Items.Add(self._exitToolStripMenuItem)<br>
  521. <br>
  522. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  523. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  524. add Component - NotifyIcon<br>
  525. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>
  526. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  527. self._notifyIcon1 =
  528. NotifyIcon(self._components,Visible=True,Text='Test')<br>
  529. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  530. self._notifyIcon1.Icon = Icon("Winforms\\app.ico")<br>
  531. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  532. self._notifyIcon1.ContextMenuStrip = self._contextMenuStrip1<br>
  533. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  534. self.Closed += self.OnNotifyIconExit<br>
  535. <br>
  536. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnmsgButtonClick(self,
  537. *args):<br>
  538. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  539. MessageBox.Show(self.txtMessage.Text,"Message")<br>
  540. <br>
  541. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnExitClick(self, *args):<br>
  542. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  543. self.Close()<br><br>
  544. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnNotifyIconExit(self, *args):<br>
  545. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._notifyIcon1.Dispose()<br></p>
  546. <p class="Code-Background">
  547. <br>
  548. Application.Run(FormV5())<br>
  549. <br>
  550. &nbsp;</p>
  551. <p class="Step">1. Now let's try the Windows Form application by
  552. launching the IronPython script from a cmd.exe window:</p>
  553. <p class="TypedExample">ipyw.exe winforms\formV5.py</p>
  554. <p class="Step">&nbsp;</p>
  555. <h3>Task 6:&nbsp; <a name="T1.1.6">Add a Web Browser to the Form
  556. (formV6.py)</a></h3>
  557. <p class="Step">Task 6 takes our basic form with a Label, TextBox, and
  558. a Button, but now we add a WebBrowser control to make a very simple web
  559. browser.&nbsp; Continuing on the theme from task 5, we want to build an
  560. application with a sophisticated UI with little work to position
  561. controls.</p>
  562. <p class="Step">We will introduce a TabelLayoutPanel that will allow
  563. the area of the application containing the Label, TextBox, and Button
  564. to stay roughly the same size while allowing the web browser to fill up
  565. any remaining space in the form.&nbsp; The TableLayoutPanel allows the
  566. form to be broken up into rows and columns.&nbsp; The __init__ method
  567. starts with the creation all of the controls -- first the
  568. TableLayoutPanel and FlowLayout Panel, followed by the WebBrowser,
  569. Label, TextBox, and Button.&nbsp; We set the TextBox's size to allow
  570. for a lengthier URL to be entered.</p>
  571. <p class="Step">We introduce the StatusStrip at the bottom of the form
  572. where status information can be displayed.&nbsp; Within the StatusStrip
  573. a StatusStripLabel is created so that text information can be
  574. displayed.&nbsp; The StatusStripLabel will be used to display the URL
  575. of the site being displayed in the web browser.</p>
  576. <p class="Step">Next the form's AcceptButton is set so that if the user
  577. hits enter, the button will be clicked.</p>
  578. <p class="Step">We set the rows and columns for the TableLayoutPanel
  579. and add controls to it.&nbsp; We add the appropriate controls to the
  580. FlowLayoutPanel.</p>
  581. <p class="Step">The OnMsgButtonClick method will be called in response
  582. to a button click.&nbsp; This method causes the URL supplied in the
  583. TextBox to be loaded.&nbsp; It displays the value in the TextBox that
  584. is in the StatusStripLabel, and the method clears the TextBox.</p>
  585. <p class="Code-Background">import clr<br>
  586. clr.AddReference("System.Windows.Forms")<br>
  587. clr.AddReference("System.Drawing")<br>
  588. from System.Windows.Forms import *<br>
  589. from System.Drawing import *<br>
  590. import System<br>
  591. from System import *<br>
  592. <br>
  593. &nbsp;&nbsp;&nbsp; class FormV6(Form):<br>
  594. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):</p>
  595. <p class="Code-Background">&nbsp;</p>
  596. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  597. # setup TableLayoutPanel and FlowLayoutPanel<br>
  598. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  599. self._tableLayoutPanel1 = TableLayoutPanel(ColumnCount = 1,RowCount =
  600. 2, Dock = DockStyle.Fill)<br>
  601. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  602. self._flowLayoutPanel1 = FlowLayoutPanel(Dock = DockStyle.Fill)<br>
  603. &nbsp;</p>
  604. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  605. self._webBrowser = WebBrowser(Dock = DockStyle.Fill)<br>
  606. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  607. self._label1 = Label(Text ='Enter Message')<br>
  608. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  609. self._txtMessage = TextBox(TabIndex = 0,Size = Size(200,20))<br>
  610. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  611. self._button1 = Button(Text ='Message')<br>
  612. &nbsp;</p>
  613. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  614. # Setup ToolStrip and ToolStripLabel<br>
  615. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  616. self._StatusStrip1 = StatusStrip()<br>
  617. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  618. self._ToolStripStatusLabel1 = ToolStripStatusLabel()<br>
  619. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  620. self._StatusStrip1.Items.Add(self._ToolStripStatusLabel1)<br>
  621. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  622. self.Controls.Add(self._StatusStrip1)<br>
  623. &nbsp;</p>
  624. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  625. self.AcceptButton = self._button1&nbsp;&nbsp; # when the enter key is
  626. pressed self._button1 will be clicked<br>
  627. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  628. self._button1.Click += self.OnmsgButtonClick<br>
  629. &nbsp;</p>
  630. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  631. # Set TableLayoutPanel column and row styles and add FlowLayoutPanel
  632. and Web Browser</p>
  633. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  634. self._tableLayoutPanel1.ColumnStyles.Add(ColumnStyle(SizeType.Percent,
  635. 100.0))<br>
  636. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  637. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute, 80.0))<br>
  638. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  639. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Percent, 100.0))<br>
  640. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  641. self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel1, 0, 0)<br>
  642. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  643. self._tableLayoutPanel1.Controls.Add(self._webBrowser, 0, 1)<br>
  644. &nbsp;</p>
  645. <p class="Code-Highlighted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  646. # add controls that will be contained in FlowLayoutPanel<br>
  647. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  648. self._flowLayoutPanel1.Controls.Add(self._label1)<br>
  649. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  650. self._flowLayoutPanel1.Controls.Add(self._txtMessage)<br>
  651. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  652. self._flowLayoutPanel1.Controls.Add(self._button1)<br>
  653. <br>
  654. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  655. self.Controls.Add(self._tableLayoutPanel1)<br>
  656. <br>
  657. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def OnmsgButtonClick(self,
  658. *args):<br>
  659. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  660. self._webBrowser.Navigate(self._txtMessage.Text)<br>
  661. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  662. self._ToolStripStatusLabel1.Text = self._txtMessage.Text<br>
  663. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  664. self._txtMessage.Text = ""<br>
  665. &nbsp;</p>
  666. <p class="Code-Background">
  667. <br>
  668. Application.Run(FormV6())</p>
  669. <p class="Body"><br>
  670. &nbsp;</p>
  671. <p class="Step">1. Now let's try the Windows Form application by
  672. launching the IronPython script from a cmd.exe window:</p>
  673. <p class="TypedExample">ipyw.exe winforms\formV6.py</p>
  674. <p class="Step"><br>
  675. </p>
  676. <p class="Step">You should see the following window pop up on your
  677. screen.&nbsp; If you type in a valid URL and hit enter, the web browser
  678. control displays the selected web page.</p>
  679. <p class="Step">&nbsp;</p>
  680. <p class="Body"><img src="WinForms/FormV6-1.jpg" border="0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  681. <img src="WinForms/FormV6.jpg" border="0"></p>
  682. <p class="Body">&nbsp;</p>
  683. <h3>Task 7:&nbsp; <a name="T1.1.7">Displaying a Map Picture with Data
  684. from MapPoint (formV7.py)</a></h3>
  685. <p class="Step">Task 7 takes our basic form with a Label, TextBox, and
  686. a Button, but now we add a PictureBox control.&nbsp; We will leverage
  687. the approach from Task 6 and use a TableLayoutPanel and FlowLayoutPanel
  688. to make laying out our form easy.&nbsp; We will use the PictureBox to
  689. display a map.&nbsp; The user will enter a landmark or address in the
  690. TextBox, and we will use MapPoint Web Services to render a map of that
  691. location.&nbsp; We will be using a C# assembly named
  692. MapPointWebServiceProject.dll to provide access to MapPoint Web
  693. Services.&nbsp; </p>
  694. <blockquote>
  695. <p class="Step">MapPointWebServiceProject.dll has already been built for you,
  696. but you are more than welcome to rebuild it.&nbsp; To build this DLL,
  697. open a command prompt and run &quot;%WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild
  698. /p:configuration=Release MapPointWebServiceProject.sln&quot; from the winformsmappoint\winforms\
  699. directory.&nbsp;
  700. Next simply copy winformsmappoint\winforms\bin\release\mappointwebservicesproject.dll to the winformsmappoint\ directory.</p>
  701. </blockquote>
  702. <p class="Step">This task and the next contact Microsoft MapPoint servers
  703. remotely.&nbsp; Information sent to the MapPoint servers include a username and
  704. password along with your IP address and the text entered into the TextBox in the
  705. sample interface.&nbsp; No information is sent remotely until the user clicks on
  706. the &quot;Get map&quot; button or presses the enter key at which point the aforementioned
  707. data will be sent via SOAP over HTTP, which is not encrypted in any way.</p>
  708. <p class="Step"><strong>We will be using a MapPoint UserID of 5200 and password
  709. of "ned68Fe".&nbsp; You can find info on applying for your own MapPoint Web Service
  710. account here <a href="http://www.microsoft.com/mappoint/en-us/default.aspx">
  711. http://www.microsoft.com/mappoint/en-us/default.aspx</a></strong>.</p>
  712. <p class="Step">The first few lines of are the same as most of the
  713. previous examples.&nbsp; We add a reference to the
  714. MapPointWebServiceProject.dll so that we can use it inside our program
  715. and add the appropriate imports so we can use the classes in
  716. MapPointWebServiceProject as well as the underlying classes the
  717. MapPoint Web Services expose (such as Location and Route).&nbsp; </p>
  718. <p class="Step">Next we create the TabelLayoutPanel and FlowLayoutPanel
  719. as well as creating the required controls such as Label, TextBox and
  720. Button.&nbsp; We setup the row and column characteristics for the
  721. TableLayoutPanel and add the controls to it.&nbsp; Then we add the
  722. controls to the FlowLayoutPanel.</p>
  723. <p class="Step">All of the event handling is done in
  724. OnMsgButtonClick.&nbsp; When the button is pressed we create the
  725. MapPointWebServiceHelper by calling
  726. MapPointWebServiceHelper.GetInstance and pass it our UserID and password.&nbsp; Please note that when writing your own scripts <span
  727. style="font-weight: bold;">you should never hard code usernames or
  728. passwords</span>. We attempt to find a location using the
  729. MapPointWebServiceHelper.FindLocation method.&nbsp; If we are
  730. successful we call the MapPointWebServiceHelper.GetMap method and
  731. display the map.&nbsp; If the location can't be found we display a
  732. message stating we couldn't find the location.&nbsp; Finally we call
  733. application run to initiate the application.</p>
  734. <p class="Code-Background">import clr<br>
  735. clr.AddReference("System.Windows.Forms")<br>
  736. clr.AddReference("System.Drawing")<br>
  737. from System.Windows.Forms import *<br>
  738. from System.Drawing import *<br>
  739. import System<br>
  740. from System import *<br>
  741. &nbsp;</p>
  742. <p class="Code-Background">clr.AddReferenceToFile("MapPointWebServiceProject.dll")<br>
  743. from MapPointWebServiceProject import *<br>
  744. from MapPointWebServiceProject.net.mappoint.staging import *<br>
  745. <br>
  746. <br>
  747. &nbsp;&nbsp;&nbsp; class FormV7(Form):<br>
  748. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  749. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  750. Create TableLayoutPanel and FlowLayoutPanel <br>
  751. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  752. self._tableLayoutPanel1 = TableLayoutPanel(ColumnCount = 1,Dock =
  753. DockStyle.Fill,RowCount = 2)<br>
  754. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  755. self._flowLayoutPanel1 = FlowLayoutPanel(Dock = DockStyle.Fill)<br>
  756. <br>
  757. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  758. Create Controls<br>
  759. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  760. self._pictureBox1 = PictureBox(Dock = DockStyle.Fill)<br>
  761. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  762. self._label1 = Label(Text ='Enter location:',AutoSize=True)<br>
  763. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  764. self._txtLocation = TextBox()<br>
  765. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  766. self._button1 = Button(Text ='Get map',AutoSize=True)<br>
  767. <br>
  768. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  769. Setup TableLayoutPanel rows and columns and add controls<br>
  770. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  771. self._tableLayoutPanel1.ColumnStyles.Add(ColumnStyle(SizeType.Percent,
  772. 100.0))<br>
  773. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  774. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute, 45.0))<br>
  775. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  776. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Percent, 100.0))<br>
  777. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  778. self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel1, 0, 0)<br>
  779. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  780. self._tableLayoutPanel1.Controls.Add(self._pictureBox1, 0, 1)<br>
  781. <br>
  782. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  783. Add controls to FlowLayoutPanel<br>
  784. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  785. self._flowLayoutPanel1.Controls.Add(self._label1)<br>
  786. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  787. self._flowLayoutPanel1.Controls.Add(self._txtLocation)<br>
  788. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  789. self._flowLayoutPanel1.Controls.Add(self._button1)<br>
  790. <br>
  791. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  792. self.AcceptButton = self._button1<br>
  793. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  794. self._button1.Click += self.OnMsgButtonClick<br>
  795. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  796. self.Controls.Add(self._tableLayoutPanel1)<br>
  797. <br>
  798. &nbsp;&nbsp;&nbsp; def OnMsgButtonClick(self, *args):<br>
  799. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try:</p>
  800. <p class="Code-Background">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  801. mapHelper = MapPointWebServiceHelper.GetInstance("5200", "ned68Fe")<br>
  802. &nbsp;<br>
  803. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loc
  804. = mapHelper.FindLocation(self._txtLocation.Text)<br>
  805. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
  806. loc:<br>
  807. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  808. self._pictureBox1.Image = mapHelper.GetMap(loc,
  809. self._pictureBox1.Width, \</p>
  810. <p class="Code-Background">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  811. self._pictureBox1.Height, 4.0)<br>
  812. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>
  813. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  814. MessageBox.Show("Address or location is not valid","Invalid Location")<br>
  815. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; except Exception, e:<br>
  816. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  817. MessageBox.Show(e.Message,"MapPoint Exception")<br>
  818. &nbsp;</p>
  819. <p class="Code-Background">Application.Run(FormV7())<br>
  820. &nbsp;</p>
  821. <p class="Step">1. Now let's try the Windows Form application by
  822. launching the IronPython script from a cmd.exe window:</p>
  823. <p class="TypedExample">ipyw.exe winforms\formV7.py</p>
  824. <p class="Step">You should see the following window pop up on your
  825. screen.&nbsp; If you type well known landmarks (Sears Tower, Navy Pier)
  826. or a valid address, then a map will be rendered.&nbsp; If you expand or
  827. contract the form and hit the Get Map button, the map will update to
  828. fit within the allocated space.</p>
  829. <p class="Step">&nbsp;</p>
  830. <p class="Body"><img src="WinForms/FormV7-1.jpg" border="0">&nbsp;&nbsp;&nbsp;&nbsp;
  831. <img src="WinForms/FormV7-2.jpg" border="0">&nbsp;&nbsp;</p>
  832. <p class="Body">&nbsp;</p>
  833. <p class="Body">&nbsp;<img src="WinForms/FormV7-3.jpg" border="0"></p>
  834. <h3>Task 8:&nbsp; <a name="T1.1.8">Add Route-finding to the Map
  835. Application (formV8.py)</a></h3>
  836. <p class="Step">Task 8 takes our task 7 and expands it by allowing us
  837. to specify start and end locations, and then generate a route
  838. map.&nbsp; We will leverage previous tasks and use a TableLayoutPanel
  839. and FlowLayoutPanel to make laying out our form easy.&nbsp; We will use
  840. the PictureBox to display a map.&nbsp; </p>
  841. <p class="Step">NOTE: See Task 7 to build and set up the
  842. MapPointWebServiceProject.dll for this task.&nbsp; If you performed
  843. task 7, you're fine to proceed.</p>
  844. <p class="Step">Like task 7, this task contacts Microsoft MapPoint servers
  845. remotely.&nbsp; Information sent to the MapPoint servers include a username and
  846. password along with your IP address and the text entered into the TextBoxes in
  847. the sample interface.&nbsp; No information is sent remotely until the user
  848. clicks on the &quot;Get map&quot; button or presses the enter key at which point the
  849. aforementioned data will be sent via SOAP over HTTP, which is not encrypted in
  850. any way.</p>
  851. <p class="Step">The first few lines of Task 8 are the same as most of
  852. the previous examples.&nbsp; We add a reference to the
  853. MapPointWebServiceProject.dll so that we can use it inside our
  854. program.&nbsp; Then we add the appropriate Python import statements so
  855. we can use the classes in MapPointWebServiceProject.dll and classes the
  856. MapPoint Web Services exposes (such as Location and Route).&nbsp; </p>
  857. <p class="Step">Next we create the TabelLayoutPanel and two
  858. FlowLayoutPanel's.&nbsp; The first FlowLayoutPanel is for the control
  859. related to specifying the starting location.&nbsp; The second
  860. FlowLayoutPanel is for the Label, TextBox, and Button used to specify
  861. the ending location.&nbsp; We setup the row and column characteristics
  862. for the TableLayoutPanel and add the controls to it.&nbsp; Then we add
  863. the appropriate controls to our two FlowLayoutPanels.</p>
  864. <p class="Step">All of the event handling is done within
  865. OnMsgButtonClick.&nbsp; When the button is pressed we create the
  866. MapPointWebServiceHelper by calling
  867. MapPointWebServiceHelper.GetInstance and pass it our UserID and
  868. password.&nbsp; We will be using a MapPoint UserID of 5200 and password
  869. of "ned68Fe".&nbsp; Please note that when writing your own scripts <span
  870. style="font-weight: bold;">you should never hard code usernames or
  871. passwords</span>.&nbsp; You can find out how to apply for your own MapPoint Web Service
  872. account here <a href="http://www.microsoft.com/mappoint/en-us/default.aspx">
  873. http://www.microsoft.com/mappoint/en-us/default.aspx</a>.&nbsp;
  874. We attempt to find our starting location using the
  875. MapPointWebServiceHelper.FindLocation method.&nbsp; Next we attempt to
  876. find our ending location by calling the
  877. MapPointWebServiceHelper.FindLocation method again.&nbsp; If a location
  878. can't be found, the helper class throws an exception, which we handle
  879. by displaying a message.&nbsp; If both locations are found, then we
  880. will call MapPointWebServiceHelper.GetRouteMap to get our route
  881. map.&nbsp; If we are successful, we will display a route map, and if
  882. not, an error message is displayed.</p>
  883. <p class="Step">Finally, we call application run to initiate the
  884. application.</p>
  885. <p class="Step">&nbsp;</p>
  886. <p class="Code-Background">import clr<br>
  887. clr.AddReference("System.Windows.Forms")<br>
  888. clr.AddReference("System.Drawing")<br>
  889. from System.Windows.Forms import *<br>
  890. from System.Drawing import *<br>
  891. import System<br>
  892. from System import *<br>
  893. &nbsp;</p>
  894. <p class="Code-Background">clr.AddReferenceToFile("MapPointWebServiceProject.dll")<br>
  895. from MapPointWebServiceProject import *<br>
  896. from MapPointWebServiceProject.net.mappoint.staging import *<br>
  897. <br>
  898. <br>
  899. &nbsp;&nbsp;&nbsp; class FormV8(Form):<br>
  900. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>
  901. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  902. Create TableLayoutPanel and FlowLayoutPanel <br>
  903. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  904. self._tableLayoutPanel1 = TableLayoutPanel(ColumnCount = 1,Dock =
  905. DockStyle.Fill,RowCount = 3)<br>
  906. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  907. self._flowLayoutPanel1 = FlowLayoutPanel(Dock = DockStyle.Fill)<br>
  908. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  909. self._flowLayoutPanel2 = FlowLayoutPanel(Dock = DockStyle.Fill)<br>
  910. <br>
  911. <br>
  912. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  913. controls for FlowLayout Start<br>
  914. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  915. self._label1 = Label(Text ='Enter start location:',AutoSize=True)<br>
  916. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  917. self._txtFromLocation = TextBox()<br>
  918. <br>
  919. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  920. controls for FlowLayout End<br>
  921. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  922. self._label2 = Label(Text ='Enter end location:',AutoSize=True)<br>
  923. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  924. self._txtToLocation = TextBox()<br>
  925. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  926. self._button1 = Button(Text ='Get map',AutoSize=True)<br>
  927. <br>
  928. <br>
  929. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  930. this will hold our route map<br>
  931. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  932. self._pictureBox1 = PictureBox(Dock = DockStyle.Fill)<br>
  933. <br>
  934. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
  935. Setup TableLayoutPanel rows and columns and add controls<br>
  936. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  937. self._tableLayoutPanel1.ColumnStyles.Add(ColumnStyle(SizeType.Percent,
  938. 100.0))<br>
  939. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  940. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute, 40.0))<br>
  941. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  942. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute, 60.0))<br>
  943. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  944. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Percent, 100.0))<br>
  945. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  946. self._tableLayoutPanel1.Controls.Add(self._flowLayout