Learning WinForm Group class controls (Panel, GroupBox, TabControl) _c# Tutorials

Source: Internet
Author: User

Grouping class controls include controls such as container controls (Panel), Group box controls (GroupBox), and tab controls (TabControl).

One, Panel control
The Panel control is provided by the System.Windows.Forms.Panel class, and the main role is to put other control groups together on a panel so that the controls are easier to manage. You can set the AutoScroll property to True when you want to display too many controls on the Panel control panels.
The Panel control does not display a border by default, and if you set the BorderStyle property to another value other than none, you can use panels to visually group related controls.
Example: demonstrates the BorderStyle and AutoScroll properties of the Panel control
(1) Add a Panel control to the form, set the AutoScroll property to True, set the BorderStyle property to Fixed3D, add a button control and a ListBox control, Set the button control's Text property to "add".
(2) Double-click the button control to generate the Click event, complete adding a project to the ListBox control and increase its height by 20 in the Click event:

<span style= "FONT-SIZE:18PX;" > private void Button1_Click (object sender, EventArgs e) 
 { 
  listBox1.Items.Add ("subkeys");//Add Subkeys 
  Listbox1.height = listbox1.height + 20;//Increase height 
 }</span> 

The complete form code is:

<span style= "FONT-SIZE:18PX;" >using System; 
Using System.Collections.Generic; 
Using System.ComponentModel; 
Using System.Data; 
Using System.Drawing; 
Using System.Linq; 
Using System.Text; 
Using System.Threading.Tasks; 
Using System.Windows.Forms; 
 
Namespace WindowsFormsApplication3 
{public 
 partial class Form1:form 
 {public 
 Form1 () 
 { 
  InitializeComponent (); 
 } 
 
 private void Button1_Click (object sender, EventArgs e) 
 { 
  listBox1.Items.Add ("subkey");//Add Subkeys 
  Listbox1.height = listbox1.height + 20;//increase height 
 } 
 } 
} 
</span> 

The result of running the form and then clicking the Add button multiple times is:

Second, GroupBox control
The GroupBox control is provided by the System.Windows.Forms.GroupBox class, which is primarily used to provide identifiable groupings for other controls, typically by using a group box to subdivide the form by function.
Example: demonstrating the use of GroupBox controls
Add two GroupBox controls Gpbsystem and Gpbclass on the form, set the Text property of the Gpbsystem control to a line, and place two RadioButton controls, setting their Text property to computer and foreign language department respectively. Also set the Gpbclass Text property to class, and place two RadioButton controls, setting their Text property to "one class" and "Second Class" respectively.
The result of running the form is:

The

third, TabControl control
TabControl control is provided by the System.Windows.Forms.TabControl class by combining related components onto a series of tab pages. The TabControl control manages the TabPages collection, and the Multiline property of the TabControl control is used to set whether to display multiline option Kashun. If the multiline property is set to false and multiple tabs cannot be displayed at once, provide a group arrow to view the remaining tabs. The Appearance property of the TabControl control indicates whether the tab is a Swing button or a General tab, with three values of normal (drawn as a general option), Buttons (drawn as a regular button), and Flatbutton (drawn as a smooth button).
  Click on the TabControl control to add and remove the TabPages collection by adding tabs or by selecting the Remove tab command. You can also add and remove TabPages collections by TabControl control TabPages Properties, which are used to set the content displayed on the tab. The Selectedtab property can determine the current tab. Each time a new tab is selected, the ambulance triggers the SelectedIndexChanged event, confirming the current selection through the SelectedIndex property and the Selectedtab property, and the pending processing can be done according to the tab.
instance: demonstrates the use of the TabControl control
(1) Add a TabControl control on the form and right-click, select the Add tab command, add a tab TabPage1, repeat the action, add a TabPage2, add a button control in TabPage1, change the TabPage1 Text property to option one, and add a TextBox control to the TabPage2. Change the TabPage2 Text property to option two.
(2) Select the TabControl control, locate the SelectedIndexChanged event in the event, double-click the trailing space, and generate the SelectedIndexChanged event. Displays the caption and index of the TabPages of the TabControl control's selected item by the Show method MessageBox:

<span style= "FONT-SIZE:18PX;" > private void Tabcontrol1_selectedindexchanged (object sender, EventArgs e) 
 { 
 MessageBox.Show ("you clicked" + TabControl1.SelectedTab.Text 
        //Uncheck Tab title 
  + "Its index is" +tabcontrol1.selectedindex.tostring ());//Click Tab Index 
 }</span> 

The complete form code is:

<span style= "FONT-SIZE:18PX;" >using System; 
Using System.Collections.Generic; 
Using System.ComponentModel; 
Using System.Data; 
Using System.Drawing; 
Using System.Linq; 
Using System.Text; 
Using System.Threading.Tasks; 
Using System.Windows.Forms; 
 
Namespace WindowsFormsApplication5 
{public 
 partial class Form1:form 
 {public 
 Form1 () 
 { 
  InitializeComponent (); 
 } 
 
 private void Tabcontrol1_selectedindexchanged (object sender, EventArgs e) 
 { 
  MessageBox.Show ("you clicked" + TabControl1.SelectedTab.Text 
         //Deselect tab title 
  + "Its index is" +tabcontrol1.selectedindex.tostring ()); Uncheck Tab Index}} 
</span> 

Click the tab to run the result:

The above is the entire content of this article, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.