Search | Contact | Link To Us  

      VB .NET       

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement


     Home> Windows Controls> ToolTip, ErrorProvider 


ToolTip, ErrorProvider

ToolTip

ToolTips are those small windows which display some text when the mouse is over a control giving a hint about what should be done with that control. ToolTip is not a control but a component which means that when we drag a ToolTip from the toolbox onto a form it will be displayed on the component tray. Tooltip is an Extender provider component which means that when you place an instance of a ToolTipProvider on a form, every control on that form receives a new property. This property can be viewed and set in the properties window where it appears as Tooltip on n, where n is the name of the ToolTipProvider.

To assign ToolTip's with controls we use it's SetToolTip method.

Notable property of the ToolTip is the Active property which is set to True by default and which allows the tool tip to be displayed.

Setting a ToolTip

Assume that we have a TextBox on the form and we want to display some text when your mouse is over the TextBox. Say the text that should appear is "Do not leave this blank". The code for that looks like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
ToolTip1.SetToolTip(TextBox1, "Do not leave this blank")
End Sub

The image below displays output from above code.

ErrorProvider Component

The ErrorProvider component provides an easy way to set validation errors. It allows us to set an error message for any control on the form when the input is not valid. When an error message is set, an icon indicating the error will appear next to the control and the error message is displayed as Tool Tip when the mouse is over the control.

Notable property of ErrorProvider in the Appearance section is the Icon property which allows us to set an icon that should be displayed. Notable property in Behavior section is the BlinkRate property which allows to set the rate in milliseconds at which the icon blinks.

Displaying an Error

Let's work with an example. Assume we have a TextBox and a Button on a form. If the TextBox on the form is left blank and if the Button is clicked, an icon will be displayed next to the TextBox and the specified text will appear in the Tool Tip box when the mouse is over the control. The code for that looks like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Cannot leave textbox blank")
Else
ErrorProvider1.SetError(TextBox1, "")
End If
End Sub

The image below displays output from above code.

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.