public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is BrushData) { string s = string.Empty; NSBrushType type = (value as BrushData).BrushType; if (type == NSBrushType.Null) { s = "空"; } else if (type == NSBrushType.Solid) { s = "单色"; } else if (type == NSBrushType.Hatch) { s = "图案"; } else if (type == NSBrushType.Textrue) { s = "图片"; } else if (type == NSBrushType.LinearGradient) { s = "渐变"; } else if (type == NSBrushType.PathGradient) { s = "放射"; } return(s); } return(base.ConvertTo(context, culture, value, destinationType)); }
public void Deserialize(BinaryFormatter bf, Stream s) { version = (int)bf.Deserialize(s); BrushType = (NSBrushType)bf.Deserialize(s); this.SolidBrushInfo.Deserialize(bf, s); this.LinearGradientBrushInfo.Deserialize(bf, s); this.TextrueBrushInfo.Deserialize(bf, s); this.HatchBrushInfo.Deserialize(bf, s); this.PathGradientBrushInfo.Deserialize(bf, s); }
public void InitLinearGradientBrush(Color color1, Color color2, float angle) { BrushType = NSBrushType.LinearGradient; LinearGradientBrushInfo.Angle = angle; ColorBlend cb = new ColorBlend(); Color[] cls = new Color[2]; cls[0] = color1; cls[1] = color2; cb.Colors = cls; float[] fs = new float[2]; fs[0] = 0; fs[1] = 1; cb.Positions = fs; LinearGradientBrushInfo.ColorBlend = cb; }
public void Deserialize(FileStream fs, BinaryFormatter bf) { version = (int)bf.Deserialize(fs); Text = (string)bf.Deserialize(fs); NSBrushType BrushType = (NSBrushType)bf.Deserialize(fs); if (BrushType == NSBrushType.Solid) { Color clr = (Color)bf.Deserialize(fs); Brush = new SolidBrush(clr); } else if (BrushType == NSBrushType.LinearGradient) { int length = (int)bf.Deserialize(fs); Color[] clrs = new Color[length]; float[] pos = new float[length]; for (int i = 0; i < length; i++) { clrs[i] = (Color)bf.Deserialize(fs); pos[i] = (float)bf.Deserialize(fs); } Angle = (float)bf.Deserialize(fs); Rectangle Rect = new Rectangle(0, 0, CellLength, CellLength); Brush = new LinearGradientBrush(Rect, Color.Red, Color.FromArgb(255, 0, 255, 0), Angle); ColorBlend cb = new ColorBlend(); cb.Colors = clrs; cb.Positions = pos; ((LinearGradientBrush)Brush).InterpolationColors = cb; } else if (BrushType == NSBrushType.PathGradient) { int length = (int)bf.Deserialize(fs); Color[] clrs = new Color[length]; float[] pos = new float[length]; for (int i = 0; i < length; i++) { clrs[i] = (Color)bf.Deserialize(fs); pos[i] = (float)bf.Deserialize(fs); } Point[] pts = new Point[4]; pts[0] = new Point(0, 0); pts[1] = new Point(0, CellLength); pts[2] = new Point(CellLength - 4, CellLength); pts[3] = new Point(CellLength - 4, 0); GraphicsPath path = new GraphicsPath(); path.AddLines(pts); Brush = new PathGradientBrush(path); ColorBlend cb = new ColorBlend(); cb.Colors = clrs; cb.Positions = pos; ((PathGradientBrush)Brush).InterpolationColors = cb; } }
public void InitSolidBrush(Color color) { BrushType = NSBrushType.Solid; SolidBrushInfo.Color = color; }
public void InitNull() { BrushType = NSBrushType.Null; }