Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write a tiny program with Windows form (instead of maybe WPF) but the file picker control is not showing up on the form.

What I have tried:

I tried using the TextBox and it appeared, but the file picker instead docks in this smaller tab below the designer.
I went to the Form1.Designer.cs code, in the IntializeComponent method, and added
this.openFileDialog1.ShowDialog();
This causes the file picker to trigger immediately the form loads (as it's initializing, before any control is even loaded), then when I close it, I can only find the TextBox on the form but no file picker.


I also tried wrapping contents in a container control but it didn't help either.

[Images of what the designer is giving me^]
Posted
Updated 19-May-18 8:58am
v2

Open File components don't display at all - that's why they do not appear on the form in the designer, but underneath it.

What you need to is decide when the dialog should be displayed, and write code to display it at that point. For example, you might want an "Open" button:
C#
private void OpenFile_Click(object sender, EventArgs e)
   {
   OpenFileDialog ofd = new OpenFileDialog();
   ...
   if (ofd.ShowDialog() = DialogResult.OK)
      {
      ...
      }
   }
 
Share this answer
 
See example here: How to: Open Files Using the OpenFileDialog Component | Microsoft Docs[^]
And please do not change Form1.Designer.cs if it is not absolutely necessary !
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900