|
I searched PictureDialog, ImageDialog, I can't find such a dialog. I want something like the one used when you want to choose the Image for a PictureBox (the preview is quite important) | | Virgil Rucsandescu Wednesday, October 25, 2006 3:59 PM | ok you have 2 choices.
you can either use the FileOpenDialog, set a filter on the supported Image file types so the user can only select those files, and set the multiselect property to true so the user can select multiple files, then when clicked on ok, get the list of files chosen, populate them in a listbox then on an item selected, load the image into the preview image picturebox.
other one is to do the same as above but use a folderopendialog to select the folder containing images, so when clicked on ok, your app will get the files of images, populate them into the listbox and do the same as above.
choice is yours! The problem here would be that you would need to resize the image loaded to fit the picturebox otherwise it would only get the top left hand corner of the image I believe, so you may wish to find a way of resizing it then displaying the image.
I would go for the first option because there appears not to be a way of scanning a directory to get a list of multiple image file types, you would have to scan for each file type which can effect performance on your application.
Either way, you can do this:
Create a form
drag 3 buttons on the form. Button1 will be a Select button (disable this initially), Button2 will be a Browse button, Button3 will be a Cancel button.
drag a listbox on the form
drag a PictureBox on the form
drag a label on the form - this will have our path selected
Make the form startup in the center screen of the form startupposition
double click the Cancel button and we will be closing the form and giving a DialogResult of Cancel:
VB.NET:
| |
Me.DialogResult = DialogResult.Cancel Me.Close()
|
C#
| |
this.DialogResult = DialogResult.Cancel; this.Close();
|
double click the Select button and we will be closing the form and giving a DialogResult of OK.
VB.NET
| |
Me.DialogResult = DialogResult.OK Me.Close()
|
C#
| |
this.DialogResult = DialogResult.OK; this.Close();
|
Double click the Browse button. This here will show our OpenFileDialog where we will select multiple images
VB.NET
| |
Dim theOFD as new OpenFileDialog() theOFD.Filter = "Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png" 'specify our filter theOFD.Multiselect = true 'allow them to select multiple files if theOFD.ShowDialog = DialogResult.OK then Me.lstFiles.Items.Clear() for each currentFile as String in theOFD.FileNames Me.lstFiles.Items.Add(System.IO.Path.GetFileName(currentFile)) 'we just want the filename, not the full path and filename next end if
|
C#
| |
OpenFileDialog theOFD = new OpenFileDialog(); theOFD.Filter = "Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png"; //specify our filter theOFD.Multiselect = true; //allow them to select multiple files if (theOFD.ShowDialog == DialogResult.OK) { this.lstFiles.Items.Clear(); foreach(string currentFile in theOFD.FileNames) { this.lstFiles.Items.Add(System.IO.Path.GetFileName(currentFile)) //we just want the filename, not the full path and filename } }
|
this will filter our open file dialog to show the file extentions we want for the user to see and select, allow them to select multiple files and finally once chosen, for each item they chose, add it into the listbox
double click the listbox (lstFiles in this example)
this will create a selectedindexchanged event which fires when we change the selection of an item, so when they select an item, to load it into the picturebox.
VB.NET
| |
if Me.lstFiles.SelectedIndex > -1 then Me.cmdSelect.Enabled = true Me.thePictureBox.Image = Image.FromFile(Me.lstFiles.Text) end if if Me.lstFiles.SelectedIndex = -1 Or Me.lstFiles.Items.Count = 0 then Me.cmdSelect.Enabled = false end if
|
C#
| |
if (this.lstFiles.SelectedIndex > -1) { this.cmdSelect.Enabled = true; this.thePictureBox.Image = Image.FromFile(this.lstFiles.Text); } if (this.lstFiles.SelectedIndex == -1 || this.lstFiles.Items.Count == 0) { this.cmdSelect.Enabled = false; }
|
and I think thats pretty much it.
Does this help? | | ahmedilyas Wednesday, October 25, 2006 5:48 PM | I don't think there is one, in which case either find one using a search engine or create your own - could I ask exactly what you are after? Are you after like a picture preview dialog where a dialog shows up, you can select the image you want and view that image in the "image preview"? | | ahmedilyas Wednesday, October 25, 2006 4:06 PM | yes, like a OpneFileDialog filtered only for images, but with a small preview area when I click the image.
| | Virgil Rucsandescu Wednesday, October 25, 2006 4:22 PM | you can create your own, which is currently what I am doing for you for fun. Basically you create a form, add a PictureBox control, then maybe a treeview or something to select the path/folders located with image files, then you can select the image you want and once selected, it will show a preview of that image in the image preview picturebox control.
To load an image into this preview picturebox:
this.thePictureBox.Image= Image.FromFile("path\filename.jpg");
this will then load the image specified/selected from the file given into the picturebox. | | ahmedilyas Wednesday, October 25, 2006 4:26 PM | don't bother ahmedilyas, this is not so important. Thank you very much for all the support !! | | Virgil Rucsandescu Wednesday, October 25, 2006 4:43 PM | not at all! I love doing this, itll take a while but it will be good to share it to all :-) | | ahmedilyas Wednesday, October 25, 2006 4:48 PM | ok you have 2 choices.
you can either use the FileOpenDialog, set a filter on the supported Image file types so the user can only select those files, and set the multiselect property to true so the user can select multiple files, then when clicked on ok, get the list of files chosen, populate them in a listbox then on an item selected, load the image into the preview image picturebox.
other one is to do the same as above but use a folderopendialog to select the folder containing images, so when clicked on ok, your app will get the files of images, populate them into the listbox and do the same as above.
choice is yours! The problem here would be that you would need to resize the image loaded to fit the picturebox otherwise it would only get the top left hand corner of the image I believe, so you may wish to find a way of resizing it then displaying the image.
I would go for the first option because there appears not to be a way of scanning a directory to get a list of multiple image file types, you would have to scan for each file type which can effect performance on your application.
Either way, you can do this:
Create a form
drag 3 buttons on the form. Button1 will be a Select button (disable this initially), Button2 will be a Browse button, Button3 will be a Cancel button.
drag a listbox on the form
drag a PictureBox on the form
drag a label on the form - this will have our path selected
Make the form startup in the center screen of the form startupposition
double click the Cancel button and we will be closing the form and giving a DialogResult of Cancel:
VB.NET:
| |
Me.DialogResult = DialogResult.Cancel Me.Close()
|
C#
| |
this.DialogResult = DialogResult.Cancel; this.Close();
|
double click the Select button and we will be closing the form and giving a DialogResult of OK.
VB.NET
| |
Me.DialogResult = DialogResult.OK Me.Close()
|
C#
| |
this.DialogResult = DialogResult.OK; this.Close();
|
Double click the Browse button. This here will show our OpenFileDialog where we will select multiple images
VB.NET
| |
Dim theOFD as new OpenFileDialog() theOFD.Filter = "Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png" 'specify our filter theOFD.Multiselect = true 'allow them to select multiple files if theOFD.ShowDialog = DialogResult.OK then Me.lstFiles.Items.Clear() for each currentFile as String in theOFD.FileNames Me.lstFiles.Items.Add(System.IO.Path.GetFileName(currentFile)) 'we just want the filename, not the full path and filename next end if
|
C#
| |
OpenFileDialog theOFD = new OpenFileDialog(); theOFD.Filter = "Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png"; //specify our filter theOFD.Multiselect = true; //allow them to select multiple files if (theOFD.ShowDialog == DialogResult.OK) { this.lstFiles.Items.Clear(); foreach(string currentFile in theOFD.FileNames) { this.lstFiles.Items.Add(System.IO.Path.GetFileName(currentFile)) //we just want the filename, not the full path and filename } }
|
this will filter our open file dialog to show the file extentions we want for the user to see and select, allow them to select multiple files and finally once chosen, for each item they chose, add it into the listbox
double click the listbox (lstFiles in this example)
this will create a selectedindexchanged event which fires when we change the selection of an item, so when they select an item, to load it into the picturebox.
VB.NET
| |
if Me.lstFiles.SelectedIndex > -1 then Me.cmdSelect.Enabled = true Me.thePictureBox.Image = Image.FromFile(Me.lstFiles.Text) end if if Me.lstFiles.SelectedIndex = -1 Or Me.lstFiles.Items.Count = 0 then Me.cmdSelect.Enabled = false end if
|
C#
| |
if (this.lstFiles.SelectedIndex > -1) { this.cmdSelect.Enabled = true; this.thePictureBox.Image = Image.FromFile(this.lstFiles.Text); } if (this.lstFiles.SelectedIndex == -1 || this.lstFiles.Items.Count == 0) { this.cmdSelect.Enabled = false; }
|
and I think thats pretty much it.
Does this help? | | ahmedilyas Wednesday, October 25, 2006 5:48 PM | Did you ever create the dialog that you mentioned? I've been looking on the web for image file open dialogs for .NET and have not found one, except at fairly high prices. I was frankly kind of shocked to see that this is not provided in Visual Studio. Delphi has had this dialog for years. Michael Bate
| | MichaelBate Thursday, October 01, 2009 4:05 PM |
|