|
I'm new to programming and VB so just for fun I'm trying to build a music player app. I want to have it set up so you can choose your own background from picture files on your computer. The code I'm using to save the registry file is:
Private Sub MusicPlayerForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Computer.Registry.SetValue _
(m_strKeyName, "BackgroundImage", Me.BackgroundImage)
End Sub
The file is saved and I can see it when I use the regedit. The problem I'm having is loading the file. Currently I have:
Private Sub MusicPlayerForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Start()
LoadDefault()
Me.BackgroundImage = m_objBackgroundImage
End Sub
Public Sub LoadDefault()
If CStr(My.Computer.Registry.GetValue(m_strKeyName, "BackgroundImage", _
Me.BackgroundImage)) = "" Then
Exit Sub
Else
m_objBackgroundImage = Image.FromFile(My.Computer.Registry.GetValue _
(m_strKeyName, "BackgroundImage", Me.BackgroundImage))
End If
End Sub
The error message I get is 'System.IO.FileNotFound Exception'. I know it's probably something simple that I overlooked, but can anyone help me?
THANKS!!!
|
|
|
|
|
Garrett Crawford wrote: System.IO.FileNotFound Exception
That should give you a clue; you are trying to load a file and either the path is mis-spelled or the file itself has been moved or deleted. Check the value of the registry key to ensure it is correct.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
You really shouldn't be saving an image to the registry. The registry is bloated enough without doing something like this.
But, what you've have to do is convert the image to a byte array. Create a MemoryStream object, then save the image to the MemoryStream. Create a byte array the length of the memorystream, then read the memory stream into the array. There's an example here[^].
Loading the image from the registry is the reverse of this.
|
|
|
|
|
Is there another way to save a user selected background image besides the registry?
|
|
|
|
|
Save it to a file??
The Bitmap object has a Save method you can use.
|
|
|
|
|
Just very new and can't get it to show up when I reload the form. But thanks for your help. For some reason when I try to save it to the registry I don't think it's reading the registry value.
|
|
|
|
|
Bitmap's constructor also takes a filename when you want to load it back in.
Dim myImage As New Bitmap( filepath )
|
|
|
|
|
Thanks for the help
|
|
|
|
|
We use SourceSafe at work, and today, I added a VB.Net project (converted from C#) to the repository. I then tried to checkout a file to work on it. SourceSafe shows it's checked out, and on the hard drive, the file shows that it's NOT read-only. When I tried to open the file in the IDE, however, it still shows as being read-only, and I can't edit it.
I've tried a number of variations on that usage theme, but I can't edit the file. When I try to do the same thing in the old C# project, everything works as expected.
I do NOT have the IDE tied into SourceSafe, and I'm not at all eager to turn that "feature" on in the IDE.
Does anyone know why this is happening, and how to fix it?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Because you're not using the integrated tool, you may just have to close the solution, shut down the IDE and then reopen everything again. I've encountered similar behavior when doing this after checking out from subversion. I think the IDE is trying to be "smart" on file permissions.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Try undo checkout and then checkout once again.
|
|
|
|
|
As someone else mentioned, you probably need to exit and restart the IDE. VS tends to cache file attributes rather than re-check them every time you want to do something.
You might also want to check that the working folder for the project in SourceSafe is the same folder from which you are opening the file in the IDE.
John Simmons / outlaw programmer wrote: I do NOT have the IDE tied into SourceSafe, and I'm not at all eager to turn that "feature" on in the IDE.
I'll probably get flamed for this, but why not?
SourceSafe integrates perfectly well with Visual Studio, as long as you use the latest version of SourceSafe (VSS 2005) with VS2008 and later. Earlier versions still work, but are missing some bug fixes that the later versions of Visual Studio need.
SourceSafe isn't the best source control solution in the world, but it isn't the complete "dog's arse" (as our friends from Oz would put it) that everyone says it is.
Software Zen: delete this;
|
|
|
|
|
The problem is that you converted your project to VB.NET from c#. If you convert it back... everything will work fine
I kid
|
|
|
|
|
Get rid of Source-Safe and move to Subversion. You will never get the type of issues you are describing...
Besides, Subversion is free...
Steve Naidamast
Black Falcon Software, Inc.
blackfalconsoftware@ix.netcom.com
|
|
|
|
|
Source-Safe is anything but safe. Make sure your data base never gets too big, make sure you never run out of disk space, etc. Actually you should probably memorize these Best Practices.
To me is sounds like running with Scissors would be safer...
|
|
|
|
|
Oh my, I thought it couldn't get worse when you said you had to convert C# to VB...
Now VB + SourceSafe... Oh my, you are F*****!!
Did you start looking for a new job yet?
|
|
|
|
|
Well, that was a big help. Not!
|
|
|
|
|
I would suggest the same as what was already suggested... So no point on that, just commenting on the events
|
|
|
|
|
I have a class library which contains a class called JBXFile which has a save method:
Public Sub Save(ByRef roomInformation As SortedList(Of Decimal, Room))
Save(Me.FilePath, roomInformation)
End Sub
This in turn calls the following method:
Public Sub Save(ByVal filepath As String, ByRef roomInformation As SortedList(Of Decimal, Room))
....
....
End Sub
Now in my main form I try to call this method with JBXFile.Save(Rooms) . Rooms is also a sorted list of decimal, room. For some reason though the IDE is giving me an error stating:
Error 5 Reference required to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the type 'System.Collections.Generic.SortedList`2'. Add one to your project.
I don't understanding why this error is occuring. What is a 'System.Collection.Generic.SortedList`2'. In the form I have a reference to
System
System.Collections
System.Generics
I tried all three to see if it would help. Can you not pass sorted lists as an argument? This has brought my application to a complete halt. Thanks in advanced for any help.
Dominick
|
|
|
|
|
In your form, you either need an appropriate Imports statement e.g.
Imports System.Collections.Generic
or else you need to fully qualify your reference(s) in your code to the SortedList class as System.Collections.Generic.SortedList .
|
|
|
|
|
That looks a bit like a mess. For generic collections you need:
Imports System.Collections.Generic
and no extra reference. All collections are located in the System.dll which is always included.
AFAIK there is no such thing as System.Generics
Are you by any chance mixing different versions of .NET? It can't be done (well there is a small exception, you don't want it, trust me).
Suggestion: do a "clear build", i.e. remove all existing intermediate files such as .obj, actually remove the obj folder(s) of your project, then do a full rebuild.
|
|
|
|
|
My mistake I had a reference to:
System
System.Collections
System.Collections.Generics
However I did notice something about the version numbers. The external assembly as a System.dll version number of 2.0.0.0 while my form application has a System.dll version number of 3.5.0.0. Could this be the problem? If so how would I go about bring my external assembly to version 3.5.0.0 with having to re-write the application? BTW this must have been a severe oversight has I alway target my applications for .NET 3.5.
|
|
|
|
|
Because the external assembly and the form application were using different version of the System.dll I decided to make a new class dll that was targeted to the same version as the form application. However, I'm still getting the same error message. Why is it telling me that I need to reference V2.0.0.0 of the System.dll when both the form application and the class library are using V3.5.0.0 of the System.dll. What am I missing here?
|
|
|
|
|
Okay it has been solved. It had to do with the version of the system dll's not matching. Thanks for the help...I alway target my applications to 3.5 so I don't know why this one was 2.0. It is something I would never have thought to check.
|
|
|
|
|
Glad you got it working.
BTW: replying to your own message gives you a message box ("is this what you really want?") as nobody will get any e-mail notification. One normally replies to someone else's message, and that someone then gets an e-mail...
|
|
|
|