What file are you trying to save? Are you trying to save the image that is being displayed in the Canvas.
I have never used a database for this purpose. It seems more elaborate. With a Dictionary, every thing is contained in the Project. If you want to save the Canvas image between sessions, then this becomes more complicated because the Dictionary will not retain its value between sessions. You can save the contents of a Dictionary in a JSON file perhaps and the repopulate the Dictionary by accessing this file at startup.
Maybe a Database would allow you to save between sessions. I personally have not needed this functionality.
Anyway, depending on your needs you can branch out into many directions.
Var dctObjectsOnCanvas As New Dictionary
Var lineRoad As CurveShape
lineRoad.Order = 0
lineRoad.X = 20
lineRoad.X2 = 100
lineRoad.Y = 30
lineRoad.Y2 = 30
Var lineTree As CurveShape
lineTree.Order = 0
lineTree.X = 40
lineTree.X2 = 40
lineTree.Y = 50
lineTree.Y2 = 200
dctObjectsOnCanvas.Value("theRoad") = lineTree
Then you have to make sure that in the Paint event of the Canvas, it accesses the Object2D in the Dictionary.
There is a “special” Object2D called a Group2D which can hold a collection of Object2D’s so. So instead of using a Dictionary, you could just pile your various objects into the Group2D and then make sure that the Paint event of the Canvas accesses that Group2D.
Var myObjects As Group2D
myObjects.AddObject(lineRoad)
myObjects.AddObject(lineTree)
You can access the individual Object2Ds in the Group2D using an index. But you have to keep track somehow which Item is in which index. The code becomes less easy to read than what a Dictionary allows with descriptive names like “theRoad” used to access a specific Object2D
objectWanted = dctObjectsOnCanvas.Value(“theRoad”)
rather than
objectWanted = myObjects.Item(1)
P.S. As I finish this comment, I noticed Eric Williams’s comment. He is a lot more experienced than I. I would believe what he said. I am still making this reply to offer alternatives.