本文介绍了如何在运行时在C#.NET windows应用程序中将folderbrowserdialog值存储在文本框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我想为创建控件和功能创建运行时应用程序,控件创建成功但值不存储在文件框中根据文件夹对话框。 />


请帮帮我。

怎么解决这个问题?



谢谢

Ankit Agarwal

软件工程师



我尝试过:



Hello,

I want to create application for runtime for create controls and functionality, controls created successfully but value not storing in text box according folder dialog.

Please help me.
How can be resolve that?

Thanks
Ankit Agarwal
Software Engineer

What I have tried:

private void btnBrowse_Click(object sender, EventArgs e)
        {
            //LoadControls();
            ChooseFolder();
        }

        public void ChooseFolder()
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {

                TextBox textbox = new TextBox();
                textbox.Text = folderBrowserDialog1.SelectedPath;
                MessageBox.Show(textbox.Text);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            int count = panel1.Controls.OfType<Label>().ToList().Count;
            TextBox textbox = new TextBox();
            count = panel1.Controls.OfType<TextBox>().ToList().Count;
            textbox.Location = new Point(3, 25 * count);
            textbox.Size = new Size(188, 20);
            textbox.Name = "textbox_" + (count + 1);
            textbox.TextChanged += new System.EventHandler(this.TextBox_Changed);
            panel1.Controls.Add(textbox);

            Button button = new Button();
            //count = panel1.Controls.OfType<Button>().ToList().Count;
            button.Location = new Point(207, 25 * count);
            button.Size = new Size(75, 23);
            button.Name = "button_" + (count + 1);
            button.Text = "Browse " + (count + 1);
            button.Click += new System.EventHandler(this.btnBrowse_Click);
            panel1.Controls.Add(button);
        }

推荐答案

string TextBoxValue = "";
public void ChooseFolder()
{
    FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        TextBoxValue = folderBrowserDialog1.SelectedPath;   // Storing the value in a temporary string.
}

然后按照以下代码中的说明添加该行。

Then add the line as indicated in the code below.

private void btnAdd_Click(object sender, EventArgs e)
{
    int count = panel1.Controls.OfType<Label>().ToList().Count;
    TextBox textbox = new TextBox();
    count = panel1.Controls.OfType<TextBox>().ToList().Count;
    textbox.Location = new Point(3, 25 * count);
    textbox.Size = new Size(188, 20);
    textbox.Name = "textbox_" + (count + 1);
    textbox.Text = TextBoxValue;    // This line was added.
    textbox.TextChanged += new System.EventHandler(this.TextBox_Changed);
    ...............................
    ...............................

我希望能解决这个问题。

I hope that will solve the problem.


这篇关于如何在运行时在C#.NET windows应用程序中将folderbrowserdialog值存储在文本框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:57