How Do I create a nice file selector form?
I am adding the ability for the user to select a file and attach it to an email that my program sends out. (see the other thread about recycling an email form for more on this)
My question is what controls can I use to create a nice GUI that lets the user select a file to attach? Does anyone hve any code they are willing to share that does this sort of thing?
Re: How Do I create a nice file selector form?
You could use the Windows Common Dialog for this:
http://www.news2news.com/vfp/images/getopenfilename.png
It's available as activex control in Visual Basic named "Microsoft Common Dialog Control" / comdlg32.ocx.
If you want to do it without activex controls, which I prefer, you can also use the GetOpenFileNameA API-call. A function wrapper for this call can be found at http://www.stefanthoolen.nl/basic/vb...ction=OpenFile
If you use that function, this code would be enough to let the user select a file:
Code:
Dim filename As String
filename = OpenFile(Me.hwnd, "MP3-files|*.mp3", "Select an MP3-file")
Re: How Do I create a nice file selector form?
Wow, I added the Windows Common Dialog control to a form and then ran my app in the VB IDE. When I got to the form where the common control was, nothing happened.
So I stopped the program and right clicked on the common control and went down to properties, I got an hourglass for a long time, then an UNknown hard error. After that I had no choice but reboot my computer.
I threw away the form containing the common control. it seemed too dangerous
Im running windows xp sp3 with 2gb of ram if your wondering
Re: How Do I create a nice file selector form?
Thats why I use API's instead of activex controls. I want to use as less dependencies as possible. Have you tried the module from the above URL?
Re: How Do I create a nice file selector form?
I downloaded it, but I have not tried it in my app yet
Re: How Do I create a nice file selector form?
I've used the common dialog control in projects beyond count since VB3 and I've never, ever had an issue with it.
Are you sure you used the Microsoft Common Dialog control found under Project/Components?
Re: How Do I create a nice file selector form?
A little bit offtopic perhaps, but to explain something;
I have had many problems with ocx-files myself. I tried betas of Visual Basic and they had their own revisions of ocx-files as well. I encountered loads of version conflicts due to this which made my applications fail on other computers then my own.
Currently I work on Windows Vista and if I add an ActiveX control it simply crashes if I'm not running VB with Administrator-rights.
Therefor I decided to avoid using ocx-files as much as possible. Also, using API's give better performance, although I doubt this is worth mentioning.
Re: How Do I create a nice file selector form?
That API function will work well for my needs, thank you. I just have one question. How do I call the function so that the filter is set to all files?
Re: How Do I create a nice file selector form?
You can enter multiple filters, for example
Filter = "All files|*.*" ' One option is available, to show all files
Filter = "Text files|*.txt;*.rtf|All files|*.*" ' Two options are available, one for textfiles and one for all files
You can add as many filters as you like.
Re: How Do I create a nice file selector form?
Quote:
Originally Posted by
vbguy2008
Wow, I added the Windows Common Dialog control to a form and then ran my app in the VB IDE. When I got to the form where the common control was, nothing happened.
So I stopped the program and right clicked on the common control and went down to properties, I got an hourglass for a long time, then an UNknown hard error. After that I had no choice but reboot my computer.
I threw away the form containing the common control. it seemed too dangerous
Im running windows xp sp3 with 2gb of ram if your wondering
I have been using the Windows Common Dialog Control since 1998.
I have used it on windows 2003 server and windows XP. No issues so far.