Has anyone done a complete conversion from wpf Pen to gdi + one?
It doesn't seem complicated at first: use a constructor with the appropriate brush. But there are so many small details: different brushes (5 in wpf and 5 in gdi + with different names, properties, etc.), as well as the properties of the pen itself.
Perhaps there is a very simple solution, for example ToString() / Parse() alone or through serialization or perhaps a dedicated method or hidden class. Do not want to go in a long and wrong way if(type is ...) .
Here is one possible approach (may not work to demonstrate)
using System.Windows.Media; using GDI = System.Drawing; public static GDI.Pen ToGDI(this Pen pen) { var brush = pen.Brush; var thickness = pen.Thickness; if(brush is SolidColorBrush) { var color = ((SolidColorBrush)brush).Color; return new GDI.Pen(new GDI.SolidBrush(Colors.FromArgb(color.A, color.R, color.G, color.B)), (float)thickness); } else if(brush is ...) { ... } }
c # winforms wpf
Sinatr
source share