{"id":9548,"date":"2015-07-16T09:00:00","date_gmt":"2015-07-16T16:00:00","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=9548"},"modified":"2016-07-20T12:21:34","modified_gmt":"2016-07-20T19:21:34","slug":"powershell-guis-where-do-i-start","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2015\/07\/16\/powershell-guis-where-do-i-start\/","title":{"rendered":"PowerShell GUIs: Where do I start?"},"content":{"rendered":"<p><a class=\"twitter-follow-button\" href=\"https:\/\/twitter.com\/juneb_get_help\" data-lang=\"en\">Follow @juneb_get_help<\/a><\/p>\n<p>I&#8217;ve been using Windows PowerShell since the very first version of Monad in 2005, but PowerShell-based applications with a graphic user interface (GUI) are a whole new world. Instead of thinking of cmdlets and parameters or properties and methods, you need to think in object events. And because there&#8217;s no console with .ps1xml-directed views, you need manage all output streams, including standard output and errors.<\/p>\n<p>Most importantly, because you&#8217;re dealing with real users, you need to assume that people will type and click whatever they please in whatever order you let them. It reminds me of turning the car over to my teenagers for the first time. In a GUI app, the user drives. So, if you don&#8217;t want them to go somewhere, you need to enable and reveal parts of the interface selectively.<\/p>\n<p>PowerShell Studio automates the complex parts, including loading assemblies, instantiating objects, and registering event handlers, so you can focus on making great PowerShell GUI apps.<\/p>\n<blockquote><p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/07\/image10.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/07\/image_thumb6.png\" alt=\"image\" width=\"239\" height=\"190\" border=\"0\" \/><\/a><\/p><\/blockquote>\n<p>Here are some of the fabulous resources that I used to help me learn how to create PowerShell GUIs. If you have a favorite book, tutorial, or blog post, comment and I&#8217;ll add it to this post.<\/p>\n<h1><\/h1>\n<h1>My First PowerShell GUI<\/h1>\n<p>If you&#8217;re starting from scratch, start here:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=BAi81bOjYlQ\" target=\"_blank\">My First Form: Build a Simple PowerShell GUI app with PowerShell Studio<\/a>\u00a0by SAPIEN Tech (video)<br \/>\nFollow along as we build a simple GUI app that displays the versions of Windows and Windows PowerShell on the local computer.<\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=BIAjbP-eQUw\" target=\"_blank\">My First Form: Controls and Properties<\/a>\u00a0by SAPIEN Tech (video)<br \/>\nLearn about the Windows Forms controls that you use in a GUI application and how to set their property values.<\/li>\n<li><a href=\"http:\/\/powershell-enthusiast.blogspot.com\/2013\/07\/building-gui-for-powershell-scripts.html\" target=\"_blank\">Building GUI for PowerShell Scripts using PowerShell Studio 2012<\/a> by <a href=\"https:\/\/twitter.com\/vinithmenon28\" target=\"_blank\">Vinith Menon<\/a><br \/>\nStep-by-step instructions for creating a GUI app that runs Get-WMIObject commands<\/li>\n<li><a href=\"http:\/\/www.lazywinadmin.com\/2013\/10\/powershell-studio-2012-winforms.html\" target=\"_blank\">PowerShell Studio 2012 &#8211; WinForms &#8211; Creating a basic GUI<\/a> by <a href=\"https:\/\/twitter.com\/LazyWinAdm\" target=\"_blank\">Francois-Xavier Cat<\/a><br \/>\nA multi-part video tutorial on making a GUI for any script<\/li>\n<li><a href=\"http:\/\/www.manning.com\/jones4\/\" target=\"_blank\">Learn Windows PowerShell Toolmaking in a Month of Lunches<\/a> by Don Jones and Jeffery Hicks<br \/>\nIn Chapters 23 \u2013 25, Don and Jeff build a GUI tool from scratch, first by using Windows Forms classes and then in PowerShell Studio.<\/li>\n<li><a href=\"http:\/\/www.scconfigmgr.com\/2015\/07\/17\/windows-forms-powershell-gui-template\/\">Windows Forms PowerShell Gui Template<\/a> by Nickolaj Andersen<br \/>\nNickolaj provides a template for creating a form object in Windows PowerShell. PowerShell Studio does all of this work for you, but it&#8217;s useful to see and understand what goes on under the covers.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Basic GUI App Techniques<\/h1>\n<p>Now that you have the basics, avoid the most common errors encountered by scripters moving to GUI apps:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.sapien.com\/blog\/2014\/12\/15\/display-output-in-a-gui-application-copy\/\">Displaying Output in a GUI Application<\/a><br \/>\nThere&#8217;s no console or automatic display in a GUI app. If you don&#8217;t assign output to a UI element, the user never sees it.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/01\/15\/manage-errors-in-a-gui-application\/\">Managing <\/a><a href=\"https:\/\/www.sapien.com\/blog\/2015\/01\/15\/manage-errors-in-a-gui-application\/\">Errors in a GUI Application<\/a><br \/>\nOnce you&#8217;ve mastered standard output, learn your options for managing errors.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/01\/19\/creating-a-gui-for-csv-data\/\">Creating a GUI for CSV Data<\/a><br \/>\nLearn how to display data that originates in CSV format. Import-Csv and then&#8230; ?<\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=l412GmXouZs\">Create a PowerShell GUI with a Fixed-Size UI (video)<\/a><br \/>\nThe simplest GUIs have a form that the end-user can&#8217;t resize. Keep it simple!<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Easy, but Sophisticated<\/h1>\n<p>These easy and quick techniques make your GUI apps more usable. They take just minutes to master.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/04\/06\/adding-auto-complete-to-an-input-textbox\/\">Adding Auto-Complete to an Input Textbox<\/a><br \/>\nAuto-complete you textbox input dynamically based on the user&#8217;s file system, available web URLs, or custom data, like servers, services, and processes.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/05\/27\/copy-to-clipboard-in-a-gui-application\/\">Copy to Clipboard in a GUI Application<\/a><br \/>\nUse a one-liner to add a &#8220;Copy to Clipboard&#8221; button to any app. It&#8217;s a great companion to a output textbox.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/08\/17\/typing-enter-pushes-a-button\/\" target=\"_blank\">Typing Enter Pushes a Button<\/a><br \/>\nLet the user press Enter instead of having to click a button. Create a KeyDown event for a textbox or use the AcceptButton property of the form.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Apps with multiple windows<\/h1>\n<p>Mastered the basics? Try a multi-form application.<\/p>\n<ul>\n<li><a href=\"http:\/info.sapien.com\/index.php\/guis\/gui-scripting\/write-a-multi-form-powershell-gui-app\">Write a Multi-Form PowerShell GUI App<\/a><br \/>\nCreate a simple two-window application that gets text from a child form and displays it a parent form.<\/li>\n<li><a href=\"http:\/info.sapien.com\/index.php\/guis\/gui-scripting\/how-do-multi-form-projects-work\">How Do Multi-Form Projects Work?<\/a><br \/>\nBehind-the-scenes view of how PowerShell Studio features for multi-form projects work.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Best Practices for UI Design<\/h1>\n<p>Where do I put that button? Should I center the textbox? You might be new to GUI app development, but your GUI apps don&#8217;t have to advertise it. Learn from user experience and human factors engineers about best practices for UI design.<\/p>\n<ul>\n<li><strong>About Face: The Essentials of Interaction Design 4th Edition<\/strong> by Alan Cooper, Robert Reimann, David Cronin, &amp; Christopher Noessel<br \/>\nLearn the principles of UI design from people who study user-computer interaction. An excellent book for beginners and experienced designers.<\/li>\n<li><a href=\"https:\/\/www.linkedin.com\/pulse\/9-things-i-learned-ux-grad-school-sara-ford?trk=hb_ntf_MEGAPHONE_ARTICLE_POST\" target=\"_blank\">9 Things I Learned in UX Grad School<\/a> by <a href=\"https:\/\/twitter.com\/saraford\" target=\"_blank\">Sara Ford<\/a><br \/>\nSara summarizes the practical elements of academic UX research for the UI designer, including &#8220;Why &#8216;Developer Speak&#8217; in UI is so bad &#8221; and &#8220;Why people make errors&#8221;<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2012\/06\/04\/user-interface-design-for-administrators\/\">User Interface Design for Administrators<\/a><br \/>\nWhen do you use a button? When are radio buttons better than checkboxes? SAPIEN Chief Technology Officer, Alexander Riedel, creates a control table that you&#8217;ll refer to again and again.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2012\/06\/11\/single-form-or-multiple-dialogs\/\">Single Form or Multiple Dialogs?<\/a><br \/>\nHow much is too much on a single form? Learn the guidelines that professional UI developers use to make this critical decision.<\/li>\n<li><a href=\"https:\/\/uxdesign.cc\/design-better-forms-96fadca0f49c#.46p25zksd\">Design Better Forms<\/a> by <a href=\"http:\/\/andrewcoyle.com\/\">Andrew Coyle<\/a><br \/>\nGreat do&#8217;s and don&#8217;t&#8217;s from a professional UI designer.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/12\/23\/how-i-learned-to-love-dialogresult\/\" target=\"_blank\">How I learned to love DialogResult<\/a><br \/>\nThe DialogResult property closes my form abruptly. Why shouldn&#8217;t I just set its value\u00a0to &#8220;None?&#8221; Learn about the best-practice standards that DialogResult supports.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Those Nagging Questions<\/h1>\n<ul>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2016\/01\/04\/powershell-gui-apps-why-think-in-events\/\" target=\"_blank\">PowerShell GUI: Why think in events?<\/a><br \/>\nA PowerShell GUI application consists of an unordered collection of event handlers. It&#8217;s so different from traditional scripting that you learn to think in a whole new way.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/09\/09\/scope-in-a-powershell-gui-app\/\">Scope in a PowerShell GUI App<\/a><br \/>\nWhy does each event handler runs in its own scope? Learn how to share variables between event handlers.<\/li>\n<li><a href=\"https:\/\/www.sapien.com\/blog\/2015\/08\/31\/the-methods-that-register-events\/\">The Methods That Register Events<\/a><br \/>\nWhat&#8217;s the source of the methods that register events, like $buttonClose.add_Click()? MSDN\u00a0doesn&#8217;t list them and Get-Member doesn&#8217;t return them.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>Troubleshooting &amp; Debugging<\/h1>\n<ul>\n<li><a title=\"Permanent Link: PowerShell GUI Debugging Tip: Duplicate Event Handlers\" href=\"https:\/\/www.sapien.com\/blog\/2015\/09\/08\/gui-debugging-tip-duplicate-event-handlers\/\" rel=\"bookmark\">PowerShell GUI Debugging Tip: Duplicate Event Handlers<\/a><br \/>\nIf your event handler doesn&#8217;t work, verify the control names. If they&#8217;re correct, you might have a duplicate event handler.<\/li>\n<li><a href=\"https:\/\/wp.me\/p3tXTf-2Pl\" target=\"_blank\">How I Learned to Love DialogResult<\/a><br \/>\nIf your form closes immediately when you click OK (or another standard button), instead of staying open so that you can use it, it might be caused by\u00a0the value of the <strong>DialogResult<\/strong> property of the button.<\/li>\n<\/ul>\n<div><\/div>\n<h1><\/h1>\n<h1>One-A-Day:\u00a0 Explore the Windows Forms Controls<\/h1>\n<p>One of the best, and easiest, ways to learn the UI controls, is to read our Spotlight articles and try the examples. You can read the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/System.Windows.Forms(v=vs.110).aspx\" target=\"_blank\">MSDN documentation<\/a> about Windows Forms controls, but our <strong>Spotlight articles<\/strong>, designed for PowerShell scripters, focus on the most important features of each UI control, and get you going with PowerShell examples.<\/p>\n<p>Use your &#8220;Month of Lunches&#8221; habit to explore one new control each day.<\/p>\n<p>In PowerShell Studio, to open a Spotlight article about a control:<\/p>\n<ul>\n<li>In the Toolbox or Property pane, right-click a control and then click <strong>View Spotlight Article<\/strong>.<\/li>\n<li>Or, in the Designer window, right a control, click <strong>Help<\/strong>, and then click <strong>View Spotlight Article<\/strong>.<\/li>\n<\/ul>\n<blockquote><p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/07\/image11.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/07\/image_thumb7.png\" alt=\"image\" width=\"244\" height=\"228\" border=\"0\" \/><\/a><\/p><\/blockquote>\n<h3>Spotlight Articles:<\/h3>\n<ul>\n<li>\n<div align=\"left\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-controls-common-properties-and-methods\" target=\"_blank\">Common properties of many controls<\/a><\/div>\n<\/li>\n<\/ul>\n<blockquote>\n<table border=\"0\" width=\"400\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-form-control\" target=\"_blank\">Form<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-imagelist-control\" target=\"_blank\">ImageList<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-statusbar-control\" target=\"_blank\">StatusBar<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-button-control\" target=\"_blank\">Button<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-listview-control\" target=\"_blank\">ListView<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-statusstrip-control\" target=\"_blank\">StatusStrip<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-textbox-control\" target=\"_blank\">Textbox<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-maskedtextbox-control\" target=\"_blank\">MaskedTextBox<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-tabcontrol\" target=\"_blank\">TabControl<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-combobox-control\" target=\"_blank\">ComboBox<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-notifyicon-control\" target=\"_blank\">NotifyIcon<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-timer-control\" target=\"_blank\">Timer<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-checkbox-control\" target=\"_blank\">CheckBox<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-picturebox-control\" target=\"_blank\">PictureBox<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-tooltip-control\" target=\"_blank\">ToolTip<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-contextmenustrip-control\" target=\"_blank\">ContextMenuStrip<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-progressbar-control\" target=\"_blank\">ProgressBar<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-treeview-control\" target=\"_blank\">TreeView<\/a><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-errorprovider-control\" target=\"_blank\">ErrorProvider<\/a><\/td>\n<td valign=\"top\" width=\"133\"><a href=\"http:\/\/info.sapien.com\/index.php\/guis\/gui-controls\/spotlight-on-the-radiobutton-control\" target=\"_blank\">RadioButton<\/a><\/td>\n<td valign=\"top\" width=\"133\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p><\/blockquote>\n<h1><\/h1>\n<p>&nbsp;<\/p>\n<p>If you have suggestions that might help other scripters, leave a comment or tweet it to me at <a href=\"http:\/\/twitter.com\/juneb_get_help\" target=\"_blank\">@juneb_get_help<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Follow @juneb_get_help I&#8217;ve been using Windows PowerShell since the very first version of Monad in 2005, but PowerShell-based applications with a graphic user interface (GUI) are a whole new world. Instead of thinking of cmdlets and parameters or properties and methods, you need to think in object events. And because there&#8217;s no console with .ps1xml-directed [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[932,946,703,644,25],"tags":[1022,934,28],"class_list":["post-9548","post","type-post","status-publish","format-standard","hentry","category-beginners","category-guiprogramming","category-powershell-studio","category-spotlight-on-controls","category-windows-powershell","tag-guiprogramming","tag-juneb","tag-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/9548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=9548"}],"version-history":[{"count":34,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/9548\/revisions"}],"predecessor-version":[{"id":12758,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/9548\/revisions\/12758"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=9548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=9548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=9548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}