当前位置:网站首页>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 . ![ Insert picture description here ](https://img-blog.csdnimg.cn/ea5c9fb1333b461dbcbd2846e63771b9.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBATXd5bGRuamUyMDAz,size_20,color_FFFFFF,t_70,g_se,x_16) - 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 ");
}
}
}
边栏推荐
- array_ The contains() function uses
- Dos and path
- [solve the error of this pointing in the applet] SetData of undefined
- nn. Exploration and experiment of batchnorm2d principle
- Post man JSON script version conversion
- World document to picture
- JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
- Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
- Entitas learning [iv] other common knowledge points
- Usage of with as
猜你喜欢
2020 Summary - Magic year, magic me
SQL greatest() function instance detailed example
Post man JSON script version conversion
2021-08-09
Notes on writing test points in mind mapping
Global function Encyclopedia
QQ group collection
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
os. Path built-in module
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
随机推荐
Foreach (system.out:: println) usage
Reptile learning 4 winter vacation learning series (1)
Login operation (for user name and password)
How to judge the advantages and disadvantages of low code products in the market?
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
QQ get group settings
If function in SQL
Source code analysis of the implementation mechanism of multisets in guava class library
(August 9, 2021) example exercise of air quality index calculation (I)
thread
os. Path built-in module
Games101 Lesson 8 shading 2 Notes
Simple understanding of generics
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
SQL greatest() function instance detailed example
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Cacti主机模板之定制版
Recommend a cool geospatial data visualization tool with low code
Usage of with as
Notes on writing test points in mind mapping