日期:2014-05-18  浏览次数:20707 次

c#按钮如何实现按一次,数值减少一点
c#窗体有一个按钮,代码中有一个整型数值int ss=10;如何实现每按一次按钮使得ss减少1。(第1次按ss=9,第2次按ss=8,...)

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int a = 10;
private void button1_Click(object sender, EventArgs e)
{
a--;
MessageBox.Show(a.ToString());
}
}
}
------解决方案--------------------

用一个成员变量ss:
private int ss=10;

按钮Click事件方法写:
ss--;



------解决方案--------------------
一楼对着
------解决方案--------------------
C# code
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private int ss = 10;//
        private void button1_Click(object sender, EventArgs e)
        {
            ss--;
            MessageBox.Show(ss.ToString());
        }
    }
}