Results 1 to 14 of 14

Thread: [2005] Saving a background Image

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Resolved [2005] Saving a background Image

    Hey, quick question if someone could answer.

    I have 2 forms.
    The user selects an Image in form 1, and that image becomes the background for form 1.

    When the user click 'save' (button) I want when the form is closed and then re-opened it will automatically load that image to form 1.

    I also need to have the background image of form 1 to become the background image of Form 2.

    Basically Form 1 is used to change the appearance of form 2.


    I have been able to do this for the Forecolour, Font, and Backcolor.
    So far i have used the Property Bindings for this. But i can't find an option in there to do this.

    Hope that makes sense
    Thanks
    Last edited by Wulfgur; Jun 19th, 2007 at 11:42 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] Saving a background Image

    write it to the registry.
    then retrieve it when you start your program + save it (filepath) to a variable
    then you can set backgroundimage = variable

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

    Re: [2005] Saving a background Image

    Use application settings rather than the registry. Lookup My.Settings on MSDN for moro information.
    Last edited by jmcilhinney; Jun 4th, 2007 at 12:54 AM.
    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

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    k thanks, i'll post if i need more help.

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    Ok, still stuck with the Saving Background Image.
    I have used Application Settings --> Property Bindings, for saving the back color, fore color, font ect. But i cannot find a setting in Property Bindings for Background Image, i see BackgroundImage style.

    I have had a search in MSDN, maybe i missed it there.
    I must be missing something.

    Thanks.

  6. #6
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: [2005] Saving a background Image

    Save the path to the image in My.Settings and then set the Background image of the form when it loads.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    Sorry i still don't understand. "Save the path to the image in my.settings" What "Type" am i meant to use?

    Sorry i just don't understand what you are saying.

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

    Re: [2005] Saving a background Image

    How would you normally specify a file path? With a String, so you need to create a setting of type String to store the path of the image file. You can then load it like so:
    vb.net Code:
    1. Me.BackgroundImage = Image.FromFile(My.Settings.FormBackgroundImagePath)
    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

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] Saving a background Image

    a directory + a filename is a string (of characters)

    i.e.

    dim filename as string = "c:\windows\paint.exe"

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    Ok. This is what i am looking for. I want a user to select an image, that image becomes the backgroundimage of the form, when the user clicks a button named "Save" the image will be saved so next time the user opens the form the backgroundimage will still be set to what he saved it to last time.

    jmcilhinney does the method you stated above do this?

    vb Code:
    1. Private Sub BtnImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnImage.Click
    2.         OpenFileDialog1.ShowDialog()
    3.         If OpenFileDialog1.FileNames.Length > 0 Then
    4.             Dim Img As New Bitmap(OpenFileDialog1.FileName.ToString())
    5.             Me.BackgroundImage = Img
    6.             Me.Refresh()
    7. End If
    (When BtnImage is clicked it prompts the user to select an image which when selected becomes the background of the form)
    This is what i have done for the selecting an image for the background i just don't know how to save it.

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

    Re: [2005] Saving a background Image

    All your code does is select an image and set it as the form's background. It doesn't do any saving for next time or loading at startup. Have you created a setting to store the file's path as we have already suggested?
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    Yea thats what i needed help with saving for the next load up.
    I have created a setting in Project Settings named: Image

    Really sorry for not understanding, just never done this before.

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

    Re: [2005] Saving a background Image

    circuits2 has already told you what to do:
    Save the path to the image in My.Settings
    I have shown you how to use that path to load the image next time you start the app.
    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

  14. #14

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving a background Image

    Ok thanks for the help

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