Results 1 to 8 of 8

Thread: [2.0] getting a comboBox to Open MyPictures

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question [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:
    1. private void pComboBox(object sender, System.EventArgs e)
    2.         {
    3.             using (openFileDialog1)
    4.             dlg.Filter = "MyPictures(*.jpg)" + "|*.png|All Files (*.*)|*.*";
    5.             dlg.InitialDirectory = MyPictures;
    6.  
    7.             try
    8.             {
    9.                 if (dlg.ShowDialog()
    10.                     == DialogResult.OK)
    11.                 {
    12.                 _MyPictures.Open(dlg.FileName);
    13.                 }
    14.             }
    15.           catch (Exception)
    16.             {
    17.               MessageBox.Show("Unable to open "
    18.             + "album\n" + dlg.FileName,
    19.           "Open Album Error",
    20.           MessageBoxButtons.OK,
    21.           MessageBoxIcon.Error);
    22.       }
    23.     }

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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);
    	}
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question 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:
    1. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    2.         {
    3.             Environment.SpecialFolder MyPictures = new Environment.SpecialFolder(); //Also added this
    4.             OpenFileDialog dlg = new OpenFileDialog();
    5.             dlg.Filter = "MyPictures(*.jpg)" + "|*.png|All Files (*.*)|*.*";
    6.             dlg.InitialDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures);
    7.             try
    8.             {
    9.                 if (dlg.ShowDialog() == DialogResult.OK)
    10.                 {
    11.                     MyPictures.ToString(dlg.FileName);//Edited _MyPictures.Open
    12.                 }
    13.             }
    14.             catch (Exception)
    15.             {
    16.                 MessageBox.Show("Unable to open "
    17.                     + "album\n" + dlg.FileName,
    18.                     "Open Album Error",
    19.                     MessageBoxButtons.OK,
    20.                     MessageBoxIcon.Error);
    21.             }
    22.         }

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question 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...
    Last edited by Rattlerr; Jun 24th, 2006 at 01:06 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question 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..

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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);
            }
        }
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width