Hi Everybody,
I am using the DrawSVG method from Alwyn to do an image button in my project but I have some problems to directly load the picture in SVG (as string).
I have two SVG files in gray and blue color that I would like to use to make a image button inside a canvas. The idea is when the mouse is entered the area of the control I want to replace the gray picture by the other one. To manage this button, the canvas control has a ‘Paint’ event handler with this code:
[code] Dim f As FolderItem = GetFolderItem("").parent.child(“SVG File.svg”)
Dim tis As TextInputStream
If f <> nil then
tis = TextInputStream.Open(f)
tis.Encoding = Encodings.MacRoman
SvgXML = tis.ReadAll
tis.Close
End if
if SvgXML <> “” then
g.DrawSVG SvgXML, 100, 100
end if[/code]
When I debug the project, I get an error in ‘tis = TextInputStream.Open(f)’ line but I don’t know how to resolve this problem.
I attach my example project here: example link
Could anybody help me, please?
Thank you very much.
Sergio
Without looking at your code, the path is wrong.
You get a folder item here:
Dim f As FolderItem = GetFolderItem("").parent.child("SVG File.svg")
It doesnt matter if the file exists, the folderitem wont be nil
So this line is passed:
If f <> nil then
And this line fails because there is no such file:
tis = TextInputStream.Open(f)
Try this:
[code]If f <> nil then
if f.exists then
tis = TextInputStream.Open(f)
tis.Encoding = Encodings.MacRoman
SvgXML = tis.ReadAll
tis.Close
else
msgbox “There is no such file”
end if
End if[/code]
… and this is probably due to the difference in relative paths between a debug and a release application.
Thanks Jeff and Jean-Paul,
I have updated my example project with your suggestions and now I don’t get any error message but I don’t see my picture when the debug mode is run. What’s wrong?
Sergio
Thank you very much Jean-Paul,
this is exactly that I want. I have modified again the example to accept different status into the canvas. I have added a property as boolean and modified the Paint event handler with this code:
[code] Dim f As FolderItem
if mFilled then
f = GetFolderItem("").child(“test_00020_blue.svg”)
else
f = GetFolderItem("").child(“test_00020_gray.svg”)
end if
if f <> nil and f.Exists then
doc = new XmlDocument(f)
end if
if doc <> nil then
g.DrawSVG doc, 0, 0
end if[/code]
Finally I have created two new event handlers: ‘MouseEnter’ and ‘MouseExit’ with the same code:
mFilled = Not mFilled
Me.Invalidate
With these modifications, my example works perfectly.
Thank you very much for your help. Great!!
Sergio