The current Microsoft Tab control is much, much simpler to create than the first prototypes of a few years ago. A typical Tab control is shown in Figure 19-8.
These are the steps in the build:
Click on the window form to put the form s properties into the Properties window. Click on the Tab Control icon, then move the mouse pointer over the window template and click again. The Tab control emerges.
Expand the Tab control rectangle to the dimensions you desire (for this example make it fairly large) by pulling on the handles at the left, bottom, and right of the control.
Highlight the Tab control to bring up its properties in the Properties window. Scroll down to the bottom of the dialog and find the entry Tab Pages. To the right of Tab Pages is the word (Collection). To the right of (Collection) there is a square with three dots on it. Click on the three dots to reveal the TabPage Collection Editor window shown in Figure 19-9.
Figure 19-9: TabPage Collection Editor window
Highlight tabPage1 of the Members list (or click in the general area of the top of the list), and immediately the properties for tabPage1 will appear in the Properties window. Type the name of the first tab ( Albuquerque, NM ) in the Text entry area. Go back to the Members list, click on the space below tabPage1, and tabPage2 will appear. Move to the Properties window again and type the name of the second tab into the Text entry area. Keep doing this until all tabs have been named. Press OK to exit the TabPage Collection Editor window.
All the tabs should be present on the Tab control, with the names that you gave them. Click on the first tab (the leftmost tab) to highlight the tab field. The Properties window should display the properties of tabControl1. Open the Toolbox , then click on the RichTextBox icon at the bottom of the list. Move to the Tab control and deposit the RichTextBox control onto the Tab control sheet. Pull the RichTextBox control so it fits nicely on the tab sheet.
Click on the RichTextBox control to bring its properties into the Properties window. Scroll down to Text in the properties list and type the word that should go on the tab sheet. Recall that the RichTextBox control allows multiple lines of code ” the TextBox control does not. You must use the RichTextBox. When you are through typing, move the mouse over the Tab control and the text will appear in the control.
Highlight the second tab on the Tab control, move to the Properties window, find Text, and type the words that go into the second tab s tab sheet.
When you have entered all the words into all the tab sheets, you are finished with the Tab control inputs. Place a label across the top of the Tab control (like Driving Distance (miles) from Denver to: ).
To complete the window, add a button to exit.
The code to support the Tab control is shown below:
Form8
Form8.cs: SC1700: #region Using directives [7 lines, same as SC0002 SC0008] SC1708: #endregion SC1709: namespace StandardControls SC1710: { SC1711: partial class Form8 : Form SC1712: { SC1713: public Form8() SC1714: {InitializeComponent(); } //-----------------------------------------------------------------------------------------// SC1715: private void button1_Click(object sender, EventArgs e) SC1716: { // Quit. SC1717: Close(); SC1718: } //-----------------------------------------------------------------------------------------// SC1719: } SC1720: } //=========================================================================================// Form8.Designer.cs: SC1800: namespace StandardControls SC1801: { SC1802: partial class Form8 SC1803: { // Required designer variable. SC1804: private System.ComponentModel.IContainer components = null; // Clean up any resources being used. SC1805: protected override void Dispose(bool disposing) SC1806: { SC1807: if (disposing && (components != null)) components.Dispose(); SC1808: base.Dispose(disposing); SC1809: } SC1810: #region Windows Form Designer generated code // Required method for Designer support - do not modify // the contents of this method with the code editor. SC1811: private void InitializeComponent() SC1812: { SC1813: this.label1 = new System.Windows.Forms.Label(); SC1814: this.label2 = new System.Windows.Forms.Label(); SC1815: this.tabControl1 = new System.Windows.Forms.TabControl(); SC1816: this.tabPage1 = new System.Windows.Forms.TabPage(); SC1817: this.tabPage2 = new System.Windows.Forms.TabPage(); SC1818: this.button1 = new System.Windows.Forms.Button(); SC1819: this.tabPage3 = new System.Windows.Forms.TabPage(); SC1820: this.tabPage4 = new System.Windows.Forms.TabPage(); SC1821: this.richTextBox1 = new System.Windows.Forms.RichTextBox(); SC1822: this.richTextBox2 = new System.Windows.Forms.RichTextBox(); SC1823: this.richTextBox3 = new System.Windows.Forms.RichTextBox(); SC1824: this.richTextBox4 = new System.Windows.Forms.RichTextBox(); SC1825: this.tabControl1.SuspendLayout(); SC1826: this.tabPage1.SuspendLayout(); SC1827: this.tabPage2.SuspendLayout(); SC1828: this.tabPage3.SuspendLayout(); SC1829: this.tabPage4.SuspendLayout(); SC1830: this.SuspendLayout(); // // label1 // SC1831: this.label1.AutoSize = true; SC1832: this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0))); SC1833: this.label1.Location = new System.Drawing.Point(140, 16); SC1834: this.label1.Name = "label1"; SC1835: this.label1.Size = new System.Drawing.Size(117, 24); SC1836: this.label1.TabIndex = 0; SC1837: this.label1.Text = "Tab Controls"; // // label2 // SC1838: this.label2.AutoSize = true; SC1839: this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); SC1840: this.label2.Location = new System.Drawing.Point(23, 54); SC1841: this.label2.Margin = new System.Windows.Forms.Padding(3, 3, 3, 1); SC1842: this.label2.Name = "label2"; SC1843: this.label2.Size = new System.Drawing.Size(221, 17); SC1844: this.label2.TabIndex = 1; SC1845: this.label2.Text = "Driving Distance (miles), Denver to:"; // // tabControl1 // SC1846: this.tabControl1.Controls.Add(this.tabPage1); SC1847: this.tabControl1.Controls.Add(this.tabPage2); SC1848: this.tabControl1.Controls.Add(this.tabPage3); SC1849: this.tabControl1.Controls.Add(this.tabPage4); SC1850: this.tabControl1.Location = new System.Drawing.Point(21, 73); SC1851: this.tabControl1.Margin = new System.Windows.Forms.Padding(3, 1, 3, 1); SC1852: this.tabControl1.Name = "tabControl1"; SC1853: this.tabControl1.SelectedIndex = 0; SC1854: this.tabControl1.Size = new System.Drawing.Size(376, 136); SC1855: this.tabControl1.TabIndex = 2; // // tabPage1 // SC1856: this.tabPage1.Controls.Add(this.richTextBox1); SC1857: this.tabPage1.Location = new System.Drawing.Point(4, 22); SC1858: this.tabPage1.Name = "tabPage1"; SC1859: this.tabPage1.Padding = new System.Windows.Forms.Padding(3); SC1860: this.tabPage1.Size = new System.Drawing.Size(368, 110); SC1861: this.tabPage1.TabIndex = 0; SC1862: this.tabPage1.Text = "Albuquerque, NM"; // // tabPage2 // SC1863: this.tabPage2.Controls.Add(this.richTextBox2); SC1864: this.tabPage2.Location = new System.Drawing.Point(4, 22); SC1865: this.tabPage2.Name = "tabPage2"; SC1866: this.tabPage2.Padding = new System.Windows.Forms.Padding(3); SC1867: this.tabPage2.Size = new System.Drawing.Size(368, 110); SC1868: this.tabPage2.TabIndex = 1; SC1869: this.tabPage2.Text = "Kansas City, MO"; // // button1 // SC1870: this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); SC1871: this.button1.Location = new System.Drawing.Point(176, 230); SC1872: this.button1.Name = "button1"; SC1873: this.button1.Size = new System.Drawing.Size(75, 25); SC1874: this.button1.TabIndex = 3; SC1875: this.button1.Text = "Quit"; SC1876: this.button1.Click += new System.EventHandler(this.button1_Click); // // tabPage3 // SC1877: this.tabPage3.Controls.Add(this.richTextBox3); SC1878: this.tabPage3.Location = new System.Drawing.Point(4, 22); SC1879: this.tabPage3.Name = "tabPage3"; SC1880: this.tabPage3.Size = new System.Drawing.Size(368, 110); SC1881: this.tabPage3.TabIndex = 2; SC1882: this.tabPage3.Text = "Billings, MT"; // // tabPage4 // SC1883: this.tabPage4.Controls.Add(this.richTextBox4); SC1884: this.tabPage4.Location = new System.Drawing.Point(4, 22); SC1885: this.tabPage4.Name = "tabPage4"; SC1886: this.tabPage4.Size = new System.Drawing.Size(368, 110); SC1887: this.tabPage4.TabIndex = 3; SC1888: this.tabPage4.Text = "Salt Lake City, UT"; // // richTextBox1 // SC1889: this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; SC1890: this.richTextBox1.Location = new System.Drawing.Point(4, 7); SC1891: this.richTextBox1.Name = "richTextBox1"; SC1892: this.richTextBox1.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\ fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\lang1033\f0\fs17 Albuquerque, New Mexico is 439 miles south of Denver, on Interstate 25. Driving time is about 8 hours. You will pass through Raton Pass, which in times past was one of the more exciting passes to drive through [until the road was four-laned]. Santa Fe is on the route, about 70 miles north of Albuquerque. On the way back to Denver you should visit Los Alamos, the Bandelier National Monument, and Taos.\par } "; SC1893: this.richTextBox1.Size = new System.Drawing.Size(358, 106); SC1894: this.richTextBox1.TabIndex = 0; // // richTextBox2 // SC1895: this.richTextBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; SC1896: this.richTextBox2.Location = new System.Drawing.Point(4, 10); SC1897: this.richTextBox2.Name = "richTextBox2"; SC1898:; this.richTextBox2.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\ fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\lang1033\f0\fs17 Kansas City is 605 miles east of Denver, on Interstate 70. Driving time is about 12 hours. About halfway there, you will see the Russell Stover's chocolate factory on the south side of the interstate. Be sure to stop there. Mr. Stover invented the Eskimo Pie in the 1920s in Chicago. You will also pass by Abilene, KS, President Eisenhower's boyhood home. \par } "; SC1899: this.richTextBox2.Size = new System.Drawing.Size(361, 98); SC1900: this.richTextBox2.TabIndex = 0; // // richTextBox3 // SC1901: this.richTextBox3.BorderStyle = System.Windows.Forms.BorderStyle.None; SC1902: this.richTextBox3.Location = new System.Drawing.Point(1, 7); SC1903: this.richTextBox3.Margin = new System.Windows.Forms.Padding(3, 0, 3, 3); SC1904: this.richTextBox3.Name = "richTextBox3"; SC1905: this.richTextBox3.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\ fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\lang1033\f0\fs17 Billings, Montana is 554 miles north of Denver, on Interstate 25. Driving time is about 11 hours. As soon as you enter Montana, look for the Custer Battlefield, which is adjacent to the freeway. Custer doesn't live there any more. On the way back to Denver, stop in Cheyenne and visit the home of the great-granddaddy of all rodeos, 'Cheyenne Days'.\par } "; SC1906: this.richTextBox3.Size = new System.Drawing.Size(365, 92); SC1907: this.richTextBox3.TabIndex = 0; // // richTextBox4 // SC1908: this.richTextBox4.BorderStyle = System.Windows.Forms.BorderStyle.None; SC1909: this.richTextBox4.Location = new System.Drawing.Point(-2, 7); SC1910: this.richTextBox4.Name = "richTextBox4"; SC1911: this.richTextBox4.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\ fnil\fcharset0 Microsoft Sans Serif;}} \viewkind4\uc1\pard\lang1033\f0\fs17 Salt Lake City is 512 miles west and a little north of Denver, on the west side of the Rocky Mountains. Driving time is about 10 hours. There are two ways to get there: Go north on I-25 to Cheyenne and turn west on I-80. This way you can see 'Little America' in western Wyoming. Or you can go west from Denver on I-25 until it quits at Interstate 15 in Utah, and follow 15 north to SLC. This way you follow the Colorado River west after you pass through Glenwood Springs. This is probably the most scenic mountain ride in the USA.\par } "; SC1912: this.richTextBox4.Size = new System.Drawing.Size(368, 106); SC1913: this.richTextBox4.TabIndex = 0; // // Form8 // SC1914: this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); SC1915: this.ClientSize = new System.Drawing.Size(414, 260); SC1916: this.Controls.Add(this.button1); SC1917: this.Controls.Add(this.tabControl1); SC1918: this.Controls.Add(this.label2); SC1919: this.Controls.Add(this.label1); SC1920: this.Name = "Form8"; SC1921: this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; SC1922: this.Text = "Tab Controls"; SC1923: this.tabControl1.ResumeLayout(false); SC1924: this.tabPage1.ResumeLayout(false); SC1925: this.tabPage2.ResumeLayout(false); SC1926: this.tabPage3.ResumeLayout(false); SC1927: this.tabPage4.ResumeLayout(false); SC1928: this.ResumeLayout(false); SC1929: this.PerformLayout(); SC1930: } SC1931: #endregion SC1932: private System.Windows.Forms.Label label1; SC1933: private System.Windows.Forms.Label label2; SC1934: private System.Windows.Forms.TabControl tabControl1; SC1935: private System.Windows.Forms.TabPage tabPage1; SC1936: private System.Windows.Forms.TabPage tabPage2; SC1937: private System.Windows.Forms.Button button1; SC1938: private System.Windows.Forms.TabPage tabPage3; SC1939: private System.Windows.Forms.TabPage tabPage4; SC1940: private System.Windows.Forms.RichTextBox richTextBox1; SC1941: private System.Windows.Forms.RichTextBox richTextBox2; SC1942: private System.Windows.Forms.RichTextBox richTextBox3; SC1943: private System.Windows.Forms.RichTextBox richTextBox4; SC1944: } SC1945: }