每次单击都会为多个事件创建一个按钮

时间:2017-11-05 04:18:20

标签: c# winforms visual-studio-2015

我想要一个名为forward的按钮,它可以帮助程序将字符串OLabel1转移到Label2Label2转换为Label3在下一次点击等等。

enter image description here

1 个答案:

答案 0 :(得分:0)

以下是转发按钮的示例代码,您可以自己做后退。希望这可以帮到你。

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        enum stringLocation : int
        {
            label1,label2, label3, label4
        }
        int location =(int) stringLocation.label1;
        string contentToMove= "0";
        public Form1()
        {
            InitializeComponent();
        }

        private void forward_Click(object sender, EventArgs e)
        {
            location = (location+1) % 4;
            switch (location){
            case (int) stringLocation.label1:
                    label1.Text = contentToMove;
                    label2.Text = "";
                    label3.Text = "";
                    label4.Text = "";
                    break;
            case (int) stringLocation.label2:
                    label1.Text = "";
                    label2.Text = contentToMove;
                    label3.Text = "";
                    label4.Text = "";
                    break;
            case (int) stringLocation.label3:
                    label1.Text =  "";
                    label2.Text = "";
                    label3.Text = contentToMove;
                    label4.Text = "";
                    break;
            case (int)stringLocation.label4:
                    label1.Text = "";
                    label2.Text = "";
                    label3.Text = "";
                    label4.Text = contentToMove; 
                    break;
            default:
                break;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = contentToMove;
            label2.Text = "";
            label3.Text = "";
            label4.Text = "";
        }
    }
}