45-10000 Windows窗体应用 点击自增+1

 

 

 

 

  点击没有连带变化,点击按钮发生自增的功能。这个只是点击,label跟随变化了。

 

   

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 Demo4
{
    public partial class Form1 : Form
    {
        // 1 外部声明一个成员变量:
        int count = 0;

        int count1 = 0;
        

        public Form1()
        {
            InitializeComponent();
        }

        //单击
        private void label1_Click(object sender, EventArgs e)
        {
            count++; // 自增
       

            label1.Text ="单击了"+ count +"";
            //单词名字label1都得一模一样!否则(只用label,少了数字1都不行)后面的Text报错的! 


        }

        private void button_Click(object sender, EventArgs e)
        {
            count1++; // 自增


            label1.Text = "单击了" + count1 + "";
            //单词名字label1都得一模一样!否则(只用label,少了数字1都不行)后面的Text报错的! 


        }
    }
}

 

效果:

 

posted @ 2021-11-25 13:37  优敏行  阅读(57)  评论(0)    收藏  举报