1.ErrorProvider Controls
(1) Purpose: Without affecting the user operation of the situation to show the user error occurred, generally in verifying that the user input data is commonly used to the control, this is like a Web application in the CompareValidator and other validation controls.
(2) errors in the specified control are generally set by the SetError method of the ErrorProvider control.
public void SetError (Control control,string value)
The control that the parameter control represents to set the error description string for
The parameter value represents a string that describes the error message
(3) Example code:
The General Judgment logic is written in the validating event of the background control itself.
private void Textbox1_validating (object sender, System.ComponentModel.CancelEventArgs e) {if (t Extbox1.text = = "")//To determine whether to enter the product name {errorProvider1.SetError (TextBox1, "cannot be empty");//If no input is activated Errorprov Ider1 Control} else {errorProvider1.SetError (TextBox1, "");//ErrorProvider1 control Do not display message}} private void Textbox2_validating (object sender, System.ComponentModel.CancelEventArgs E {if (TextBox2.Text = = "")//determine if input {errorprovider2.seterror (TextBox2, "cannot be empty ");//Set ErrorProvider2 error prompt} else {try { int x = Int32.Parse (TextBox2.Text);//Determine whether to enter a number, if not the number will appear abnormal errorprovider2.seterror (TextBox2, "");/ER RorProvider2 control does not display any error messages} catch {//If an exception occurs, set ErrorProvider Error message for 2 control Errorprovider2.seterror (TextBox2, "Please enter a number"); }}} private void Textbox3_validating (object sender, System.ComponentModel.CancelEventArgs e) {if (TextBox3.Text = = "")//determine whether to enter {Errorprovider3.seterror (TEXTBOX3, "cannot be empty"); /Set ERRORPROVIDER3 display error message} else {errorprovider3.seterror (TextBox3, "");// ErrorProvider3 control does not display any messages}}
Run:
2.HelpProvider Controls
This is not much to say, mainly to call the Help file.
This is mainly HelpNamespace, the property that specifies the name of the Help file and the Setshowhelp (Control,value) method
Note: First create the Help.htm help document in the program's Bin file.
Main code:
String strpath= "help.htm";//Setting the location of the Help file
helpprovider1.helpnamespace=strpath;//Setting the HelpNamespace property, setting the Help file path
Helpprovider1.setshowhelp (this,true);//Set method specifies whether to display help information for a control
3.Timer Control------Important, commonly used
(1) Purpose: Event is raised periodically, the length of the interval is defined by its Interval property , and its attribute value is in milliseconds.
When the control is started, a tick event is raised for each event interval, and we can add code to perform the action in the Tick event.
(2) The Interval property is used to set the event interval at which the timer starts timing.
public int interval{get;set;}
The value represents the number of milliseconds between each start of the timer, and the value is not less than 1.
(3) The start and stop methods of the timer control are used to start and stop timers, respectively
(4) example part of important code: Display the current system time
private void Form1_Load (object sender, EventArgs e) { timer1. Interval = 1000;//Setting Interval property is 1000 milliseconds } private void Timer1_Tick (object sender, EventArgs e)//timer1 control's Tick event { TextBox1.Text = DateTime.Now.ToString ();//Get system current date }
Run:
4.ProgressBar Control-----Important, commonly used
(1) Purpose: to indicate the progress of the work by displaying the appropriate number of rectangular blocks in a horizontally placed box, the progress bar is filled when the work is completed, the progress bar is used to help the user understand the progress of waiting for a job to complete, so it is a good human-computer interaction control.
(2) Important properties and methods
Value indicates progress that has been completed during the operation
Minimum setting the minimum value of the progress bar
Maximum setting the maximum value of the progress bar
STEP Specifies the value of the Increment property
PerformStep Increment Step value
(3) example part of important code
private void Button1_Click (object sender, EventArgs e) { progressBar1.Value = 0;//Sets the initial value of the progress bar Progressbar1.minimum = 0;//Set the Minimum value of the ProgressBar1 control to 0 progressbar1.maximum = 500;// Set the maximum value of progressBar1 to progressbar1.step = 1;//Set the value of PROGRESSBAR1 to 1 for (int i = 0; i <; i++)// Call the For Statement loop increment { progressbar1.performstep ();//Use the PerformStep method to increment by step value TextBox1.Text = "Progress value:" + ProgressBar1.Value.ToString (); } }
Run: