This project has moved and is read-only. For the latest updates, please go here.

WF - Hosting SharpVectors WPF


HeyHo Paul,

it is nice that you tried to help me, but it aint saying me anything right now.
It would be very nice if you could show me what you are meaning.

My situation is that we have complete Software in VB.NET 2010 in Windows Forms and we need to add some SVG we created for another branch.

With friendly Regards
Jan aka. Sonorpearl

file attachments


Sonorpearl wrote May 19, 2015 at 10:26 AM

Thank you Paul for your Example.

The only Problem is that I can´t figure out. How to scale the svg properly.

How can I change the width/height to 100% of the HostElement, everytime it changes?
Or if that is too complicated. How can I parse a width/height?

With friendly Regards
Jan aka. Sonorpearl

wrote May 21, 2015 at 12:32 PM

SelormeyPaul wrote May 21, 2015 at 12:32 PM

Simply host the SvgCanvas in a Viewbox, which will take care of the scaling. Also, setting the SvgCanvas.AutoSize = True will let the canvas assume the size of the drawing.

I have uploaded an updated code for the demo.

Best regards,

wrote May 22, 2015 at 8:07 AM

Sonorpearl wrote May 22, 2015 at 8:07 AM

HeyHo Paul,

Thank you again, but I figured it out myself. I just used ViewBox instead of Canvas. It worked as I suspected.
Now I have one last Problem with a MouseEvent.

The Thing is that I have an ElementHost with an SVGViewbox as an Child.
And If I load an SVG that does not fill up the complete Space.
That means the ElementHost ist for example 100x100 big and the SVG fills 100x50 because its not a square. Than there is "Room" left.

Now I have registered an Listener on Every Event I can think of: Handles ...
Handles MyBase.MouseUp

If I click on the Edge it does throw an Event.
If I click on the Image is does throw an Event.
But if I click on the Space in between it doesnt.
I have attached an Files Click.png there you can see the "Room" in Between, better.

Sonorpearl wrote May 22, 2015 at 8:08 AM


Sonorpearl wrote May 22, 2015 at 9:35 AM

Okay I think I got it now, too.
    AddHandler ElementHost1.HostContainer.MouseLeftButtonUp, AddressOf ElementHost12_MouseUp
    AddHandler ElementHost1.HostContainer.PreviewMouseLeftButtonUp, AddressOf ElementHost13_MouseUp
    AddHandler ElementHost1.HostContainer.MouseUp, AddressOf ElementHost14_MouseUp
Those get thrown if you click the Space in between.
I added now about 20 MouseEvents. Every even possible to get the result. xD
Thank you.

Sonorpearl wrote Jun 2, 2015 at 1:52 PM

HeyHo Paul,

I´ve a new Request. Since I can load and get the Click-Events now properly, I want to create a real "Button" now. The Button shall have a special SVG-Image like a Folder or a Plus or whatever and a Button-Design.
So I would need 2 SVGViewbox.

But the Problem is that I need an ElementHost in to load your Library.
And the ElementHost is not Transparent and cant be made Transparent.
I even tried it with Capturing the Background and set it as BackgroundImage,

but that is too heavy for the Performance.

theCtl = PSVG1

theCtl.Visible = False

bmp = New Bitmap(theCtl.Width, theCtl.Height)
MyGraphics = Graphics.FromImage(bmp)
MyGraphics.CopyFromScreen(intSourceX, intSourceY, 0, 0, bmp.Size)

theCtl.BackgroundImageLayout = ImageLayout.None

theCtl.BackgroundImage = bmp

It takes way too long and it would need a special Resize-Handler and all.

So the Functionality I need is that I can display 2 or more SVG-Images at top of each others.
Parsing a Top / Left... Variable.
And so that every SVG really is transparent (What it is without the ElementHost, but which is required) and shows the SVG behind it.

With friendly Regards
Jan aka. Sonorpearl

SelormeyPaul wrote Jun 2, 2015 at 4:05 PM

Try the SvgPictureBox in the SharpVectors.Rendering.Gdi. The GDI+ version is not updated for sometime now, but it could handle some of the simple files.

Sonorpearl wrote Jul 9, 2015 at 10:18 AM

HeyHo Paul,

I could not resolve the Problem by now. Its kinda hard getting a full working SVG on, but I want to try further. Can you show me what do you mean by SvgPictureBox? Could it handle all things I need? And what is old about that?

SelormeyPaul wrote Jul 9, 2015 at 4:43 PM

The rendering part of the library is extensible and there are currently two implementations: WPF and GDI+ (or Windows Forms). The Windows Forms control is the SvgPictureBox in the assembly SharpVectors.Rendering.Gdi. The Windows Forms version is less maintained, you will have to try it to see if it meets all your needs. It should be able to handle the "Button" problem you were talking about.

Best regards,

Sonorpearl wrote Jul 24, 2015 at 9:25 AM

HeyHo Paul,

the Project were currently set on Ice. But I will start trying again.

Windows Forms Project

Can the PictureBox be truely Transparent if I load an Transparent SVG in it?
With truely Transparent I mean that you can see other SVG Elements or Form Elements behind it and not the Form.

There are some basic Events I need: Click, Enter, Focus.

I want to create a Usercontrol where you can set the filepath and than the Object starts rendering.
That Object should always rerender itself if the Size of the Usercontrol has changed.

I´ve already done the Project with SvgViewbox, but ran into the errors I listed above.
The Elementhost is not transparent, even with several hours of Trial and Error and help of some strangers I couldnt get it running.

That was one of the Problems I ran into:

Now I will try to create the same Example with your SvgPictureBox, but I may need help or you could do it faster.

A Final Button should behave and look like this:
  • Focus Rectangle
  • Clickable / Throwing Events to the Outside
  • Icon SVG
  • Background SVG
Thank you for your time Paul.

I will start coding now.

Sonorpearl wrote Jul 24, 2015 at 10:43 AM

HeyHo Paul,

I am getting an Error, while trying to add the SvgPictureBox to a UserControl:

Inheritance security rules violated while overriding member: "SharpVectors.Rendering.Gdi.GdiGraphicsRenderer.get_Windows()"
Security accessibility of the overriding method must match the security accessibility of the method being overriden.