{"id":3193,"date":"2011-07-14T09:54:00","date_gmt":"2011-07-14T17:54:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3193"},"modified":"2011-07-14T09:54:24","modified_gmt":"2011-07-14T17:54:24","slug":"primalforms-2011-spotlight-on-the-progressbar-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/07\/14\/primalforms-2011-spotlight-on-the-progressbar-control\/","title":{"rendered":"PrimalForms 2011: Spotlight on the ProgressBar Control"},"content":{"rendered":"<p>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.<\/p>\n<p>Last time we took a look at the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/07\/08\/primalforms-2011-spotlight-on-the-radiobutton-control\/\">RadioButton<\/a> control. This time we will look at the ProgressBar control:<\/p>\n<p><span style=\"font-size: medium\"><strong>ProgressBar Control <\/strong>[System.Windows.Forms.ProgressBar]<\/span><\/p>\n<p>Represents a Windows progress bar control.<\/p>\n<p>Default Event: Click<\/p>\n<p><em>Why use a ProgressBar control?<\/em><\/p>\n<p>Use a ProgressBar when you need to show the user that progress is being made in some operation, such as copying files.<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>Maximum<\/strong>  <\/p>\n<\/td>\n<td width=\"330\">The Maximum is the upper bound of the range this ProgressBar is working with.  <\/p>\n<p><em>Why use the Maximum property?<\/em>  <\/p>\n<p>Use the Maximum property when you have a known limit for your ProgressBar. When the Value property is equal to the value of the Maximum property, the progress bar is completely filled.  <\/p>\n<p>Example of setting the Maximum property in the Script Editor:<\/p>\n<pre><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.Maximum <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\">.Count<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>Values (Default: <em>100<\/em>):<\/p>\n<blockquote>\n<p>Any Integer value [Int32]<\/p>\n<\/blockquote>\n<p><strong>Minimum<\/strong> <\/p>\n<\/td>\n<td width=\"330\">The Minimum is the lower bound of the range this ProgressBar is working with. When the Value property is equal to the value of the Minimum property, the ProgressBar will be empty. <\/p>\n<p>Values (Default: <em>0<\/em>): <\/p>\n<blockquote>\n<p>Any Integer value [Int32]<\/p>\n<\/blockquote>\n<p><strong>Step<\/strong> <\/p>\n<\/td>\n<td width=\"330\">The Step is the amount to increment the current value of the ProgressBar by when the PerformStep() method is called. <\/p>\n<p><em>Why use the Step property?<\/em> <\/p>\n<\/td>\n<p>Use the Step property to specify the amount that each completed task in an operation changes the value of the progress bar.&nbsp; The Step property default value is 10, so you may want to set the step to 1 when necessary. <\/p>\n<p>Values (Default: <em>10<\/em>):<\/p>\n<blockquote>\n<p>Any Integer value [Int32]<\/p>\n<\/blockquote>\n<p><strong>Style<\/strong> <\/p>\n<\/td>\n<td width=\"330\">This property allows the user to set the style of the ProgressBar. <\/p>\n<p><em>Why use the Style property?<\/em> <\/p>\n<p>Use the style property when you want to change the way&nbsp; ProgressBar is displayed or in cases where you have an unknown amount of increments (See Marquee style). <\/p>\n<p>Values (Default: <em>Blocks<\/em> ): <\/p>\n<blockquote>\n<p><em>Blocks<\/em><br \/>Indicates progress by increasing the number of segmented blocks in a ProgressBar. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Block &amp; Contineous\" border=\"0\" alt=\"Block &amp; Contineous\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Block-Contineous1.png\" width=\"300\" height=\"44\"> <\/p>\n<p><font size=\"2\">(Windows 7)<\/font> <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Block &amp; Contineous XP\" border=\"0\" alt=\"Block &amp; Contineous XP\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Block-Contineous-XP.png\" width=\"278\" height=\"39\"> <\/p>\n<p><font size=\"2\">(Windows XP)<\/font> <\/p>\n<p><em>Continuous<\/em><br \/>Indicates progress by increasing the size of a smooth, continuous bar in a ProgressBar. Since PrimalForms enables VisualStyles by default, Continuous will resemble Blocks style. <\/p>\n<p><em>Marquee<\/em><br \/>Indicates progress by continuously scrolling a block across a ProgressBar in a marquee fashion. Use Marquee when you can\u2019t specify a quantity of progress, but still need to indicate that progress is being made. Use the MarqueeAnimationSpeed property to control the speed of the ProgressBar.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Marquee.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Marquee\" border=\"0\" alt=\"Marquee\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Marquee_thumb.png\" width=\"298\" height=\"44\"><\/a><\/p>\n<p><font size=\"2\">(Windows 7)<\/font><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Marquee XP\" border=\"0\" alt=\"Marquee XP\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Marquee-XP.png\" width=\"277\" height=\"40\"><\/p>\n<p><font size=\"2\">(Windows XP)<\/font><\/p>\n<\/blockquote>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Value<\/strong> <\/p>\n<\/td>\n<td width=\"330\">The current value of the ProgressBar, in the range specified by the Minimum and Maximum properties.<\/p>\n<p><em>Why use the Value property?<\/em><\/p>\n<p>Use the Value property if you want to set the progress at a specific point or to obtain the current position of the ProgressBar .<\/p>\n<p>Values (Default: <em>0<\/em>):<\/p>\n<blockquote>\n<p>Any Integer value [Int32]<\/p>\n<\/blockquote>\n<p><strong>MarqueeAnimationSpeed<\/strong><\/p>\n<p>This property indicates the speed of the marquee animation in milliseconds. The ProgressBar\u2019s Style must be set to Marquee in order to use this property.<\/p>\n<p><em>Why use the MarqueeAnimationSpeed property<\/em>?<\/p>\n<p>Use the MarqueeAnimationSpeed property if you want to change the speed of the ProgressBar \u2019s animation or to pause the marquee by setting the speed to 0.<\/p>\n<p>To clear the Marquee, it is recommended to change the Style property to Block and set the Value property to 0.<\/p>\n<p>Values (Default: <em>100<\/em>):<\/p>\n<blockquote>\n<p>Any Integer value [Int32] (In milliseconds)<\/p>\n<\/blockquote>\n<p><strong><font size=\"3\">Important Methods:<\/font><\/strong> <\/p>\n<p><strong>Increment<\/strong> <\/p>\n<p>This method advances the current position of the ProgressBar by the specified amount. <\/p>\n<p><em>Why use the Increment method?<\/em> <\/p>\n<p>Use the Increment method when you need to increment the value of the ProgressBar by varying amounts.&nbsp; This method of incrementing the ProgressBar is similar to using the Step property with the PerformStep method. Setting the Step property is not necessary when using the Increment method. <\/p>\n<p>Example of using Increment method in the script editor:<\/p>\n<pre><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.Increment(<\/span><span style=\"color: #000000\">1<\/span><span style=\"color: #000000\">)<\/span><\/pre>\n<pre><span style=\"color: #000000\"><\/span>&nbsp;<\/pre>\n<p><strong>PerformStep<\/strong> <\/p>\n<\/td>\n<td width=\"330\">This method advances the current value of the ProgressBar by the amount of the Step property.<\/p>\n<p><em>Why use the PerformStep method?<\/em><\/p>\n<p>Use the PerformStep method when repeatedly incrementing the ProgressBar by the same amount (i.e., the value set in the Step property). <\/p>\n<p>&nbsp;<\/p>\n<p>Here is a sample script block triggered by a button, that displays its progress as it creates a backup of all the text files located in a folder specified by the user:<\/p>\n<\/td>\n<\/tr>\n<pre><span style=\"color: #8b0000\">$buttonBackupFiles_Click<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    <\/span><span style=\"color: #008000\">#Back up Text files from a selected directory<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$folderbrowserdialog1<\/span><span style=\"color: #000000\">.ShowDialog() <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #ff0000\">'OK'<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #8b0000\">$selectedPath<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$folderbrowserdialog1<\/span><span style=\"color: #000000\">.SelectedPath\n        \n        <\/span><span style=\"color: #008000\">#Get all the text files in the folder<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff; font-weight: bold\">Get-ChildItem<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$selectedPath<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-<\/span><span style=\"color: #0000ff\">Filter<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">*<\/span><span style=\"color: #000000\">.txt\n\n        <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$null<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-or<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\">.Count <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">0<\/span><span style=\"color: #000000\">)\n        {\n            <\/span><span style=\"color: #008000\">#No files to backup<\/span><span style=\"color: #000000\">\n            <\/span><span style=\"color: #0000ff\">return<\/span><span style=\"color: #000000\">    \n        }\n        \n        <\/span><span style=\"color: #008000\">#Initialize the Progress Bar<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.Maximum <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\">.Count\n        <\/span><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.Step <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">1<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.Value <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">0<\/span><span style=\"color: #000000\">\n        \n        <\/span><span style=\"color: #008000\">#Create the Backup Folder<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$destination<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #ff0000\">'{0}\\\\Backup'<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-f<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$selectedPath<\/span><span style=\"color: #000000\">)\n        [System.IO.Directory]<\/span><span style=\"color: #0000ff\">::<\/span><span style=\"color: #000000\">CreateDirectory(<\/span><span style=\"color: #8b0000\">$destination<\/span><span style=\"color: #000000\">)\n        \n        <\/span><span style=\"color: #008000\">#Copy the files and update the progress bar<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #0000ff\">foreach<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #8b0000\">$file<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">in<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$files<\/span><span style=\"color: #000000\">){    \n            <\/span><span style=\"color: #0000ff; font-weight: bold\">Copy-Item<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #ff0000\">'{0}\\\\{1}'<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-f<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$selectedPath<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #8b0000\">$file<\/span><span style=\"color: #000000\">) <\/span><span style=\"color: #0000ff\">-<\/span><span style=\"color: #000000\">Destination <\/span><span style=\"color: #8b0000\">$destination<\/span><span style=\"color: #000000\">\n            <\/span><span style=\"color: #8b0000\">$progressbar1<\/span><span style=\"color: #000000\">.PerformStep()\n        }\n    }\n}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms. Last time we took a look at the [&hellip;]<\/p>\n","protected":false},"author":10,"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":[575,644,25],"tags":[641,28,633,663,327],"class_list":["post-3193","post","type-post","status-publish","format-standard","hentry","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-powershell","tag-primalforms-2011","tag-progressbar","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3193","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\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=3193"}],"version-history":[{"count":4,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3193\/revisions"}],"predecessor-version":[{"id":3203,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3193\/revisions\/3203"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}