从一个字符串函数获得多个返回

时间:2018-12-15 00:48:29

标签: c# winforms

基于/ users / 668272 / bas对话框。我尝试编写更多内容以获取多个值

public static class ControlInfo
        {
            public static TextBox[] TextData { get; set; }
        }

        public static class Prompt
        {
            public static Form prompt = new Form();
            public static void ShowDialog(string Text, string caption)
            {
                //string[] inputval = new string[6];
                prompt = new Form()
                {
                    Width = 500,
                    Height = 650,
                    FormBorderStyle = FormBorderStyle.FixedDialog,
                    Text = caption,
                    StartPosition = FormStartPosition.CenterScreen
                };
                #region:create
                Label textLabel = new Label() { Left = 20, Top = 20, Text = Text };
                TextBox textBox1 = new TextBox() { Left = 50, Top = 100, Width = 400 };
                Button confirmationok = new Button()
                { Text = "Save", Left = 250, Width = 100, Top = 550, DialogResult = DialogResult.OK };
                Button confirmationcancel = new Button()
                { Text = "Cancel", Left = 350, Width = 100, Top = 550, DialogResult = DialogResult.Cancel };
                confirmationok.Click += (sender, e) => { Save(); };
                confirmationcancel.Click += (sender, e) => { prompt.Close(); };

                prompt.Controls.Add(confirmationcancel);
                prompt.Controls.Add(textBox1);
                prompt.Controls.Add(textBox2);
                prompt.Controls.Add(textBox3);
                prompt.Controls.Add(textBox4);
                prompt.Controls.Add(textBox5);
                prompt.Controls.Add(textBox6);
                prompt.Controls.Add(confirmationok);
                prompt.Controls.Add(textLabel);
                prompt.Controls.Add(textLabel1);
                prompt.Controls.Add(textLabel2);
                prompt.Controls.Add(textLabel3);
                prompt.Controls.Add(textLabel4);
                prompt.Controls.Add(textLabel5);
                prompt.Controls.Add(textLabel6);
                prompt.AcceptButton = confirmationok;
                prompt.AcceptButton = confirmationcancel;
                prompt.ShowDialog();
            }

            public static void Save()
            {
                var cArray = prompt.Controls.OfType<TextBox>().ToArray();
                ControlInfo.TextData = cArray;
            }
        }

[更新]我尝试使用string []获取值,但是这种情况一直在发生:return inputval;'索引超出了数组的界限。'那么如何正确将值返回到string []数组?

[更新2]通过创建TextData []来存储值,然后像这样ControlInfo.TextData[0].Text

对其进行调用,解决了该问题

1 个答案:

答案 0 :(得分:-1)

我使用Textdata类通过SAVE按钮存储对话框中的值。完整的代码在问题中