{"id":3368,"date":"2011-08-18T09:04:00","date_gmt":"2011-08-18T17:04:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3368"},"modified":"2011-08-24T13:47:46","modified_gmt":"2011-08-24T21:47:46","slug":"primalforms-2011-spotlight-on-the-errorprovider-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/08\/18\/primalforms-2011-spotlight-on-the-errorprovider-control\/","title":{"rendered":"PrimalForms 2011: Spotlight on the ErrorProvider 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\/08\/09\/primalforms-2011-spotlight-on-the-timer-control\">Timer<\/a> control. This time we will look at the ErrorProvider control:<\/p>\n<p><span style=\"font-size: medium\"><strong>ErrorProvider Control <\/strong>[System.Windows.Forms.ErrorProvider]<\/span><\/p>\n<p>Provides a user interface for indicating that a control on a form has an error associated with it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline\" title=\"ErrorProvider\" alt=\"ErrorProvider\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/ErrorProvider.png\" width=\"103\" height=\"19\"><\/p>\n<p>Default Event: N\/A<\/p>\n<p><em>Why use a ErrorProvider control?<\/em><\/p>\n<p>Use the ErrorProvider if you want to notify the user that there is an input error by flashing an icon next to the input control. You can use a single ErrorProvider for multiple controls. In the case where you wish to display different icons or styles, you will need to use multiple ErrorProvider controls.<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\"><\/font><\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>Icon<\/strong>  <\/p>\n<p>Use this property to change the icon used to indicate an error.  <\/p>\n<p>Default Icon: <em><img loading=\"lazy\" decoding=\"async\" style=\"display: inline\" title=\"DefaultIcon\" alt=\"DefaultIcon\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/DefaultIcon.png\" width=\"19\" height=\"19\"><\/em><\/p>\n<p><strong>BlinkRate<\/strong><\/p>\n<p>This property controls the rate in milliseconds at which the error icon blinks.<\/p>\n<p>Use this property to increase or decrease the blink rate of the icon. Note: 1000 milliseconds = 1 sec.<\/p>\n<p>Default Value: 250<\/p>\n<p><strong>BlinkStyle<\/strong><\/p>\n<p>This property controls whether the error icon blinks when an error is set.<\/p>\n<p>Values (Default: <em>BlinkIfDifferentError<\/em>):<\/p>\n<blockquote>\n<p><em>BlinkIfDifferentError<\/em><br \/>Blinks when the icon is already displayed and a new error string is set for the control.  <\/p>\n<p><em>AlwaysBlink<\/em><br \/>Always blinks when the error icon is first displayed, or when an error description string is set for the control and the error icon is already displayed.  <\/p>\n<p><em>NeverBlink<\/em><br \/>Never blinks the error icon.<\/p>\n<\/blockquote>\n<p><strong><font size=\"3\">Important Methods:<\/font><\/strong>  <\/p>\n<p><strong>SetError<\/strong>  <\/p>\n<p>This method sets the error description string for the specified control.  <\/p>\n<p>Use the SetError method to display the error icon next to the target control and display a specified error message when the user hovers the mouse over the error icon. To clear an error message, pass an empty string to the method, using the same control as a parameter.<\/p>\n<p>Example use of the SetError method when validating a TextBox:<\/p>\n<pre><span style=\"color: #8b0000\">$textboxName_Validating<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">[System.ComponentModel.CancelEventHandler]{\n<\/span><span style=\"color: #008000\">#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #008000\">#Check if the Name field is empty<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">.Text.Trim() <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #ff0000\">\"\"<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #008000\">#Display an error message<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetError(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #ff0000\">\"Please enter your name.\"<\/span><span style=\"color: #000000\">);\n    }\n    <\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #000000\">\n    {\n        <\/span><span style=\"color: #008000\">#Clear the error<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetError(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #ff0000\">\"\"<\/span><span style=\"color: #000000\">);    \n    }\n}<\/span><\/pre>\n<p>The ErrorProvider displayed in the form:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline\" title=\"Display an Error\" alt=\"Display an Error\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/Display-an-Error.png\" width=\"432\" height=\"140\"><\/p>\n<p><strong>SetIconAlignment<\/strong> <\/p>\n<p>This method sets the location where the error icon should be placed in relation to the control.<\/p>\n<p>Note: You have to set the alignment for each individual control.<\/p>\n<p>Note: You can set also set the Icon Alignment in the designer by setting the target control\u2019s \u201cIconAlignment on errorprovider1\u201d property.<\/p>\n<p>An example use of the SetIconAlignment method where the error Icon is set on the left side of the TextBox control:<\/p>\n<pre><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetIconAlignment(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">, [System.Windows.Forms.ErrorIconAlignment]<\/span><span style=\"color: #0000ff\">::<\/span><span style=\"color: #000000\">MiddleLeft)<\/span><\/pre>\n<p>The resulting form:<\/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=\"ErrorIconLeftAlignment\" border=\"0\" alt=\"ErrorIconLeftAlignment\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/ErrorIconLeftAlignment.png\" width=\"304\" height=\"124\"><\/p>\n<p>The second parameter of the method accepts an <em>enum<\/em> of type [System.Windows.Forms.ErrorIconAlignment]. Since PowerShell allows you to express <em>enum<\/em> values as strings, you can shorten the call by just passing the name of the ErrorIconAlignment value:<\/p>\n<pre><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetIconAlignment(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #ff0000\">\"MiddleLeft\"<\/span><span style=\"color: #000000\">)<\/span><\/pre>\n<p>Default Alignment: <em>MiddleRight<\/em><\/p>\n<p>ErrorIconAlignment Values:<\/p>\n<blockquote>\n<p><em>TopLeft<\/em><br \/>The icon appears aligned with the top of the control and to the left of the control. <\/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=\"TopLeft\" border=\"0\" alt=\"TopLeft\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/TopLeft.png\" width=\"203\" height=\"62\"> <\/p>\n<p><em>TopRight<\/em><br \/>The icon appears aligned with the top of the control and to the right of the control. <\/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=\"TopRight\" border=\"0\" alt=\"TopRight\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/TopRight.png\" width=\"203\" height=\"62\"> <\/p>\n<p><em>MiddleLeft<\/em><br \/>The icon appears aligned with the middle of the control and the left of the control. <\/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=\"MiddleLeft\" border=\"0\" alt=\"MiddleLeft\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/MiddleLeft.png\" width=\"203\" height=\"62\"> <\/p>\n<p><em>MiddleRight<\/em><br \/>The icon appears aligned with the middle of the control and the right of the control. <\/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=\"MiddleRight\" border=\"0\" alt=\"MiddleRight\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/MiddleRight.png\" width=\"203\" height=\"62\"> <\/p>\n<p><em>BottomLeft<\/em><br \/>The icon appears aligned with the bottom of the control and the left of the control. <\/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=\"BottomLeft\" border=\"0\" alt=\"BottomLeft\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/BottomLeft.png\" width=\"203\" height=\"62\"> <\/p>\n<p><em>BottomRight<\/em><br \/>The icon appears aligned with the bottom of the control and the right of the control. <\/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=\"BottomRight\" border=\"0\" alt=\"BottomRight\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/BottomRight.png\" width=\"203\" height=\"62\"><\/p>\n<\/blockquote>\n<p>&nbsp; <\/p>\n<p><strong>SetIconPadding<\/strong> <\/p>\n<p>Sets the amount of extra space left between the specified control and the error icon. <\/p>\n<p>Note: You have to set the padding for each individual control.<\/p>\n<pre><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetIconPadding(<\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #000000\">1<\/span><span style=\"color: #000000\">)<\/span><\/pre>\n<p>Note: You can set also set the Icon Padding in the designer by setting the target control\u2019s \u201cIconPadding on errorprovider1\u201d property.<\/p>\n<p>ErrorProvider with padding set to 1:<\/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=\"Padding1\" border=\"0\" alt=\"Padding1\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/Padding1.png\" width=\"214\" height=\"60\"><\/p>\n<p>ErrorProvider with the padding set to 10:<\/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=\"Padding10\" border=\"0\" alt=\"Padding10\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/Padding10.png\" width=\"214\" height=\"60\"><\/p>\n<p>&nbsp;<\/p>\n<p>Download the <a href=\"http:\/\/www.sapien.com\/downloads#Sample Scripts\/PrimalForms 2011\/ErrorProviderSample.zip\">ErrorProvider Sample<\/a> from our <a href=\"http:\/\/sapien.com\/downloads\">Downloads<\/a> section.<\/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=\"ErrorProvider Sample Form\" border=\"0\" alt=\"ErrorProvider Sample Form\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/08\/ErrorProvider-Sample-Form.png\" width=\"368\" height=\"203\"><\/p>\n<p><font size=\"2\"><\/font><\/p>\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":[509,575,644,25],"tags":[641,679,28,633,327],"class_list":["post-3368","post","type-post","status-publish","format-standard","hentry","category-primalforms-software-news","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-errorprovider","tag-powershell","tag-primalforms-2011","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3368","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=3368"}],"version-history":[{"count":3,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3368\/revisions"}],"predecessor-version":[{"id":3421,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3368\/revisions\/3421"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}