当前位置:网站首页>13、 C window form technology and basic controls (3)
13、 C window form technology and basic controls (3)
2022-07-04 12:03:00 【Mwyldnje2003】
1、GroupBox Control
- GroupBox Control is created by System.Windows.Forms.GroupBox Class provides the , The function is to provide identifiable groups for other spaces
- On the same page , Show multiple groups of radio choices RadioButton( If you do not use this control , There can only be one group of single choices in a single form RadioButton)
- Usually , Use the grouping box to subdivide the form by function , for example : A student is choosing a class and department , To subdivide the form , You can use two GroupBox Control to set , use Text Attribute to achieve the purpose of grouping prompts .

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 _27GropuBox Control
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btmsubmit_Click(object sender, EventArgs e)
{
string mystr = "";
foreach (Control ourctrl in groupBox2.Controls) //controls Represents a collection of controls
{
if (ourctrl is RadioButton) // Determine the control type
{
if (((RadioButton)ourctrl).Checked) // The result of traversal is ordinary control , Cast to RadioButton Then judge whether it is selected
{
mystr += " You belong to :" + ourctrl.Text;
}
}
}
foreach (Control ourctrl in groupBox1.Controls) //controls Represents a collection of controls
{
if (ourctrl is RadioButton) // Determine the control type
{
if (((RadioButton)ourctrl).Checked) // The result of traversal is ordinary control , Cast to RadioButton Then judge whether it is selected
{
mystr += "\n Your race is :" + ourctrl.Text;
}
}
}
MessageBox.Show(mystr, " The result of the selection is ");
}
}
}
2、TabControl Control
TabControl Control is created by System.windows.Forms.TabControl Class provides the , The function is to combine relevant components into a series of tab pages .
Multiline Property is used to set whether to display multiline tabs , If false, There are multiple tabs that cannot be displayed at one time , Provide group arrows to view the remaining tabs


Appearance Attributes refer to whether the display tab is drawn as a button or a regular think card , This attribute has three values Normal( Draw as general options )、Buttons( Draw as regular buttons )、FaltButton( Draw as smooth button )
TabControl Control management TabPage aggregate
add to / Delete TabPage aggregate
Right click 【 Add Tab 】 Or select 【 Remove tab 】 Be careful : The currently selected tab is removed , Instead of the tab you right-click


TabPages Property to add and remove


TabPages Of text Property is used to set the content displayed on the tab
SelectedTab Property can determine the current tab . Every time you select a new tab , Will get rid of SelectedIndexChanged event , adopt SelectedIndex Properties and SelectedTab Property to confirm the current selection , You can perform specific processing according to the tab .

- Set up TabControl when , Be sure to see TabPages Or choose TabControl Control properties
- Own attributes ctl+tab( It can be used ctrl+tab Switch tabs , There is no need to set it separately , With this attribute )
using System;
using System.Windows.Forms;
namespace _28_TabControl Control
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(" You click on the "+tabControl1.SelectedTab.Text+"\n The index value is "+tabControl1.SelectedIndex.ToString()," The result of your choice ");
}
}
}
3、MenuStrip Controls and ContexMenuStrip Control
3.1 MenuStrip Control
- Menu is the main way for users to obtain the main functions and use the program in the studio program , For example, create a new file 、 Open files, etc .
- MenuStrip Control by System.windows.Forms.MenuStrip Class provides , But with the previous MainMenu Control , It is the container of the application menu structure . When creating menus , To give MenuStrip Controls to add ToolStripMenu Object this operation can be completed when setting , It can also be done in code .





3.2 ContextMenuStrip Control
ContextMenuStrip Control is created by System.Windows.Forms.ContextMenuStrip Class provides . It's also ToolStripMenu Object's container , Used to create the menu displayed by right clicking the form . The main event is response Click event 
add to contextMenuStrip

3.3 ToolTip— Tooltip control
Hover over a menu , Prompt menu function
add to ToolTip: Put the control where you need prompt

add to ToolTip Content
choice ToolTip Control of placement position ,
4、ToolStrip Control
Toolbar is another common way to get the main functions of an application , More intuitive than the menu bar .
ToolStrip Control use System.Windows.Forms.ToolStrip Class provides the , The function is to create a common toolbar for depression customization , Let these toolbars support advanced user interface and layout functions , Such as docking , floating , Button with text and image , Pull down buttons, etc .
ToolStrip The property manager of the control, the display position and display mode of the control , yes MenuStrip The foundation of the control (Toolstrip Belong to MenuStrip A kind of )

- AllowItemRecorder:: The value is True, Allow... At run time Alt+ Drag to move the control position , Otherwise you can't move - Dock: determine ToolStrip Display position , When None You can drag it to the desired position .  - LayoutStyle:ToolStrip How to display the controls added in , General coordination Doke Use it together

- GripStyle: Set the visibility of the handle

- Items: subset
- ShowItemToolStrip: Set whether to display the control prompt in the toolbar ( Whether to display a prompt on the mouse over toolbar control )
- stay ToolStrip Many controls can be used in , Such as toolbar Contains buttons 、 Combo box 、 The text box . In addition to these , Toolbars can also contain other controls



5、StatusStrip Control
- The status bar is used to display brief information about the user's status .
- StatusStrip Control : from System.Windows.Forms.StatusStrip Class provides , It is used to identify the column at the bottom of the dialog box in the application , Usually used to display short information about the current state of the application .
- stay StatusStrip Can be used in ToolStrip Three of the controls introduced in —ToolStripDropDownButton、ToolStripProgressBarhe and ToolStripSplitButton
- Another control is StatusStrip A dedicated , namely StatusStripStatusLable, The function is to use text and images to display the current status information of the application to the user .


There is something wrong with the following code , The line number is not obtained
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 _32_StatusStrip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = DateTime.Now.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = DateTime.Now.ToString();
}
private void textBox1_Click(object sender, EventArgs e)
{
// The characters in the text are arranged from the first character ( The index value is 0) Began to increase continuously , Calculate the row and column through the index value
// Get the index value of the first character of the current line
int index = textBox1.GetFirstCharIndexOfCurrentLine();
// Calculate line number
int line = textBox1.GetFirstCharIndexFromLine(index)+1;
// Count columns
int column = textBox1.SelectionStart - index + 1;
toolStripStatusLabel4.Text = " The first " + line.ToString() + " That's ok , The first " + column.ToString() + " Column ";
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
// The characters in the text are arranged from the first character ( The index value is 0) Began to increase continuously , Calculate the row and column through the index value
// Get the index value of the first character of the current line
int index = textBox1.GetFirstCharIndexOfCurrentLine();
// Calculate line number
int line = textBox1.GetFirstCharIndexFromLine(index) + 1;
// Count columns
int column = textBox1.SelectionStart - index + 1;
toolStripStatusLabel4.Text = " The first " + line.ToString() + " That's ok , The first " + column.ToString() + " Column ";
}
}
}
Mission implementation
Realize a simple window login




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 Mission implementation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = " Welcome to this system , Please log in before using ";
toolStripStatusLabel2.Text = " Our website : Under construction , Coming soon ";
toolStripStatusLabel3.Text = DateTime.Now.ToString();
// hide MenuStrip Control
menuStrip1.Visible = false;
toolStrip1.Visible = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel3.Text = DateTime.Now.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text;
string pwd = textBox2.Text;
if (name == "darly" && pwd == "darly")
{
MessageBox.Show(" Welcome to the system ", " Login successful ");
this.panel1.Visible = false;
this.menuStrip1.Visible = true;
toolStripStatusLabel1.Text = " welcome " + name + " Log in to this system ";
toolStripMenuItemShow.Enabled = true;
toolStripMenuItemHid.Enabled = false;
}
else
{
MessageBox.Show(" Wrong user name or password , Please re-enter ", " Login failed ");
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
}
private void newly build ToolStripMenuItem_Click(object sender, EventArgs e)
{
int maxval = 0;
foreach (Form myform in this.MdiChildren)
{
int index =Convert.ToInt32( myform.Text.Substring(4, 1));
if (index > maxval)
{
maxval = index;
}
}
registerForm myRegisterForm = new registerForm();
myRegisterForm.MdiParent = this;
myRegisterForm.Text = " Registration information " + Convert.ToString(++maxval);
myRegisterForm.BringToFront();
myRegisterForm.Show();
}
private void Close the current form CToolStripMenuItem_Click(object sender, EventArgs e)
{
Form myactiveForm = this.ActiveMdiChild; // Determine the current window
myactiveForm.Close();
}
private void sign out XToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show(" Please save all files before exiting \n Please confirm whether to exit , To exit, press yes , Please press no to cancel ", " Exit prompt ", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) this.Close();
}
private void toolStripMenuItemCas_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void toolStripMenuItemVer_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void toolStripMenuItemHor_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void toolStripMenuItemShow_Click(object sender, EventArgs e)
{
toolStrip1.Visible = true;
toolStripMenuItemHid.Enabled = true;
toolStripMenuItemShow.Enabled = false;
}
private void toolStripMenuItemHid_Click(object sender, EventArgs e)
{
toolStrip1.Visible = false;
toolStripMenuItemHid.Enabled =false;
toolStripMenuItemShow.Enabled = true;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
int maxval = 0;
foreach (Form myform in this.MdiChildren)
{
int index = Convert.ToInt32(myform.Text.Substring(4, 1));
if (index > maxval)
{
maxval = index;
}
}
registerForm myRegisterForm = new registerForm();
myRegisterForm.MdiParent = this;
myRegisterForm.Text = " Registration information " + Convert.ToString(++maxval);
myRegisterForm.BringToFront();
myRegisterForm.Show();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
Form myactiveForm = this.ActiveMdiChild; // Determine the current window
myactiveForm.Close();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show(" Please save all files before exiting \n Please confirm whether to exit , To exit, press yes , Please press no to cancel ", " Exit prompt ", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) this.Close();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void toolStripMenuItemAbout_Click(object sender, EventArgs e)
{
MessageBox.Show(" This software is produced by self-study network "," System introduction ");
}
}
}
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 Mission implementation
{
public partial class registerForm : Form
{
public registerForm()
{
InitializeComponent();
}
private void registerForm_Load(object sender, EventArgs e)
{
}
string race;
string language;
private void button1_Click(object sender, EventArgs e)
{
foreach (Control outctrl in panel1.Controls)
{
if (outctrl is RadioButton)
if (((RadioButton)outctrl).Checked)
race = outctrl.Text;
}
foreach (Control outctrl in panel2.Controls)
{
if (outctrl is RadioButton)
if (((RadioButton)outctrl).Checked)
language = outctrl.Text;
}
MessageBox.Show(" Your registration information is :\n full name :" + textBox1.Text + "\n Company :" + textBox2.Text + " Gender :" + comboBox1.SelectedItem + "\n Age :" + numericUpDown2.Value + "\n race :" + race + "\n Favorite language :" + language, " Thank you for registering ");
}
}
}
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
- TCP fast retransmission sack mechanism
- In 2022, financial products are not guaranteed?
- array_ The contains() function uses
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
- 2021-08-09
- Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
- Decrypt the advantages of low code and unlock efficient application development
- Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
- Login operation (for user name and password)
猜你喜欢

(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
![Entitas learning [3] multi context system](/img/f9/a3ce86ff2121dd1043305b7e834cc5.jpg)
Entitas learning [3] multi context system

Simple understanding of seesion, cookies, tokens
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22](/img/e0/21367eeaeca10c0a2f2aab3a4fa1fb.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22

QQ group administrators

Detailed array expansion analysis --- take you step by step analysis

How to create a new virtual machine
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15](/img/72/0fe9cb032339d5f1ccf6f6c24edc57.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15

Login operation (for user name and password)
![[solve the error of this pointing in the applet] SetData of undefined](/img/19/c34008fbbe1175baac2ab69eb26e05.jpg)
[solve the error of this pointing in the applet] SetData of undefined
随机推荐
A few words explain redis cache penetration, breakdown, avalanche, and redis sentinel
re. Sub() usage
Snowflake won the 2021 annual database
How to deal with the relationship between colleagues
OSI seven layer reference model
LxC shared directory permission configuration
Global function Encyclopedia
Games101 Lesson 8 shading 2 Notes
Shift EC20 mode and switch
Understanding of object
Heartbeat启动后无反应
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
Climb Phoenix Mountain on December 19, 2021
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
DDS-YYDS
Analysis function in SQL
Configure SSH certificate login
Common tips
template<typename MAP, typename LIST, typename First, typename ... Keytypes > recursive call with indefinite parameters - beauty of Pan China