cjk

Ok, I figured out how to change my background image that i wanted from a button, but now i need to know how to save the background I chose so the next time i run the program the same background i chose will be there.


Re: Visual Basic Express Edition saving background image

ahmedilyas

you are talking about application settings.

you need to create a key for the background image setting and the value for it, then read that value next time your app loads and apply the background to your application.

Take a look at this:

http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/bc6ws923(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/ms171565(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/wabtadw6(VS.80).aspx

I hope these links help - gives you everything you want :-)






Re: Visual Basic Express Edition saving background image

Keo1

Hi cjk,

Do you mean saving a setting to a file that automatically loads the background the next time Or just how to change the general background of the program

If you mean saving it as a setting to a file.. then you could use .xml or .ini files.. or the user config option.






Re: Visual Basic Express Edition saving background image

ahmedilyas

there is no need to use the ini files at all. These are outdated and xml is really a replacement for it. in addition, why re-invent the wheel if .NET provides such functionality and at an ease :-)

The application settings is the way to do it - correctly.






Re: Visual Basic Express Edition saving background image

Keo1

Makes perfect sense, it would be going out of the way and re-inventing the wheel to use something that be done though .NET

I appreciate the clarification. Ill make note of it for later use. Smile




Re: Visual Basic Express Edition saving background image

ahmedilyas

no worries Keo - glad I could help in some way, just to steer you in the right direction and to make life that bit easier my friend :-)






Re: Visual Basic Express Edition saving background image

cjk

Thanks everyone...but it didnt seem to help.

I figured out how to use application settings to save and load a single color, and this is the code for that-

MyBase.BackColor = Color.Green

My.Settings.SavedColor = Color.Green

this works perfectly, but then when i try to do it with a background image, I use this-

Form1.BackgroundImage = My.Resources.bg

My.Settings.SavedBG = My.Resources.bg

and the My.Resources.bg in the second line has an error that reads-

Value of Type "System.Drawing.Bitmap" cannot be converted to 'String'.

my application setting I made for the backgrounds is SavedBG






Re: Visual Basic Express Edition saving background image

Keo1

Hi cjk,

I tried the code you provided and got it to work by changing

" My.Settings.SavedBG = My.Resources.bg "

to

"
My.Settings.SavedBG = My.Resources.bg.ToString "





Re: Visual Basic Express Edition saving background image

cjk

Thanks! You rock

also how do i turn off the loader lock






Re: Visual Basic Express Edition saving background image

ahmedilyas

sure, because the My.Settings.SavedBG is a string property. - the My.Resources.bg is another type.

What you should be doing is saving the string type of what "bg" is, such as the name of the background or whatever.

How are you loading the image from the resources






Re: Visual Basic Express Edition saving background image

cjk

to load i just used

Form1.BackgroundImage = My.Resources.b_bg

b_bg is my resource

also, the ToString didnt work...I have no idea why but it didnt






Re: Visual Basic Express Edition saving background image

Keo1

Make sure under your application settings, that the resource Type is also set to " String " .




Re: Visual Basic Express Edition saving background image

cjk

yes its set to string too...

maybe I dont have the right code that is saving the image in my SavedBG setting... do you know what that would be






Re: Visual Basic Express Edition saving background image

Keo1

Heres the code i used.. i loaded the background in Form1 on load.

( I imported the exact background file named "tile1" and named my resource under application settings as "savedbg" type set to String )


Me.BackgroundImage = My.Resources.tile1
My.Settings.savedbg = My.Resources.tile1.ToString




Re: Visual Basic Express Edition saving background image

ahmedilyas

I knew that wouldnt work ;-)

the reason is because you are getting back the type of the object as a string - not the actual object itself.