After completion of today's lab, you should be able to
While we would all like to design systems that are so intuitive and self-evident that uses never need assistance, the reality is that for some users, a good help system needs to be made available.
Providing help can take many forms: user manuals and documentation, web site support, wizards or agents, context-sensitive help, pop-up tips, and any number of other means.
One way of designing help systems is in examining the types of questions users may ask:
Software designers need to consider providing support each of these type of questions.
The Windows Forms ToolTip extender control can be used to display a short, specialized help message for individual controls to answer questions of the type: What is this? or What does this do?
To add tooltips to your controls, using the Toolbox, drag and drop a ToolTip provider onto your Form. Once a ToolTip provider has been added to the form, to set a tooltip for any particular control
Tooltips are most often used to display the name or directions for graphical controls that lack text labels. A good example is a toolbar, which in Visual Studio.NET, provides its own mechanism for providing tooltips.
See Design guidelines for Tooltips.

Activity: - Create an Email Dialog Box
WindowsUI in solution Lab8MainForm.csMainForm to create the email form shown at the right.Activity - Add a Tooltip Control
toolTip1 will be placed in the component tray.toTextBox and set the ToolTip on toolTip1 to "Enter the recipient's Email address"
For many users, images can often be faster and easier to recognize than text. Coming up with the right images can be tough however.
Activity - Add a image to the Send Email button
SendEmailButton and set its Image property to the the file sendEmail.gifWhile we do not need it for this prototype, .NET does allow for the sending of Email.
using System.Web.Mail; to your codeSendEmailButton_Click event handler method
using System.Net.Mail;
private void sendEmailButton_Click(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage(fromTextBox.Text, toTextBox.Text);
mail.Subject = subjectTextBox.Text;
mail.Body = messageTextBox.Text;
// your real server should go here, this will not work from lab
// SmtpClient s = new SmtpClient("localhost");
// s.Send(mail);
}
Whenever code has the potential to throw an error, consider placing it inside a try..catch statement.
The text for tooltips may be set in code as well as with Visual Studio's designer.
private void SendEmailButton_MouseEnter(object sender, System.EventArgs e)
{
toolTip1.SetToolTip(sendEmailButton, "Send email to " + toTextBox.Text);
}
While tooltips can be considered a form of context-sensitive help, .NET provides another extender control for providing context-sensitive help when the user presses the F1 function key: the HelpProvider Component.
Activity - Add a HelpProvider component to your Form
helpProvider1 will be placed in the component tray.fromTextBox and set the HelpString on helpProvider1 to "Enter your Email address"fromTextBox and pressing F1
This works OK if the user knows about it. The Status Bar area can be used to display a brief context-sensitive message related to the screen item with the focus.
Activity - Add a StatusStrip to your Form
toolStripStatusLabel1's Text property to the empty stringfromTextBox to set the message in the Status Bar with the Focus enters and leaves the fromTextBoxfromTextBoxprivate void fromTextBox_Enter(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Press F1 for Help"; } private void fromTextBox_Leave(object sender, EventArgs e) { toolStripStatusLabel1.Text = String.Empty; }

One form of the What's This help button is a icon located on the title bar of a secondary window. In Visual Studio.Net it is used in combination with the HelpProvider control as another way to produce context-sensitive help.
Activity - Add a What's This help button
MainForm and set the HelpButton property to TruefromTextBoxUsing HTML Help files with a browser or as compiled help files has become another common way to provide online help.
We can create a quick-and-dirty version of HTML help in Visual Studio by
helpProvider1 control and setting its HelpNameSpace property to point to the WebPages/index.html file we created
../../WebPages/index.html"Microsoft makes available a HTML Help SDK that you would want to download and install if you decide to make use of advanced HTML Help features
You can invoke the simple Help HTML page in a browser from a menu item or button by using the static method ShowHelp in .NET's Help class
private void helpButton_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, helpProvider1.HelpNamespace);
}
Or, to invoke the user's default Web browser to display help from a Internet address, one could use the Process.Start method
System.Diagnostics.Process.Start("http://www.cwu.edu/~gellenbe/index.php");
Validation of user input is a huge part of any user interface project. One advantage of using radio buttons, list boxes, combo boxes, DateTimePickers, etc. is that they constrain user input so that validation becomes less of an issue.
User input in text boxes, on the other hand, should be checked for legal values and any errors reported back to the user.
Activity: Require a "To" Email address
isValidEmailAddress to require a "To" Email address before the email gets sentprivate bool isValidEmailAddress() { if (toTextBox.Text.Length == 0) { MessageBox.Show("Please enter the Email address to send to", "Send Email", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else { return true; } }
Message Boxes can get pretty annoying if there are too many of them. A cleaner approach to providing an error message for invalid user input is to use an ErrorProvider component.
Activity: Add an ErrorProvider component
ErrorProvider component onto your EmailFormisValidEmailAddress method to use errorProvider1 to display the error private bool isValidEmailAddress() { if (toTextBox.Text.Length == 0) { errorProvider1.SetError(toTextBox, "E-mail address required"); return false; } else { errorProvider1.SetError(toTextBox, ""); return true; } }
Regular expressions are very useful for error checking user input
using System.Text.RegularExpressions;
//Only allow cwu.edu e-mail addresses
Regex regularExp = new Regex("^[A-Za-z0-9]+@cwu\\.edu$");
if (!regularExp.IsMatch(toTextBox.Text.Trim())
//error - incorrect e-mail entered
URL: http://www/cwu.edu /~gellenbe/446/labs/lab8.php
Author: Ed Gellenbeck, Department of Computer Science, Central Washington University, gellenbe@cwu.edu
Copyright 2006 Ed Gellenbeck, Central Washington University
Last modified: March 22, 2008