'Declaration Public Property ErrorImageAlignment As ErrorIconAlignment
public ErrorIconAlignment ErrorImageAlignment {get; set;}
By default, the error image is displayed alongside the outer right edge of the control with which it is associated, centered vertically. The ErrorImageAlignment property, in conjunction with the ErrorImagePadding property, makes it possible to customize the placement of the error image.
Note: Changing the vertical alignment of the error image is only possible when the vertical component of the ErrorImageSize property is less than the height of the control with which it is associated. For example, if the height of the control is 20 pixels, and the height returned from ErrorImageSize is also 20 pixels, there is no discrepancy between the height of the error image and the height of the control, so there is no space in which the image can be adjusted. If in the same example the height returned from ErrorImageSize is 10, there are 10 "unused" pixels between the top/bottom of the image and the edge of the control; this space can then be used to adjust the vertical placement of the error image.
The ErrorImageAlignment property is not applicable when the entity being validated is an embeddable editor.
Imports Infragistics.Win Imports Infragistics.Win.Misc Imports System.Drawing Imports System.Drawing.Drawing2D Private Sub SetErrorImageProperties(ByVal ultraValidator As UltraValidator) ' Set the ErrorImageAlignment property to 'MiddleLeft' so that the ' error image appears on the left side, centered vertically. ultraValidator.ErrorImageAlignment = ErrorIconAlignment.MiddleLeft ' Set the ErrorImagePadding property to 5 so that there is a ' little space between the image and the control. ultraValidator.ErrorImagePadding = 5 ' Set the blink rate for the error image to 182 milleseconds, ' and the blink style to 'Always', so that the error image ' blinks quickly when an error occurs. ultraValidator.ErrorImageBlinkRate = 182 ultraValidator.ErrorImageBlinkStyle = ErrorImageBlinkStyle.Always ' Generate an image to be displayed when a validation error occurs, ' and use a smaller that usual size for a compact UI. Set the transparent ' color to Color.Transparent. Also, handle the Disposed event so we can ' properly dispose of the error image since we created it. Dim errorImageSize As Size = New Size(13, 13) ultraValidator.ErrorImageSize = errorImageSize ultraValidator.NotificationSettings.Image = Me.GenerateErrorImage(errorImageSize) ultraValidator.ErrorImageTransparentColor = Color.Transparent AddHandler ultraValidator.Disposed, AddressOf Me.ultraValidator_Disposed ' Set the notification action to 'Image'. ultraValidator.NotificationSettings.Action = NotificationAction.Image End Sub Private Function GenerateErrorImage(ByVal size As Size) As Bitmap Dim errorImage As Bitmap = New Bitmap(size.Width, size.Height) Dim bounds As Rectangle = New Rectangle(Point.Empty, size) Using gr As Graphics = Graphics.FromImage(errorImage) gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias Using brush As SolidBrush = New SolidBrush(Color.Red) gr.FillEllipse(brush, bounds) End Using bounds.Inflate(-3, -3) Using pen As Pen = New Pen(Color.White, 2.0F) gr.DrawLine(pen, bounds.Location, New Point(bounds.Right, bounds.Bottom)) gr.DrawLine(pen, New Point(bounds.Left, bounds.Bottom), New Point(bounds.Right, bounds.Top)) End Using End Using Return errorImage End Function Private Sub ultraValidator_Disposed(ByVal sender As Object, ByVal e As EventArgs) Dim ultraValidator As UltraValidator = sender Dim errorImage As Image = ultraValidator.NotificationSettings.Image If Not errorImage Is Nothing Then errorImage.Dispose() End Sub
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Text; using System.Windows.Forms; using Infragistics.Win; using Infragistics.Win.Misc; using System.Drawing; using System.Drawing.Drawing2D; private void SetErrorImageProperties( UltraValidator ultraValidator ) { // Set the ErrorImageAlignment property to 'MiddleLeft' so that the // error image appears on the left side, centered vertically. ultraValidator.ErrorImageAlignment = ErrorIconAlignment.MiddleLeft; // Set the ErrorImagePadding property to 5 so that there is a // little space between the image and the control. ultraValidator.ErrorImagePadding = 5; // Set the blink rate for the error image to 182 milleseconds, // and the blink style to 'Always', so that the error image // blinks quickly when an error occurs. ultraValidator.ErrorImageBlinkRate = 182; ultraValidator.ErrorImageBlinkStyle = ErrorImageBlinkStyle.Always; // Generate an image to be displayed when a validation error occurs, // and use a smaller that usual size for a compact UI. Set the transparent // color to Color.Transparent. Also, handle the Disposed event so we can // properly dispose of the error image since we created it. Size errorImageSize = new Size(13, 13); ultraValidator.ErrorImageSize = errorImageSize; ultraValidator.NotificationSettings.Image = this.GenerateErrorImage( errorImageSize ); ultraValidator.ErrorImageTransparentColor = Color.Transparent; ultraValidator.Disposed += new EventHandler( this.ultraValidator_Disposed ); // Set the notification action to 'Image'. ultraValidator.NotificationSettings.Action = NotificationAction.Image; } private Bitmap GenerateErrorImage( Size size ) { Bitmap errorImage = new Bitmap( size.Width, size.Height ); Rectangle bounds = new Rectangle( Point.Empty, size ); using ( Graphics gr = Graphics.FromImage(errorImage) ) { gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using ( SolidBrush brush = new SolidBrush(Color.Red) ) { gr.FillEllipse( brush, bounds ); } bounds.Inflate( -3, -3 ); using ( Pen pen = new Pen(Color.White, 2f) ) { gr.DrawLine( pen, bounds.Location, new Point(bounds.Right, bounds.Bottom) ); gr.DrawLine( pen, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Top) ); } } return errorImage; } private void ultraValidator_Disposed(object sender, EventArgs e) { UltraValidator ultraValidator = sender as UltraValidator; Image errorImage = ultraValidator.NotificationSettings.Image; if ( errorImage != null ) errorImage.Dispose(); }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2