Remove "openfiledialog" from C#field

Asked

Viewed 63 times

4

Good,

I have an Openfiledialog in my program, but I didn’t want when I "open" to appear what is in the image... If I close the window, it is "openfiledialog" in Textbox, and I want it to be empty, since nothing was selected.

Imagery:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Code:

 private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.Filter = "Request File (*.CSR)|*.csr|Configuration File (*.CNF)|*.cnf";
        DialogResult resposta = openFileDialog1.ShowDialog();
        if (resposta == DialogResult.OK)
        {

            string arquivo = openFileDialog1.FileName;

            VariaveisGlobais.cnf = arquivo;
            VariaveisGlobais.csr = label2.Text;
        }

        textBox3.Text = string.Format("{0}", openFileDialog1.FileName);
        label2.Text = Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
        button2.Enabled = Path.GetExtension(openFileDialog1.FileName) == ".cnf";
        button3.Enabled = Path.GetExtension(openFileDialog1.FileName) == ".csr";
        button4.Enabled = Path.GetExtension(openFileDialog1.FileName) == ".csr";
    }

1 answer

5


In his instance of OpenFileDialog, before calling the method ShowDialog(), use of property FileName to name a proposed file:

openFileDialogInstance.FileName = "arquivo.txt";

If the name of this file is a little long, the cursor will be at the end of the file name, and can cut the name in the display.

If that happens, use the property ShowHelp to leave the file name selected:

openFileDialogInstace.ShowHelp = true;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.