{"id":3250,"date":"2011-08-05T07:44:00","date_gmt":"2011-08-05T15:44:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3250"},"modified":"2011-08-05T07:45:12","modified_gmt":"2011-08-05T15:45:12","slug":"primalforms-2011-spotlight-on-the-picturebox-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/08\/05\/primalforms-2011-spotlight-on-the-picturebox-control\/","title":{"rendered":"PrimalForms 2011: Spotlight on the PictureBox 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\/14\/primalforms-2011-spotlight-on-the-progressbar-control\/\">ProgressBar<\/a> control. This time we will look at the PictureBox control:<\/p>\n<p><span style=\"font-size: medium\"><strong>PictureBox Control <\/strong>[System.Windows.Forms.PictureBox]<\/span><\/p>\n<p>Represents a Windows picture box control for displaying an image.<\/p>\n<p>Default Event: Click<\/p>\n<p><em>Why use a PictureBox control?<\/em><\/p>\n<p>Use a PictureBox when you need to display an image either located on a disk or the internet. Similar to other controls, you can also imbed an image in your form with the PictureBox.<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>Image<\/strong>  <\/p>\n<\/td>\n<td width=\"330\">\n<p>The image displayed in the PictureBox.<\/td>\n<p><em>Why use the Image property?<\/em>  <\/p>\n<p>Use the Image property when you wish to display an image in your form. In PrimalForms 2011 the image will be imbedded with the form, whereas older versions of PrimalForms reference a file path.&nbsp; <\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/ImageLocation.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=\"ImageLocation\" border=\"0\" alt=\"ImageLocation\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/ImageLocation_thumb.png\" width=\"242\" height=\"244\"><\/a>  <\/p>\n<p><strong>ImageLocation<\/strong>  <\/p>\n<p>Disk or Web location to load image from.  <\/p>\n<p><em>Why use the ImageLocation property?<\/em>  <\/p>\n<p>Use the ImageLocation property when you wish to load an image asynchronously from either a website or disk location. Unlike the Image property,&nbsp; the ImageLocation&nbsp; property does not imbed the image in the form.  <\/p>\n<p><strong>InitialImage<\/strong>  <\/p>\n<p>Image to display while the main image is loading (ImageLocation). The InitialImage is always displayed non-stretched, in the center of the PictureBox.&nbsp; <\/p>\n<p>Default IntialImage:  <\/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=\"InitialImage\" border=\"0\" alt=\"InitialImage\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/InitialImage.png\" width=\"248\" height=\"250\">  <\/p>\n<p><strong>ErrorImage<\/strong>  <\/p>\n<p>The image to display when an error occurs during the image-loading process or if the image load is canceled. (ImageLocation)  <\/p>\n<p>Default ErrorImage:  <\/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=\"ErrorImage\" border=\"0\" alt=\"ErrorImage\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/ErrorImage.png\" width=\"248\" height=\"250\">  <\/p>\n<\/td>\n<p><strong>SizeMode<\/strong>  <\/p>\n<p>This property controls how the PictureBox will handle image placement and control sizing.<\/td>\n<p>Values (Default: <em>Normal<\/em>):  <\/p>\n<blockquote>\n<p><em>Normal<\/em><br \/>The image is placed in the upper-left corner of the PictureBox. The image is clipped if it is larger than the PictureBox it is contained in.  <\/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=\"Normal\" border=\"0\" alt=\"Normal\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Normal.png\" width=\"284\" height=\"250\">  <\/p>\n<p><em>StretchImage<\/em><br \/>The image within the PictureBox is stretched or shrunk to fit the size of the PictureBox.  <\/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=\"Stretch\" border=\"0\" alt=\"Stretch\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Stretch.png\" width=\"284\" height=\"250\">  <\/p>\n<p><em>AutoSize<\/em><br \/>The PictureBox is sized equal to the size of the image that it contains.  <\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/AutoSize.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=\"AutoSize\" border=\"0\" alt=\"AutoSize\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/AutoSize_thumb.png\" width=\"379\" height=\"370\"><\/a>  <\/p>\n<p><em>CenterImage<\/em><br \/>The image is displayed in the center if the PictureBox is larger than the image. If the image is larger than the PictureBox, the picture is placed in the center of the PictureBox and the outside edges are clipped.  <\/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=\"Center\" border=\"0\" alt=\"Center\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Center.png\" width=\"284\" height=\"250\">  <\/p>\n<p><em>Zoom<\/em><br \/>The size of the image is increased or decreased maintaining the size ratio.<\/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=\"Zoom\" border=\"0\" alt=\"Zoom\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/Zoom.png\" width=\"284\" height=\"250\"><\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong>Important Events:<\/strong><\/p>\n<p><strong>LoadProgressChanged<\/strong><\/p>\n<p>This event occurs when the progress of an asynchronous image-loading operation has changed.<\/p>\n<p>The LoadProgressChanged event passes a [System.ComponentModel.ProgressChangedEventArgs] object as a parameter to the event block. You can access this object by using the <span style=\"color: #8b0000\">$_<\/span> variable.<\/p>\n<p>The important property of the ProgressChangedEventArgs object is:<\/p>\n<blockquote>\n<p><em>ProgressPercentage<\/em><\/p>\n<p>Gets the asynchronous task progress percentage.<\/p>\n<\/blockquote>\n<p>You can utilize to LoadProgressChanged to display the current load percentage in a progress bar:<\/p>\n<pre><span style=\"color: #8b0000\">$picturebox1_LoadProgressChanged<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">[System.ComponentModel.ProgressChangedEventHandler]{\n<\/span><span style=\"color: #008000\">#Event Argument: $_ = [System.ComponentModel.ProgressChangedEventArgs]<\/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: #8b0000\">$_<\/span><span style=\"color: #000000\">.ProgressPercentage\n}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>Image loading with a progress bar:<\/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=\"LoadProgressChanged\" border=\"0\" alt=\"LoadProgressChanged\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/LoadProgressChanged.png\" width=\"284\" height=\"250\"><\/p>\n<p>Image load completed:<\/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=\"LoadCompleted\" border=\"0\" alt=\"LoadCompleted\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/LoadCompleted.png\" width=\"284\" height=\"250\"><\/p>\n<p><strong>LoadCompleted<\/strong><\/p>\n<p>This event occurs when the asynchronous image-load operation is completed, been canceled, or raised an exception.<\/p>\n<p>The LoadCompleted event passes a [System.ComponentModel.AsyncCompletedEventArgs] object as a parameter to the event block. You can access this object by using the $_ variable.<\/p>\n<p>The two important properties of the AsyncCompleteEventArgs object are:<\/p>\n<blockquote>\n<p><em>Cancelled<\/em><\/p>\n<p>The Cancelled property will tell you if the loading process was cancelled.<\/p>\n<p><em>Error<\/em><\/p>\n<p>The Error property will contain the exception error if the load operation failed. Use the Message sub-property get the error message text. <\/p>\n<\/blockquote>\n<p>Below is an example where an error message is displayed when an image fails to load asynchronously using the ImageLocation property:<\/p>\n<pre><span style=\"color: #8b0000\">$picturebox1_LoadCompleted<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">[System.ComponentModel.AsyncCompletedEventHandler]{\n<\/span><span style=\"color: #008000\">#Event Argument: $_ = [System.ComponentModel.AsyncCompletedEventArgs]<\/span><span style=\"color: #000000\">\n    \n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Error <\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$null<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #8b0000\">$labelMessage<\/span><span style=\"color: #000000\">.Text <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Error.Message\n    }\n}<\/span><\/pre>\n<p>&nbsp;<\/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=\"LoadCompletedErrorMessage\" border=\"0\" alt=\"LoadCompletedErrorMessage\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/07\/LoadCompletedErrorMessage.png\" width=\"348\" height=\"310\"><\/p>\n<pre><\/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,676,28,633,327],"class_list":["post-3250","post","type-post","status-publish","format-standard","hentry","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-picturebox","tag-powershell","tag-primalforms-2011","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3250","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=3250"}],"version-history":[{"count":2,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3250\/revisions"}],"predecessor-version":[{"id":3279,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3250\/revisions\/3279"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}