复制文本框数组到剪贴板?

时间:2019-02-09 20:59:07

标签: c# arrays object clipboard

我正在尝试制作一个简单的程序,一个按钮生成彩票号码,第二个按钮将所有号码复制到剪贴板。但是,无论我用谷歌搜索多少,它都不会将任何内容复制到剪贴板,只是崩溃了,我却失去了可悲的代码。任何帮助都会很可爱,我是初学者:)

using System;
using System.Windows.Forms;

namespace Lottery_Number_Generator
{
    public partial class Form1 : Form
    {

        private TextBox[] allBoxes;

        private int[] randomArray = new int[7];

        int Min = 1;
        int Max = 60;

        Random rand = new Random();

        public Form1()
        {

        InitializeComponent();

        allBoxes = new TextBox[] { // Creating an array of Textboxes
        boxNum1, boxNum2, boxNum3, boxNum4, boxNum5, boxNum6, boxNum7 };



        }

        private void Form1_Load(object sender, EventArgs e)
        {
            genBtn.Focus();
        }

        private void genBtn_Click(object sender, EventArgs e)
        {
            foreach (TextBox box in allBoxes)
            {
                box.Text = rand.Next(Min, Max).ToString();
            }

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void copyBtn_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(allBoxes.ToString());
            string boxes = allBoxes[6].ToString();

        }

        private void CopyBtn_Click_1(object sender, EventArgs e)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:0)

使用此:

RelativeLayout

,并将其添加到.cs文件的开头:

Clipboard.SetText(String.Join("",allBoxes.Select(t=>t.Text)))