WinForm user Control, Timer control, level three linkage

Source: Internet
Author: User

User controls:

The equivalent of a custom panel can be placed in a variety of other controls, and in the background can call the entire custom control.

Usage: Right-click on an item, add, user control, and then edit the user control to resemble a normal container control.

If you want to add to the form in the background, instantiate it, and then add it to the control collection of the container you want to add.

Timer Control:

The last control in the component, which is capable of triggering time based on user-defined intervals, does not impress other events on the form itself.

Property:

Enable to set whether the control is enabled

Interval set the frequency of events, in milliseconds

Event has only one: Tick event

Example: Using the Timer control to get the current time and change instantly

void Timer1_Tick (object sender, EventArgs e)        {            Label1. Text = DateTime.Now.ToString ("yyyy mm month DD Day hh" @ ss seconds ");}     

Control linkage:

Similar region selection, selected province, the back of the drop-down box into the corresponding provinces and counties

PublicForm2 () {InitializeComponent ();//Bind Province Combobox1.datasource =New Chinadata (). Select ("0001"); Combobox1.displaymember ="AreaName"; Combobox1.valuemember ="AreaCode";//Bound City Combobox2.datasource =NewChinadata (). Select (ComboBox1.SelectedValue.ToString ()); Combobox2.displaymember ="AreaName"; Combobox2.valuemember ="AreaCode";//Bound Counties Combobox3.datasource =NewChinadata (). Select (ComboBox2.SelectedValue.ToString ()); Combobox3.displaymember ="AreaName"; Combobox3.valuemember ="AreaCode"; }Privatevoid ComboBox1_SelectedIndexChanged (Objectsender, EventArgs e) {//Bound City Combobox2.datasource =NewChinadata (). Select (ComboBox1.SelectedValue.ToString ()); Combobox2.displaymember ="AreaName"; Combobox2.valuemember = "areacode" ; } private void combobox2_selectedindexchanged (object sender, EventArgs e) {//< Span style= "COLOR: #008000" > bind counties Combobox3.datasource = new  Chinadata (). Select (ComboBox2.SelectedValue.ToString ()); Combobox3.displaymember =  "areaname"  "areacode"       
control linkage Bound region

Entity class

1UsingSystem;2UsingSystem.Collections.Generic;3UsingSystem.Linq;4UsingSystem.Text;56NamespaceWindowsFormsApplication27{8PublicClassChina9{10PrivateString_AreaCode;1112PublicStringAreaCode13{14get {Return_AreaCode; }15set {_AreaCode =Value }16}17PrivateString_areaname;1819PublicStringAreaName20{21stget {Return_areaname; }22set {_areaname =Value }23}24private string _ Parentareacode; 25 26 public string Parentareacode27  {28 get { Return _parentareacode;} 29 set {_parentareacode = Value }30 }31 32 }33}       

Data manipulation classes:

1UsingSystem;2UsingSystem.Collections.Generic;3UsingSystem.Data.SqlClient;4UsingSystem.Linq;5UsingSystem.Text;67NamespaceWindowsFormsApplication28{9PublicClassChinadata10{SqlConnection conn =Null;SqlCommand cmd =Null;1314PublicChinadata ()15{conn =New SqlConnection ("Server=.; Database=data0216;user=sa;pwd=123");+ cmd =Conn. CreateCommand ();18}1920//By a parent number, query the region of the parent number, and put it in a collection.21stPublic list<china> Select (StringPcode)22{List<china> CList =New list<china>();Cmd.commandtext ="Select *from chinastates where Parentareacode = @a";25Cmd. Parameters.clear ();+ cmd. Parameters.addwithvalue ("@a", Pcode);27Conn. Open ();SqlDataReader dr =Cmd. ExecuteReader ();29While(Dr. Read ())30{to China C =NewChina ();C.areacode = dr[0]. ToString (); 33 c.areaname = Dr[1. ToString (); 34 c.parentareacode = Dr[2 ]. ToString (); 35 36  CList. ADD (c); 37 }38  Conn. Close (); 39 return Clist;40 }41 }42}        

Turn off prompt to close

Confirm Cancel

WinForm user Control, Timer control, level three linkage

Related Article

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.