[2.0] getting a comboBox to Open MyPictures
Error1 The name 'MyPictures' does not exist in the current context
But in the OpenFileDialog InitialDirectory for the Properties box "MyPictures" is in their....
VB Code:
private void pComboBox(object sender, System.EventArgs e)
{
using (openFileDialog1)
dlg.Filter = "MyPictures(*.jpg)" + "|*.png|All Files (*.*)|*.*";
dlg.InitialDirectory = MyPictures;
try
{
if (dlg.ShowDialog()
== DialogResult.OK)
{
_MyPictures.Open(dlg.FileName);
}
}
catch (Exception)
{
MessageBox.Show("Unable to open "
+ "album\n" + dlg.FileName,
"Open Album Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
Re: [2.0] getting a comboBox to Open MyPictures
Code:
private void pComboBox(object sender, System.EventArgs e)
{
OpenFileDialog dlg=new OpenFileDialog();
dlg.Filter = "MyPictures(*.jpg)" + "|*.png|All Files (*.*)|*.*";
dlg.InitialDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
try
{
if (dlg.ShowDialog()== DialogResult.OK)
{
_MyPictures.Open(dlg.FileName);
}
}
catch (Exception)
{
MessageBox.Show("Unable to open "
+ "album\n" + dlg.FileName,
"Open Album Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
Re: [2.0] getting a comboBox to Open MyPictures
I edited apart of the code because it produced an Error so this is what i have changed it too...Overall out come thou,Dosnt Open the MyPictures Folder,it actually Does nothing at all..Even during Debug the ComboBox shows Nothing & No Errors appear..
VB Code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Environment.SpecialFolder MyPictures = new Environment.SpecialFolder(); //Also added this
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "MyPictures(*.jpg)" + "|*.png|All Files (*.*)|*.*";
dlg.InitialDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
try
{
if (dlg.ShowDialog() == DialogResult.OK)
{
MyPictures.ToString(dlg.FileName);//Edited _MyPictures.Open
}
}
catch (Exception)
{
MessageBox.Show("Unable to open "
+ "album\n" + dlg.FileName,
"Open Album Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
Re: [2.0] getting a comboBox to Open MyPictures
What are you trying to do here?
Code:
Environment.SpecialFolder MyPictures = new Environment.SpecialFolder(); //Also added this
You don't create instances of the SpecialFolder type. It is an enumeration so each member is a constant. The only thing you use the Environment.SpecialFolders enumeration for is to pass constants to the Environment.GetFolderpath method. That's the only place it should ever be seen, as CJ has done in his code. CJ's code fixes the issues in your original code as far as setting the initial folder for the dialogue. If there are other issues then that's something else. In words, what exactly are you trying to achieve?
Re: [2.0] getting a comboBox to Open MyPictures
When you use the ComboBox it will open the My Pictures Folder so you can select an image out of it...The project is a CSS Generator...
Re: [2.0] getting a comboBox to Open MyPictures
So whenever the user makes a selection from a ComboBox, regardless of what that selection is, you want to open an OpenFileDialog so they can select an image file, correct? And what exactly do you want to do with that image file once it's been selected?
Re: [2.0] getting a comboBox to Open MyPictures
to be added to a CSS Body
Body {
background-color:Transparent;
background:..\..\Imagename.jpg
}
Get to autofill in the background code for the css file..
Re: [2.0] getting a comboBox to Open MyPictures
So basically you don't want to open the image file. You just want to use the path that the user selects in the OpenFileDialog. CJ has already shown you how to set the InitialDirectory to MyPictures but you have for some reason decidied to change his code. Once the user has clicked the OK button you would simply take the string returned by the FileName property and insert it into your CSS string.
Code:
const string JPEG_FILTER = "*.jpeg;*.jpg;*.jpe;*.jfif";
const string GIF_FILTER = "*.gif";
const string PNG_FILTER = "*.png";
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Select Image";
ofd.Filter = string.Format("JPEG ({0})|{0}|GIF ({1})|{1}|PNG ({2})|{2}|All Image Files|{0},{1},{2}|All Files|*.*",
JPEG_FILTER,
GIF_FILTER,
PNG_FILTER);
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (ofd.ShowDialog() == DialogResult.OK)
{
// Use the selected path here.
MessageBox.Show("You selected the file " + ofd.FileName);
}
}
}