例9.7

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 WindowsFormsApp4{public partial class Form2 : Form{public Form2(){InitializeComponent();}private int nCounter;private void Form2_Load(object sender, EventArgs e){this.nCounter = 20;this.ShowCounter();}private void ShowCounter(){string strMsg = this.nCounter.ToString("D8");this.label1.Text = strMsg;}private void button1_Click(object sender, EventArgs e){this.nCounter++;this.ShowCounter();}private void button2_Click(object sender, EventArgs e){this.nCounter--;this.ShowCounter();}private void button3_Click(object sender, EventArgs e){string strMsg = "当前计数器=" + this.nCounter.ToString("D8");MessageBox.Show(strMsg, "提示");}}}
例9.9


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 WindowsFormsApp4{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){this.textBox1.Text = this.label1.Text;}}}
