CODE CORRECTION - "RichTextBoxTest"
Problem:
Customer was going through the sample "RichTextBoxTest" within chapter 13
"Using Windows Form Controls".
The eventhandler "txtSize_Validating" in book is as followed:
private void txtSize_Validating(object sender, CancelEventArgs e)
{
TextBox txt = (TextBox)sender;
ApplyTextSize(txt.Text);
this.rtfText.Focus();
}
This will raise a convert exception when the TextBox.Text is empty, because
the is no check on the length of txt.Text.
Correction/fix:
Customer inserted the marked line:
private void txtSize_Validating(object sender, CancelEventArgs e)
{
TextBox txt = (TextBox)sender;
--> if (txt.Text.Length > 0)
ApplyTextSize(txt.Text);
this.rtfText.Focus();
}
XUMUSKIEFAN
Wrox Moderator
__________________
XUMUSKIEFAN
Wrox Moderator
|