例9.7
    image.pngimage.png

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Threading.Tasks;
    9. using System.Windows.Forms;
    10. namespace WindowsFormsApp4
    11. {
    12. public partial class Form2 : Form
    13. {
    14. public Form2()
    15. {
    16. InitializeComponent();
    17. }
    18. private int nCounter;
    19. private void Form2_Load(object sender, EventArgs e)
    20. {
    21. this.nCounter = 20;
    22. this.ShowCounter();
    23. }
    24. private void ShowCounter()
    25. {
    26. string strMsg = this.nCounter.ToString("D8");
    27. this.label1.Text = strMsg;
    28. }
    29. private void button1_Click(object sender, EventArgs e)
    30. {
    31. this.nCounter++;
    32. this.ShowCounter();
    33. }
    34. private void button2_Click(object sender, EventArgs e)
    35. {
    36. this.nCounter--;
    37. this.ShowCounter();
    38. }
    39. private void button3_Click(object sender, EventArgs e)
    40. {
    41. string strMsg = "当前计数器=" + this.nCounter.ToString("D8");
    42. MessageBox.Show(strMsg, "提示");
    43. }
    44. }
    45. }

    例9.9
    image.pngimage.png
    image.png

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Threading.Tasks;
    9. using System.Windows.Forms;
    10. namespace WindowsFormsApp4
    11. {
    12. public partial class Form1 : Form
    13. {
    14. public Form1()
    15. {
    16. InitializeComponent();
    17. }
    18. private void button1_Click(object sender, EventArgs e)
    19. {
    20. this.textBox1.Text = this.label1.Text;
    21. }
    22. }
    23. }