Chapter 21: Timers and Clocks

 

Edit Controls

There are two edit controls on the Toolbox: TextBox and RichTextBox. The TextBox cannot be set to a depth (vertically) such that it wraps the text onto a lower line. If the user types too many characters in the TextBox control, the text scrolls to the left and is hidden.

The RichTextBox control can be set in depth (vertically) to accommodate several lines of text. The text that the user enters will wrap onto the next lower line when the upper line is filled.

image from book
Figure 19-2: Edit Controls window

These edit controls are fully wired with event handlers that take the data entered by the user from the edit control and place it in a persistent location in the main window (frmParent.strForm2EditBox, and frmParent.strForm2RichEditBox, lines SC0332 and SC0342). These variables are declared in Form1, lines SC0013-SC0014. The code for the edit boxes is shown below:

Form2

 Form2.cs: SC0300:       #region Using directives               [7 lines, same as SC0002  SC0008] SC0308:       #endregion SC0309:       namespace StandardControls SC0310:       { SC0311:         partial class Form2 : Form SC0312:         { SC0313:           public Form1 frmParent; // Send and receive info to/from Form 1. SC0314:           public Form2(Form1 frm) SC0315:           { SC0316:             frmParent = frm; // Handle to Form1. SC0317:             InitializeComponent(); SC0318:           } //-----------------------------------------------------------------------------------------// SC0320:           private void textBox1_TextChanged(object sender, EventArgs e) SC0321:           { // Edit box.                     // This is where you check for correct input. SC0322:             return; SC0323:           } //-----------------------------------------------------------------------------------------// SC0324:           private void richTextBox1_TextChanged(object sender, EventArgs e) SC0325:           { // Rich text editbox.                     // This is where you check for correct input. SC0326:             return; SC0327:           } //-----------------------------------------------------------------------------------------// SC0330:           private void textBox1_Leave(object sender, EventArgs e) SC0331:           { // Editbox leave.                     // Place the 'textBox1.Text' into a persistent variable. SC0332:             frmParent.strForm2EditBox = textBox1.Text; SC0333:           } //-----------------------------------------------------------------------------------------// SC0340:           private void richTextBox1_Leave(object sender, EventArgs e) SC0341:           { // Rich textbox leave.                     // Place the 'richTextBox1.Text' into a persistent variable. SC0342:             frmParent.strForm2RichEditBox = richTextBox1.Text; SC0343:           } //-----------------------------------------------------------------------------------------// SC0350:           private void button1_Click(object sender, EventArgs e) SC0351:           { // Quit. SC0352:             Close(); SC0353:           } SC0354:         } SC0355:       } //=========================================================================================// Form2.Designer.cs: SC0400:       namespace StandardControls SC0401:       { SC0402:         partial class Form2 SC0403:         {                   // Required designer variable. SC0404:           private System.ComponentModel.IContainer components = null;                   // Clean up any resources being used. SC0405:           protected override void Dispose(bool disposing) SC0406:           { SC0407:             if (disposing && (components != null)) components.Dispose(); SC0408:             base.Dispose(disposing); SC0409:           } SC0410:           #region Windows Form Designer generated code                   // Required method for Designer support. SC0411:           private void InitializeComponent() SC0412:           {                     [3 labels, 1 textBox, 1 richTextBox, 1 button, 60 lines] SC0473:           } SC0474:           #endregion SC0475:           private System.Windows.Forms.Label label1; SC0476:           private System.Windows.Forms.Label label2; SC0477:           private System.Windows.Forms.Label label3; SC0478:           private System.Windows.Forms.TextBox textBox1; SC0479:           private System.Windows.Forms.RichTextBox richTextBox1; SC0480:           private System.Windows.Forms.Button button1; SC0481:         } SC0482:       } 
 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net