1、多文档窗体(MDI Form)功能演示
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 Demo_MDIForm { public partial class Form1 : Form { private Form2 aForm; public Form1() { InitializeComponent(); } private void mi_File_Exit_Click(object sender, EventArgs e) { Close(); } private void mi_File_OpenForm2_Click(object sender, EventArgs e) { if (aForm==null) aForm = new Form2(); aForm.MdiParent = this; aForm.Show(); } private void mi_File_CloseForm2_Click(object sender, EventArgs e) { aForm.Close(); aForm = null; } private void mi_Win_NewForm_Click(object sender, EventArgs e) { Form aForm = new Form(); aForm.MdiParent = this; aForm.Width = 450; aForm.Text = string.Format("新窗口 {0}",this.MdiChildren.Count()); aForm.Show(); } private void mi_Win_CloseForm_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) this.ActiveMdiChild.Close();//关闭当前活动的窗口 } private void mi_Win_DropDownOpened(object sender, EventArgs e) { mi_Win_CloseForm.Enabled = (this.ActiveMdiChild != null); } private void mi_Win_Title_H_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.TileHorizontal);//窗口水平分割排列 } private void mi_Win_Title_V_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.TileVertical);//窗口垂直分割排列 } private void mi_Win_Cas_Click(object sender, EventArgs e) { this.LayoutMdi(MdiLayout.Cascade);//窗口层叠排列 } private void mi_Help_About_Click(object sender, EventArgs e) { (new AboutForm()).ShowDialog(); } } }2、日期控件DateTimePicker功能演示
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 Demo_DateTime { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton2_CheckedChanged(object sender, EventArgs e) { this.dateTimePicker1.Format = DateTimePickerFormat.Long; } private void radioButton1_CheckedChanged(object sender, EventArgs e) { this.dateTimePicker1.Format = DateTimePickerFormat.Short; } private void radioButton3_CheckedChanged(object sender, EventArgs e) { this.dateTimePicker1.Format = DateTimePickerFormat.Time; } private void radioButton4_CheckedChanged(object sender, EventArgs e) { this.dateTimePicker1.Format = DateTimePickerFormat.Custom; this.dateTimePicker1.CustomFormat = textBox2.Text; } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = this.dateTimePicker1.Value.ToString(); //this.textBox1.Text = this.dateTimePicker1.Text; } } }3、月历控件MonthCalender功能演示
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 Demo_MonthCalendar { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) { textBox1.Text = monthCalendar1.TodayDate.ToString("yyyy-MM-dd");//返回月历的今天的日期 textBox2.Text = monthCalendar1.SelectionStart.ToString("yyyy-MM-dd"); textBox3.Text = monthCalendar1.SelectionEnd.ToString("yyyy-MM-dd"); } private void button1_Click(object sender, EventArgs e) { Close(); } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { monthCalendar1.MaxSelectionCount = Convert.ToInt16(numericUpDown1.Value); } } }4、树型列表控件TreeView功能演示
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 Demo_Tree { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { textBox1.Text = treeView1.SelectedNode.Text+"(级别:"+(treeView1.SelectedNode.Level+1).ToString()+")"; } private void button5_Click(object sender, EventArgs e) { treeView1.ExpandAll();//展开节点 } private void button6_Click(object sender, EventArgs e) { treeView1.CollapseAll();//收缩节点 } private void button1_Click(object sender, EventArgs e) { if (textBox2.Text != "") { TreeNode tn,tn1; if (treeView1.SelectedNode != null) { tn = treeView1.SelectedNode; tn1 = tn.Nodes.Add(textBox2.Text); } else { tn = treeView1.Nodes.Add(textBox2.Text); tn1 = tn; } tn.Expand();//展开tn节点 treeView1.SelectedNode = tn1;//把新增节点设置为当前选中的节点 } else { MessageBox.Show("项目名称不能为空!"); } } private void button4_Click(object sender, EventArgs e) { treeView1.Nodes.Clear(); } private void button3_Click(object sender, EventArgs e) { if (treeView1.SelectedNode != null) treeView1.Nodes.Remove(treeView1.SelectedNode); else MessageBox.Show("没有选中的项目!"); } private void Form1_Load(object sender, EventArgs e) { treeView1.ExpandAll();//展开所有节点 } } }5、数据库操作技术、ADO.NET技术讲解
详见:https://blog.csdn.net/xieyunc/article/details/90441902
6、演示DEMO源代码在github上的仓库地址:
https://github.com/xieyunc/csharp_teach.git