<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Visual Basic 2008</title><link>http://blogs.vbcity.com/xtab/category/201.aspx</link><description>The next generation</description><managingEditor>Ged Mead</managingEditor><dc:language>et</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Ged Mead</dc:creator><title>How To Animate a TextBox in Windows Forms</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx</link><pubDate>Fri, 03 Jul 2009 15:34:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9348.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/07/03/9348.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9348.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9348.aspx</trackback:ping><description>&lt;FONT face=Calibri&gt;
&lt;P&gt;&lt;U&gt;Starting Point&lt;/U&gt;&lt;BR&gt;In my earlier post, &lt;A href="http://cs.vbcity.com/blogs/xtab/archive/2009/07/01/wpf-and-winforms-interop-a-highlighted-textbox.aspx"&gt;the HiliteTextBox&lt;/A&gt;, I created a simple WPF UserControl which is hosted in an ElementHost in a Windows Form. If the user tries to continue without entering text in the TextBox, a bright colored Border would appear around it and stay there until the user does enter something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight6.png"&gt;&lt;/P&gt;
&lt;P&gt;If we are going to go to the trouble of harnessing WPF's graphics power, we may as well go a step further and add some animation to the control. One simple thing we can do is to animate the Border Thickness.&lt;/P&gt;
&lt;P&gt;This is the XAML for the UserControl I created previously. The only thing I have changed is the class name. It was originally HiliteTextBox, but for this version it will be named AnimatedTextBox :&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="AnimatedTextBox"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BrightGradient"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;EndPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.056,0.993"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; StartPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.634,0.342"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SpreadMethod&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Repeat"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB50D0D"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFE80C2C"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFF4DF5A"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.17399999499320984"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFCA0C1F"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.357"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDCD762"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.522"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB70D36"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.716"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDDEE49"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.823"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LightGray"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="5"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4,4,4,4"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox_TextChanged"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;And this is the code-behind in the UserControl:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; InputTextBox_TextChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Controls.TextChangedEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; SolidColorBrush(Colors.Black)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"BrightGradient"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(4)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; IsTBEmpty() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length = 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Creating the Animation in Code&lt;/U&gt;&lt;BR&gt;&lt;BR&gt;Generally, you will find XAML to be the best tool for creating animations - and if they are quite complex then Expression Blend is your best bet. However, you can create a simple animation in the UserControl using code. The following code-behind in the UserControl will cause the Border to change in size over a short period of time: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; ChangeSize()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; ThickAnim &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; ThicknessAnimation&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;With&lt;/SPAN&gt; ThickAnim&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .To = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(14)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .AutoReverse = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Duration = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Duration(TimeSpan.FromSeconds(0.6))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;With&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.GradBorder.BeginAnimation(Border.BorderThicknessProperty, ThickAnim)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Even if you have no experience of WPF, most of the above code is relatively easy to follow.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;ThicknessAnimation &lt;/B&gt;is a class that 'does what it says on the tin', as we say here in the UK - it does exactly what you would expect. It animates the Thickness Property of a target element. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;To &lt;/B&gt;sets the value of the Thickness that has to be reached by the conclusion of the animation.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;AutoReverse&lt;/B&gt; ensures that the Thickness returns to its starting value by the end of the animation sequence.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Duration&lt;/B&gt; assigns the length of time for which the animation will run. Note that in the case of this AutoReversed animation both the increase (The &lt;B&gt;To&lt;/B&gt; value) and the decrease (&lt;B&gt;AutoReverse&lt;/B&gt; to the start value) in size are completed within the allowed Duration. &lt;/P&gt;
&lt;P&gt;The &lt;B&gt;BeginAnimation Method&lt;/B&gt; takes parameters of a kind that might be unfamiliar. It takes the WPF DependencyProperty for the Border class as the first argument and it takes the ThicknessAnimation instance as the second argument. The correct element is animated, of course, because the BeginAnimation method is applied to GradBorder, the Border instance we are dealing with. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.GradBorder.BeginAnimation(Border.BorderThicknessProperty, ThickAnim)&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;To get the animation to run, we can incorporate it into the code we used previously that tests if the TextBox is empty. This code is in the Windows Form on which we placed an ElementHost to house the WPF UserControl :&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; AnimatedTextBox1.IsTBEmpty = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Change to bright gradient border&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AnimatedTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Animate&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AnimatedTextBox1.ChangeSize()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Return focus&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ElementHost1.Focus()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"You are clear to continue"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you try this code and run the project, click the Continue Button with no text in the TextBox, you will see that the Gradient Border appears and then the Border size is animated.&lt;/P&gt;
&lt;P&gt;One thing you may have noticed is that the target in the Button Click event is an object named AnimatedTextBox1. If you scour through the small amount of code I have written so far, you won't find where I created this object. The reason being that I didn't. When you use the Smart Tag in the ElementHost and select the content, it will automatically create an instance for you and name it. &lt;/P&gt;
&lt;P&gt;In the next part, I will create a different animation using what on the face of it seems to be a very complex block of XAML. When we take a closer look, you will see that it is not as complicated as it first appears.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9348.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>WPF-WinForms Interop: A Highlighted TextBox</title><link>http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx</link><pubDate>Wed, 01 Jul 2009 16:49:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9346.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/07/01/9346.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9346.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9346.aspx</trackback:ping><description>&lt;FONT face=Calibri&gt;
&lt;P&gt;&lt;U&gt;Introduction&lt;/U&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;A recent forum post on VBCity asked for a way to highlight an important TextBox in a Windows Form. Assuming that the plan is to highlight the TextBox if the user is about to leave the Form without entering any text into it, there are of course several ways this can be done using Windows Forms techniques. But I thought it might be interesting to try something different and see how easy it would be to create a &lt;B&gt;WPF&lt;/B&gt; UserControl that incorporated a TextBox, a smack-you-in-the-eye gradient and a border with rounded corners*. I picked those last two features because they are not particularly easy to create in Windows Forms. The WPF UserControl would then have to be integrated seamlessly into the Windows Forms environment. &lt;BR&gt;&lt;BR&gt;(*If this isn't cutting-edge enough for you, I will be looking at adding animation to the control in a follow up blog post). &lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;So here's our demo Windows Form that will contain two TextBoxes. The WinForms TextBox is already in place. We will create the WPF one shortly. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight1.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;The WPF UserControl&lt;/U&gt; &lt;BR&gt;The first step is to add a WPF UserControl to the Windows Forms project. This is as simple as hitting Ctrl+Shift+A and selecting "WPF" from the &lt;B&gt;Add New Item&lt;/B&gt; menu which appears. The only choice you will then see is "User Control (WPF)", so select this and change the default name to 'HiliteTextBox.xaml'. Then click the &lt;B&gt;Add&lt;/B&gt; button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight2.png"&gt;&lt;/P&gt;
&lt;P&gt;The WPF UserControl will be added to your Windows Forms project and behind the scenes all the required References will be added also. The UserControl will be on display as the selected item in Visual Studio and you will see that all the WPF tools are in the Toolbox, not the WinForms ones. &lt;/P&gt;
&lt;P&gt;Delete the default Grid from the UserControl and then drag a Border element from the Toolbox and drop it on the &lt;I&gt;XAML&lt;/I&gt; pane, on one of the empty lines where the Grid used to be. You might think it strange that you drag a visual element and drop it into the markup area. There's nothing to stop you from dropping it in the Design pane instead. If you do this, you will find that several properties are automatically added for you and, as it happens, we don't want those particular properties set and you would therefore have to delete them.&lt;/P&gt;
&lt;P&gt;Assign the Name 'GradBorder' to the Border. Create an empty line between the opening and closing tags of the Border. Drag a TextBox from the Toolbox and drop it on the empty line. Name the TextBox 'InputTextBox'.&lt;/P&gt;
&lt;P&gt;Here's the Markup as at this point:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="HiliteTextBox"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Don't worry that nothing seems to be happening in the Design pane. We'll soon change that. With the Border selected in the XAML pane, move over to the Properties window and change the BorderBrush to LightGray, the BorderThickness and CornerRadius properties to 4. (Still no change in the Design pane; no worries). &lt;/P&gt;
&lt;P&gt;The plan is to have a plain gray border round the TextBox by default and have this change to a bright gradient if the user tries to continue without entering any text in the TextBox. To set this up, first create a new empty line between the opening tag of the Window and the opening tag of the Border. Copy and paste the following markup, which creates a LinearGradientBrush that will be stored as a Resource. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="BrightGradient"&lt;/SPAN&gt; &lt;SPAN style="COLOR: red"&gt;EndPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.056,0.993"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; StartPoint&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.634,0.342"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; SpreadMethod&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Repeat"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB50D0D"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFE80C2C"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFF4DF5A"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.17399999499320984"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFCA0C1F"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.357"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDCD762"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.522"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFB70D36"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.716"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GradientStop&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Color&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="#FFDDEE49"&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; Offset&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0.823"/&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;LinearGradientBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;There is a very good reason for storing the gradient brush separately and naming it with the 'BrightGradient' Key, as you will see soon. &lt;/P&gt;
&lt;P&gt;We will set a few properties on the TextBox. Select the TextBox in the XAML pane and then move to the Properties Window and set the TextWrapping property to 'Wrap'. &lt;/P&gt;
&lt;P&gt;In the XAML pane, create a new empty line inside the opening tag of the TextBox. Then type in: 'TextChanged='. &amp;nbsp;&amp;nbsp; As soon as you do this, an Intellisense popup will appear, inviting you to create a new event handler for the TextChanged event. &lt;BR&gt;&lt;BR&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight3.png"&gt;&lt;BR&gt;&lt;BR&gt;Press the TAB key and the rest of the line will be completed for you. It will be assigned a default name and this event handler will have been added to the code-behind for you. &lt;/P&gt;
&lt;P&gt;Your markup for the Border and TextBox should now look like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="GradBorder"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderBrush&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LightGray"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;BorderThickness&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: red"&gt;CornerRadius&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="4,4,4,4"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt; x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextWrapping&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Wrap"&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN style="COLOR: red"&gt;TextChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="InputTextBox_TextChanged"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBox&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Border&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Open up the vb file for the UserControl - HiliteTextBox.xaml.vb - in the project files in Solution Explorer. The InputTextBox_TextChanged event handler will be there for you. &lt;BR&gt;Before we code the event handler though, first create a Sub that will check if the TextBox contains any Text. If it does, the Border will be set to the non-highlighted LightGray; if it doesn't, the Border will be the bright gradient. Enter the following code: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Imports&lt;/SPAN&gt; System.Windows&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Imports&lt;/SPAN&gt; System.Windows.Media&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length &amp;gt; 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; SolidColorBrush(Colors.Black)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(1)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderBrush = FindResource(&lt;SPAN style="COLOR: #a31515"&gt;"BrightGradient"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GradBorder.BorderThickness = &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt; Thickness(4)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The only code that may be new to you might be the FindResource method. This is a really useful feature in WPF, which allows you to ferret through the project and pull out any specific resource that you want to use. The 'BrightGradient', you will recall, is the Key that I assigned to the LinearGradientBrush that I stored as a UserControl Resource earlier.&lt;BR&gt;&lt;BR&gt;The Imports statements at the top of the file ensure that you are accessing elements in the System.Windows namespace.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Hosting the UserControl&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;Now the UserControl is built, it has to be hosted in the Windows Form. Rebuild the project and then select the Form1.vb file. The control that WinForms uses to host WPF UserControls is the ElementHost. This probably won't be in your Toolbox by default, so if it isn't listed, right-click on the Toolbox and select &lt;B&gt;Choose Items...&lt;/B&gt; &amp;nbsp;&amp;nbsp;Select the ElementHost from the .NET Framework Components Tab. &lt;/P&gt;
&lt;P&gt;Drag an instance of the ElementHost from the Toolbox on to the surface of the Form. It will be too large by default, but before you change its size, click on small down arrow next to 'Select Hosted Content' and select HiliteTextBox from the list: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight5.png"&gt;&lt;/P&gt;
&lt;P&gt;The Smart Tag window will close and you can then adjust the size of the ElementHost. As you can see from the screenshot, an error message appears inside the ElementHost. You can safely ignore this as it is only tells you that the Windows Form can't display the visuals of the UserControl at Design time.&lt;/P&gt;
&lt;P&gt;Next we need to add code to the Continue button. For our demo purposes, this will be sufficient:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HiliteTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you look back at the earlier code, you will know that the HighlightEmpty method checks if the TextBox has Text entered and sets the Border accordingly. Although the Button on the Windows Form can't access the graphical elements of the UserControl directly, the HighlightEmpty procedure allows for this interchange between the two. &lt;/P&gt;
&lt;P&gt;Try running the application now. Don't enter any text into the UserControl, then press the Continue button. You should see the highlight gradient border appear around the TextBox.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/HiliteTextBox/Highlight6.png"&gt;&lt;/P&gt;
&lt;P&gt;If you then insert some text and press the Continue button again, the highlight border will be replaced with the gray one.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Adding Some Refinements&lt;/U&gt;&lt;BR&gt;That pretty much fulfills the spec, but there are a couple of things I would definitely add. The first feature is that if the user is warned about not entering text, then I would like to give some positive feedback as soon as they do so. That is, before they press the Continue button for a second time. This is easily achieved by adding a line of code to the TextChanged event handler of the InputTextBox. &lt;/P&gt;
&lt;P&gt;Go back to the WPF UserControl code-behind file and add a call to the HighlightEmpty procedure:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; InputTextBox_TextChanged(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Controls.TextChangedEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;When you run the application again and press the Continue button with no text in the TextBox, the highlight border appears as before. Now though, when you enter a character, the highlight Border disappears. As a small bonus, if the user then deletes all the text in the TextBox, the highlight will reappear, just to make certain they know about it.&lt;/P&gt;
&lt;P&gt;The second thing I would like to add is a way of giving the developer a choice of actions on the Continue Button Click event. What I mean by this is that at the moment, the call goes to the HighlightEmpty procedure of the UserControl. This approach makes it difficult to build choices into the Button Click event, along the lines of "Depending whether the TextBox is empty, do something here in the &lt;I&gt;Form's&lt;/I&gt; logic". &lt;/P&gt;
&lt;P&gt;There are several easy ways of doing this, including adding a Boolean Property to the UserControl or creating a simple Function. This tests if the InputTextBox is empty and if it is, it Returns True. Based on the returned value, the Button event handler can follow one course of action or another.&lt;/P&gt;
&lt;P&gt;Here's a Function that can be added to the UserControl: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; IsTBEmpty() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; InputTextBox.Text.Length = 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can then put whatever code you want in the Button Click event handler. Maybe something like:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Button1_Click(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Object, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; Button1.Click&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; HiliteTextBox1.IsTBEmpty = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; HiliteTextBox1.HighlightEmpty()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.ElementHost1.Focus()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"You are clear to continue"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can apply this approach of using a WPF UserControl in a Windows Form to get access to lots of those enhanced visual goodies that WPF offers, including Animation. As you have seen, creating a WPF UserControl hosted in an ElementHost is a very easy process. As an alternative to fiddling with individual controls on a Windows Form, you can of course include complete WPF Windows in Windows Forms projects. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9346.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>Copying An Item Between ListViews</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx</link><pubDate>Tue, 09 Jun 2009 09:44:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9319.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9319.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9319.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9319.aspx</trackback:ping><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I've always found ListViews quite fascinating. Slightly confusing sometimes, but fascinating nevertheless. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; As I have often been heard to say,&amp;nbsp;it's the little Gotchas that'll get ya.&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Take, for instance, the subject of this blog - copying an item between ListViews. The scenario is that you let the user click on an item in ListView1 and if they want this item copied to ListView2, they hit a button. &lt;BR&gt;&lt;BR&gt;Now, you would probably think that all you need to do is identify the currently selected item and add it straight to the second ListView. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;ListView2.Items.Add(ListView1.SelectedItems(0))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;But if you do try this, you will get an error. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;IMG height=249 src="http://www.xtabvbcity.plus.com/Blogs/ListViewItemCopy1.jpg" width=453&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The text of the error message pretty much says it all. What you have to do (assuming that you aren't prepared to remove the item from the original ListView) is to clone it. You will then be allowed to add the clone to the second ListView.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Although the cloning isn't difficult, you do have to be aware of the need to cast the selected item to ListViewItem if you have Option Strict On. To be honest, I found this a bit strange at first. If I lift a ListViewItem from a ListView, I didn't expect to have to cast it to what it is - i.e a ListViewItem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I'm not entirely sure why this occurs and wonder if the underlying reason for this is that the ListViewItem is stored in the SelectedItems collection of the ListView as a generic object. Anyway, Casting it back to a ListViewItem at the point where the cloning takes place, fixes this&amp;nbsp;without any problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This code works well:&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt; ListView1.SelectedItems.Count &amp;gt; 0&lt;SPAN style="COLOR: #0000ff"&gt; Then&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; lvi&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; ListViewItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvi = ListView1.SelectedItems(0)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; lvi2&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; ListViewItem&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lvi2 =&lt;SPAN style="COLOR: #0000ff"&gt; CType&lt;/SPAN&gt;(lvi.Clone, ListViewItem)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ListView2.Items.Add(lvi2)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; If&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You'll have noticed that I built in a test to ensure that an item is currently selected. It's an easy thing to forget and is sure to bring your app to a grinding halt before long if you don't build this in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You can see where I have cast the selected item (aka lvi) to ListViewItem in Line 5. Intriguingly, casting to ListViewItem in the third line of code, e.g. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;lvi =&lt;SPAN style="COLOR: #0000ff"&gt; CType&lt;/SPAN&gt;(ListView1.SelectedItems(0), ListViewItem)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;doesn't cut it. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9319.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>Removing Double Quotes from a Text File</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx</link><pubDate>Tue, 09 Jun 2009 09:35:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9318.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9318.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9318.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9318.aspx</trackback:ping><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: x-small; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Sometimes you don't have control over how the data is saved to a text file. For instance, some items might be saved with quotation marks around words or phrases. If you want to read the file but not show these marks then you'll need a way to remove them. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Like a lot of things, it's actually very easy when you know how. You can use the built-in Replace function of the String class, replacing the marks as you find them. The trick though (and to my mind, the less than totally intuitive bit) is knowing how many quotation marks to use in the first argument of the Replace method's parameters. This is the 'OldChar' parameter, i.e the one you want to replace. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;You would think, wouldn't you, that you could put a Quotation Mark inside a pair of Quotation Marks like this:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;MyString.Replace(&lt;SPAN style="COLOR: #a31515"&gt;"""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;But if you try that, you will find that it doesn't work. What you actually have to do is include a second Quotation Mark inside the outside ones. In other words, you need four Quotation Marks in a row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;MyString.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It's only a tiny change, but it will move your mental state from annoyed confusion to enlightened contentment. Or something like that, anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So putting this together with code that reads from a file and displays the result (minus Quotation Marks) in a ListBox, you have:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt; RemoveQuotes(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; filename&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #0000ff"&gt; ByVal&lt;/SPAN&gt; target&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt; ListBox)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A StreamReader to fetch the data&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; sr&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; IO.StreamReader(filename)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A string to hold each line as it is read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; line&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt; =&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;.Empty&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Read from the file&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' As long as there is something left to read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; While&lt;/SPAN&gt; sr.Peek &amp;lt;&amp;gt; -1&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Replace the Quotation Marks with Nothing&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = sr.ReadLine.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Add edited text to a ListBox&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;target.Items.Add(line)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Loop&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Tidy up when finished&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Close()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr =&lt;SPAN style="COLOR: #0000ff"&gt; Nothing&lt;BR&gt;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;If you prefer your code to be broken down into clearer steps, you could do this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: #aaaaaa 1px solid; BORDER-TOP: #aaaaaa 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #aaaaaa 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 10pt; BORDER-BOTTOM: #aaaaaa 1px solid"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Lucida Console'; BACKGROUND-COLOR: #dbdbdb"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt; RemoveQuotes(&lt;SPAN style="COLOR: #0000ff"&gt;ByVal&lt;/SPAN&gt; filename&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #0000ff"&gt; ByVal&lt;/SPAN&gt; target&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt; ListBox)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A StreamReader to fetch the data&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; sr&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; New&lt;/SPAN&gt; IO.StreamReader(filename)&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;A string to hold each line as it is read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/SPAN&gt; line&lt;SPAN style="COLOR: #0000ff"&gt; As&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt; =&lt;SPAN style="COLOR: #0000ff"&gt; String&lt;/SPAN&gt;.Empty&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Read from the file&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' As long as there is something left to read&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Do&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; While&lt;/SPAN&gt; sr.Peek &amp;lt;&amp;gt; -1&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Read the next line&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = sr.ReadLine&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Replace the Quotation Marks with Nothing&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line = line.Replace(&lt;SPAN style="COLOR: #a31515"&gt;""""&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #a31515"&gt; ""&lt;/SPAN&gt;)&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' Add edited text to a ListBox&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;target.Items.Add(line)&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Loop&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;Tidy up when finished&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Close()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr =&lt;SPAN style="COLOR: #0000ff"&gt; Nothing&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; Sub&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Either way, your quotation marks will be history.&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9318.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>Restricting TextBox Input</title><link>http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx</link><pubDate>Tue, 09 Jun 2009 09:28:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9316.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2009/06/09/9316.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9316.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9316.aspx</trackback:ping><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This is a question that seems to come up a lot in the forums:- How can I restrict the TextBox input to numerals, or only a single occurrence of a decimal point, or some other restriction?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;As ever, there are several approaches. If the restriction is something basic, such as numerals only then the easy approach is to use the KeyPress event. What you can do is stop the character from appearing in the TextBox, test to see if it is allowable and, if it is, then allow it to continue. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;B&gt;Letters Only&lt;/B&gt;&lt;/U&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; To take an example which only allows letters of the alphabet, it would look like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox1_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox1.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In this snippet, it is the e.Handled = True which blocks the input temporarily. The next line assesses whether the key press is a letter of the alphabet*, either lower or upper case, and if it is then the handled setting is reversed. This allows the key press to be passed to the TextBox display. If it fails the test, the block on this key press remains. &lt;/P&gt;
&lt;P&gt;&amp;nbsp; * Depending on your locale and keyboard, some other keys are allowed. These include symbols that are used in combination with characters in some languages, such as accents. In most cases this is the behaviour you will want.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Specific Keys&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;Sometimes you may want to allow certain keys. A common situation is where you will let the user use the Backspace to correct an error when inputting: &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox2_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox2.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = Chr(&amp;amp;H8) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In this case, it is the Chr(&amp;amp;H8) which identifies and allows the Backspace.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Numbers Only&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;Another common requirement is to restrict input to numerals. Of the several possible approaches, using IsNumeric is one of the most straightforward:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox3_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox3.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Sometimes that is too restrictive though. What happens if you want to allow the user to enter decimal points or (depending on their locale) commas to break up large numbers? Allowing these individual characters is simple, but there is another potential catch as we will see in a moment:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox4_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox4.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = &lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; e.KeyChar = &lt;SPAN style="COLOR: #a31515"&gt;","&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Only One Decimal Point&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;In most cases where users are inputting numeric values you will want to restrict them to a single decimal point. The code above will allow multiple entries. Again, there are several solutions, but the following one will usually do the job:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; TextBox5_KeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.KeyPressEventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; TextBox5.KeyPress&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &amp;lt;&amp;gt; &lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt; &lt;SPAN style="COLOR: green"&gt;' &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;ElseIf&lt;/SPAN&gt; TextBox5.Text.Contains(&lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&lt;SPAN style="COLOR: #a31515"&gt;"Only one decimal point allowed"&lt;/SPAN&gt;)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Command Keys&lt;/U&gt;&lt;/B&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; If you use any of the previous methods, you will be able to control the standard input keys. But there is another group of keys - Command keys - which won't be excluded by the use of the e.Handled approach. These include such keys as Home, End, Tab, and so on. You may risk alienating your users by excluding these, but there may be times when it is reasonable to do so, in which case you'll need to know how.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;A good way is to intercept the message at the window level and you can do this by overriding the ProcessCmdKey function. Here's how:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Create a new class which inherits from the basic TextBox. Override the ProcessCmdKey function and test for the currently pressed key in a similar way to that used in the earlier examples. If the key is one you want to suppress then you return True and the Windows message pump will ignore it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The following code will be all you need:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt; CustomTextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Inherits&lt;/SPAN&gt; System.Windows.Forms.TextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;New&lt;/SPAN&gt;()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.BackColor = Color.Azure&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Overrides&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; ProcessCmdKey(&lt;SPAN style="COLOR: blue"&gt;ByRef&lt;/SPAN&gt; msg &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.Message, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; keyData &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.Windows.Forms.Keys) &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Boolean&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Declare a variable of type Keys enumeration &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' named keyPressed. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Cast the msg's WParam as a KeyEnum value &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' and assign it to the keyPressed variable. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Dim&lt;/SPAN&gt; keyPressed &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Keys = &lt;SPAN style="COLOR: blue"&gt;CType&lt;/SPAN&gt;(msg.WParam.ToInt32(), Keys)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Process the key that is pressed. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; If keyPressed = Keys.Home Or keyPressed = Keys.End Then Return True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; keyPressed = Keys.Tab &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Return the Command key message&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.ProcessCmdKey(msg, keyData)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The light blue back color is simply to make this sub-classed TextBox look slightly different from the default one for demo purposes, but of course is not a key part of the key checking functionality. As you can see, my example blocks the Tab key. You can add or replace other keys, such as Home and End. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Multiple Options&lt;/U&gt;&lt;/B&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;Handling the KeyPress is fine if you only have a few TextBoxes for which you are controlling input. If there are going to be a lot of them throughout your application, or if you have different input rules for several TextBoxes, then again it may be worth your while to create your own inherited version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The following example deals with some of the previous scenarios, but allows the input rule to be selected from an enumeration of choices. The choices used here remain basic, but of course you can expand this idea much further. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here is the code:&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt; RestrictedTextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Inherits&lt;/SPAN&gt; System.Windows.Forms.TextBox&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Enum&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NoRestriction&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NumeralsOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LettersOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AlphanumericOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Enum&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; _allowedKeys &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Property&lt;/SPAN&gt; AllowedKeys() &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Get&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; _allowedKeys&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Get&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Set&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; Value &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; RestrictionCategory)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; Value&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR: blue"&gt;To&lt;/SPAN&gt; 3 &lt;SPAN style="COLOR: green"&gt;' One of the enum choices &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _allowedKeys = Value&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt; &lt;SPAN style="COLOR: green"&gt;' No restriction&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _allowedKeys = 0&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Property&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Overrides&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; OnKeyPress(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; KeyPressEventArgs)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.OnKeyPress(e)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; Test whether key is allowed, based on the current choice&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;'&amp;nbsp; from the enum&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; _allowedKeys&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR: green"&gt;'Numerals only &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 2&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Letters Only&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Case&lt;/SPAN&gt; 3&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Alphanumeric&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt; e.KeyChar &lt;SPAN style="COLOR: blue"&gt;Like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"[A-z]"&lt;/SPAN&gt; _&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Or&lt;/SPAN&gt; IsNumeric(e.KeyChar) &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Exit&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Else&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; e.Handled = &lt;SPAN style="COLOR: blue"&gt;True&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;If&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Select&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Class&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The key areas are the enumeration which is called RestrictionCategory. These are automatically assigned values from 0 to 3. The Property AllowedKeys and its backing Field carry out the standard roles of a Property, the user being able to set the AllowedKeys property in code. (You could improve this by having the property appear in the Properties Window). &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The core of this class is the overridden OnKeyPress method. This checks for the chosen enumeration and then either allows or applies the blocking filter to the currently pressed key. This works in a very similar way to the individual KeyPress approach used in the earlier examples. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;By default, all keys will be allowed and to set the enumeration of your choice, you simply include code similar to the following somewhere appropriate in your form (I've used the Form Load event for my example):&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt; Form1_Load(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; sender &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; e &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.Load&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.RestrictedTextBox1.AllowedKeys = RestrictedTextBox.RestrictionCategory.NumeralsOnly&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Sub&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Summary&lt;/U&gt;&lt;/B&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;I think that a combination or extension of any of the above approaches will enable you to control exactly what you will allow the user to input into a TextBox. &lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9316.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>My Blogs Are Moving to New Site</title><link>http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx</link><pubDate>Mon, 08 Dec 2008 16:13:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9212.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2008/12/08/9212.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9212.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9212.aspx</trackback:ping><description>&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp; VBCity will be looking very different&amp;nbsp;soon, as we change to the new Community Server based model.&amp;nbsp;&amp;nbsp; In advance of that change, our blogs are moving to a new area.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;From now on, you can view my latest blogs both here and&amp;nbsp;at the new site &lt;/FONT&gt;&lt;A href="http://cs.vbcity.com/blogs/xtab/default.aspx"&gt;&lt;FONT face=Verdana&gt;here&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;.&amp;nbsp; Once the new site is fully up and running, all new blog items will be posted on the new area only.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;All previous blogs from VBCity Bloggers will still be available and hopefully will continue to rank highly in search engine results.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9212.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>How To Get the Icon from an Application</title><link>http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx</link><pubDate>Thu, 27 Nov 2008 18:00:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9208.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2008/11/27/9208.aspx#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9208.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9208.aspx</trackback:ping><description>&lt;FONT face=Verdana size=2&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;This question comes up every so often in the forums and it's one of those things that you'd think should be easy, but actually isn't. Well, it isn't until you know how - like most things in developer land. The question is usually something along the lines of &lt;I&gt;"How can I grab the icon from an MS Word file?"&lt;/I&gt; The application may not necessarily be MS Word, but the that's the general thrust of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The only approach I have successfully used in this kind of scenario is the SHGetFileInfo API*. This API will grab the icon from an application. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here's the way I do it: First, Import Runtime.InteropServices into your Windows Form. &lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Imports&lt;/FONT&gt; System.Runtime.InteropServices&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Next, the API code, which goes at the top of the form, outside of any procedures:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Structure&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; hIcon&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; iIcon&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; dwAttributes&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)&amp;gt; _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; szDisplayName&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)&amp;gt; _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt; szTypeName&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Structure&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Declare&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Auto&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Function&lt;/FONT&gt; SHGetFileInfo&lt;FONT color=#0000ff&gt; Lib&lt;/FONT&gt;&lt;FONT color=#a31515&gt; "shell32.dll"&lt;/FONT&gt; _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; pszPath&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; dwFileAttributes&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByRef&lt;/FONT&gt; psfi&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; SHFILEINFO, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; cbFileInfo&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;, _&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ByVal&lt;/FONT&gt; uFlags&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Integer&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; hImgSmall&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; IntPtr&lt;FONT color=#008000&gt; 'The handle to the system image list.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Const&lt;/FONT&gt; SHGFI_ICON&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Long&lt;/FONT&gt; = &amp;amp;H100&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Const&lt;/FONT&gt; SHGFI_SMALLICON&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Long&lt;/FONT&gt; = &amp;amp;H1&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Note the two Constants at the end there being declared as Long. You'll usually find you have to tweak old API code to fix these kind of lines if you have Option Strict On.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;To demonstrate this API in action, here is how I've structured it: 
&lt;UL&gt;
&lt;LI&gt;I have added a button (btnSelectFile) to the Form.&lt;BR&gt;
&lt;LI&gt;When this button is clicked, an OpenFileDialog is created to allow the user to select a file.&lt;BR&gt;
&lt;LI&gt;Once a file has been selected, the file name is passed to a function that will dig out the icon for that file type and pass it back. &lt;BR&gt;
&lt;LI&gt;For demo purposes, the Form's default icon will be replaced with this selected one. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Here is the code in the function that grabs the icon:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; GetIcon(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; filename&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; Icon&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; shinfo&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;shinfo =&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SHFILEINFO&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Get the small icon.&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hImgSmall = SHGetFileInfo(filename, 0, shinfo, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Marshal.SizeOf(shinfo), _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SHGFI_ICON&lt;FONT color=#0000ff&gt; Or&lt;/FONT&gt; SHGFI_SMALLICON)&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return&lt;/FONT&gt; System.Drawing.Icon.FromHandle(shinfo.hIcon)&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Function&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;And here is that function being called from a Button Click, the icon then being shown as the Form's icon:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Sub&lt;/FONT&gt; btnSelectFile_Click(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; System.Object,&lt;FONT color=#0000ff&gt; ByVal&lt;/FONT&gt; e&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; System.EventArgs)&lt;FONT color=#0000ff&gt; Handles&lt;/FONT&gt; btnSelectFile.Click&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&lt;/FONT&gt; ofd&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; OpenFileDialog&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If&lt;/FONT&gt; ofd.ShowDialog = Windows.Forms.DialogResult.OK&lt;FONT color=#0000ff&gt; Then&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Me&lt;/FONT&gt;.Icon = GetIcon(ofd.FileName)&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Sub&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;That's pretty much all there is to it, if you are happy to plonk the icon on the form like that. But in most cases you'll probably want something a bit more reusable. One easy way to store the grabbed icon is to put it in an ImageList.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Assuming that you are only going to deal with one icon at a time, you can do something like this:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; myIcons&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; ImageList&lt;BR&gt;myIcons.Images.Add(System.Drawing.Icon.FromHandle(shinfo.hIcon))&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Now that you have that icon safely stored in the ImageList, you can access the ImageList in the usual way if you want to place the icon image elsewhere. And of course you can change the above code slightly to allow for more than one icon to be added to the ImageList and used as required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Finally, if you need to switch the icon into Bitmap format you can use the handy ToBitmap method:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #e0e0e0"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; bmp&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt; Bitmap = System.Drawing.Icon.FromHandle(shinfo.hIcon).ToBitmap&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;It is possible then to save the Bitmap by using the Bitmap's Save method. However, I have found this to be a bit hit-and-miss, with it sometimes throwing a generic GDI+ error when I tried to recall it for use by means of the Image.FromFile method. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I hope that if you need to grab an image from an application that you find this article useful.&lt;/P&gt;---------------------------------------------------------------------- 
&lt;P&gt;&amp;nbsp;&amp;nbsp;* There is the much more hopeful sounding ExtractIcon API which I have used to extract the icon of a currently running VB application, but haven't managed to port the logic over to the kind of file selection scenario described here.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9208.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>WPF: How To Hide the Minimize and Maximize Buttons</title><link>http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx</link><pubDate>Wed, 22 Oct 2008 09:17:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9189.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2008/10/22/9189.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9189.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9189.aspx</trackback:ping><description>&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;For some time now, I've been promising myself that one day I will create a&amp;nbsp;&amp;nbsp;list of what I like&amp;nbsp;to&amp;nbsp;think of as "WPF MIA" - those basic elements&amp;nbsp;that I am totally familiar with in WindowsForms, but which somehow seem to have disappeared into thin air in WPF.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;In many cases of course the tools are still there; it's just that the name has changed.&amp;nbsp;&amp;nbsp; Here's an example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;In Windows Forms, you can hide the Minimize and Maximize buttons by setting the MinimizeBox or MaximizeBox to False&amp;nbsp; I guess that this is most people's favourite way of doing this.&amp;nbsp;If you dig deeper into the Properties Window though, there is also the &amp;nbsp;FormBorderStyle property.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; I used to think that this property was only good for things like changing&amp;nbsp;the border style, say, from 3D to single line.&amp;nbsp; But actually if you choose FixedToolWindow or SizableToolWindow then you automatically get a Form that only has the close button - no Min or Max.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; So what about WPF then? Does it have the same properties available?&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp;&amp;nbsp;If you've spent any time on WPF, you'll know that that's really a rhetorical question because you can almost guarantee that things will have changed.&amp;nbsp;Now though&amp;nbsp;you have a WindowStyle property which you can use to set the Window's border style, including showing or hiding the Max and Min buttons.&amp;nbsp; To have those buttons hidden, you need to choose the &lt;STRONG&gt;ToolWindow&lt;/STRONG&gt; option.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&amp;nbsp; As far as&amp;nbsp;I know, there isn't a property setting that will hide the individual buttons&amp;nbsp;in in WPF.&amp;nbsp; At first I found this a bit surprising.&amp;nbsp;&amp;nbsp; However,&amp;nbsp; as I've become more familiar with WPF and its ability to morph its Windows into almost any conceivable style and shape, I can see that creating your own Window style is so easy that maybe those properties would have been almost redundant anyway.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9189.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>Object Initializers - A New Perspective</title><link>http://blogs.vbcity.com/xtab/archive/2008/08/28/9166.aspx</link><pubDate>Thu, 28 Aug 2008 07:09:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2008/08/28/9166.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9166.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2008/08/28/9166.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9166.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9166.aspx</trackback:ping><description>&lt;FONT face=verdana&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;There's something that's always bothered me a little bit about creating classes. We go to the trouble of creating backing Private fields and Public properties in order to implement data hiding - right?&amp;nbsp;&amp;nbsp; And when we want to include data validation, we usually use properties for that task, don't we? &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; But then what do we do? We go and create a parameterized constructor that lets client code push invalid data straight into a field. At least that's what I see in most of the class building examples I've&amp;nbsp;come across&amp;nbsp;- both in books as well as in real world code. It's quite rare to see values passed into properties in a parameterized constructor; fields seem to be the most popular recipients of initialization data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I'm surprised at how many times I've seen this done. Of course it's possible to include validation in the constructor too (but the examples I've seen that use fields rarely seem to do&amp;nbsp;this; leaving the door to bad data wide open) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Luckily, we now have a very easy solution - Object Initializers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;In fact, you could claim that with the arrival of Object Initializers the parameterized constructor has just about become redundant. &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Parameterized constructors were devised to make it easy to pass arguments in to a constructor and to avoid having to add several lines of code for property values when initializing a new object. You know the sort of thing:-&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; sr&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SalesRecord&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.CustomerName =&lt;FONT color=#a31515&gt; "Joe Soap"&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sr.Total = 2399.65&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;nbsp;&amp;nbsp;etc&amp;nbsp;&amp;nbsp;etc&lt;/FONT&gt;&lt;BR&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;which was short-circuited with :-&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; sr&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; SalesRecord(&lt;FONT color=#a31515&gt;"Joe Soap"&lt;/FONT&gt;, 2399.65)&lt;BR&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;However, as I said, in most cases people code this so that it assigns the CustomerName and Total values directly to the fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Object Initializers step round this issue while still enabling client code to be fairly concise. How it works is that when you initialize an instance of a class object you are allowed to use the 'With' keyword as a way of assigning values to properties, all in one line of code. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Let's knock up a quick class to demo this.&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Class&lt;/FONT&gt; Product&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt; _itemcode&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;/FONT&gt; ItemCode()&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return&lt;/FONT&gt; _itemcode&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Set&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; value&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_itemcode = value&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Set&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt; _cost&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Decimal&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;/FONT&gt; Cost()&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Decimal&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return&lt;/FONT&gt; _cost&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Set&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; value&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Decimal&lt;/FONT&gt;)&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If&lt;/FONT&gt; value &amp;gt; 0&lt;FONT color=#0000ff&gt; Then&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_cost = value&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Else&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_cost = 0&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; If&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Set&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Private&lt;/FONT&gt; _itemname&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;/FONT&gt; ItemName()&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return&lt;/FONT&gt; _itemname&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Get&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Set&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; value&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_itemname = value&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Set&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Property&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Class&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So, three fields, three properties (one of which includes some validation) and just the default constructor. To create a new instance of the Product class and assign values to any of the properties that interest us, this is what we can now do:&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; P1&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; Product&lt;FONT color=#0000ff&gt; With&lt;/FONT&gt; {.ItemName =&lt;FONT color=#a31515&gt; "Widget"&lt;/FONT&gt;, .Cost = 0.99}&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;That's it! &amp;nbsp;&amp;nbsp; A Product instance with those values for the ItemName and Cost properties now exists. And of course the validation is applied effectively at the time of instantiation to avoid any unacceptable values being passed. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Note that the property assignments are contained inside curly braces and not standard parentheses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;There are several advantages to this approach. Not only does it get around the validation problem I mentioned at the start, but it also allows you to pick'n'mix the properties you want to assign values to when you instantiate the object. As you saw in my example above, I chose only to assign values to two of the properties. &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; And if that's not enough to get you interested, there's more. You even have the&amp;nbsp;further advantage that you can pass the values in any order you like (unlike the standard parameter arguments which have to be passed in a strict order). &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; Finally, if there is a parameterized constructor available that contains some, but not all, the arguments you want to pass in, then you can simply combine the two approaches and use the constructor's parameters, as well as the object initializers, all in one chunk of initialization code. &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;So if you had this parameterized constructor in the class:- &lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;Sub&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; code&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; String&lt;/FONT&gt;)&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Me&lt;/FONT&gt;.ItemCode = code&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;End&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; Sub&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;you could use the following code to assign values to all three properties:-&lt;/P&gt;
&lt;DIV style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 2pt"&gt;
&lt;DIV style="FONT-SIZE: 10pt"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy &lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="FONT-SIZE: 15px; OVERFLOW: auto; FONT-FAMILY: 'Courier New'; BACKGROUND-COLOR: #d1eecc"&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; P2&lt;FONT color=#0000ff&gt; As&lt;/FONT&gt;&lt;FONT color=#0000ff&gt; New&lt;/FONT&gt; Product(&lt;FONT color=#a31515&gt;"TOOL12"&lt;/FONT&gt;)&lt;FONT color=#0000ff&gt; With&lt;/FONT&gt; {.ItemName =&lt;FONT color=#a31515&gt; "Spade"&lt;/FONT&gt;, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Cost =&lt;FONT color=#a31515&gt; "12.99"&lt;/FONT&gt;}&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; How cool is that? &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; To be honest, I'm not sure how often I'd want to do that - given that I can do the same thing using three object initializers - but it's an option to consider. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;So there it is. A new feature that you may have heard about but weren't sure if it was going to be of use to you. Personally, I think it's great and plan on implementing this approach whenever I can from now on.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9166.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ged Mead</dc:creator><title>How To Navigate Around Your Code in Visual Studio</title><link>http://blogs.vbcity.com/xtab/archive/2008/07/08/9126.aspx</link><pubDate>Tue, 08 Jul 2008 15:48:00 GMT</pubDate><guid>http://blogs.vbcity.com/xtab/archive/2008/07/08/9126.aspx</guid><wfw:comment>http://blogs.vbcity.com/xtab/comments/9126.aspx</wfw:comment><comments>http://blogs.vbcity.com/xtab/archive/2008/07/08/9126.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.vbcity.com/xtab/comments/commentRss/9126.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/xtab/services/trackbacks/9126.aspx</trackback:ping><description>&lt;FONT face=Verdana&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;One of the things that I've always found a bit frustrating as a project grows larger and larger is that it gets more difficult to navigate backwards and forwards between chunks of code that you've recently accessed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Now I know that Visual Studio has some built in navigation hot keys:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;B&gt;Ctrl and Minus&lt;/B&gt; to go back to the last point, &lt;BR&gt;&lt;B&gt;Ctrl-Shift-Minus&lt;/B&gt; to go forward again are the most useful, &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;but it can still be a bit laborious when you're trying to flit between several sets of code blocks and you don't particularly want to move in a linear or consecutive way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Step forward that very clever little Add-In (well, not so little really!) &lt;B&gt;CodeSMART&lt;/B&gt;. For some reason I'd stopped using it when I upgraded Visual Studios a while back, but when I was looking around for an answer to this problem I remembered that amongst its many little tools is the Code Explorer. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; One of the elements included in the Code Explorer window is a history of the last 20 procedures you've visited. So not only can you&amp;nbsp;move backwards and forwards one step at a time, you can of course jump to any of the saved locations just by double clicking on a choice in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://www.xtabvbcity.plus.com/Blogs/CodeExplorer.jpg" &lt;P &amp;gt;&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;It has some smart features (well, it is Code&lt;EM&gt;Smart &lt;/EM&gt;after all!), one of which is that it greys out any history items from other files - which helps you to very quickly identify those in your current file that you may be looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; And best of all? It persists your history list for each individual Visual Studio Solution, so that the next time you access a particular project Code Explorer will be repopulated with the relevant history for that project. How cool is that? &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;The Code Explorer does have additional features, such as a fast and neat search tool to take you to procedures that match search criteria, together with what's effectively a Favorites store, the Workbench, where you can keep tabs on items you're particularly interested in. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;Of course, CodeSMART has a ton of other features and tools, so if you want to check it out you can download a trial version from their &lt;A href="http://www.axtools.com"&gt;website here&lt;/A&gt;.&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://blogs.vbcity.com/xtab/aggbug/9126.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>