/// <summary> /// 新增一个可拖拽标准形状 /// </summary> /// <param name="name"></param> /// <param name="basicShape"></param> /// <param name="size"></param> /// <param name="point"></param> /// <param name="background"></param> /// <param name="borderBrush"></param> /// <returns></returns> public DragShape AddDragShape(string name, EmBasicShape basicShape, Size size, Point point, Brush background, Brush borderBrush, string sText = "") { int childCount = this.Children.Count; DragShape shape = new DragShape() { CtrlName = string.IsNullOrEmpty(name) ? Guid.NewGuid().ToString("N") : name, Background = background, BorderBrush = borderBrush, Name = "DragShape" + childCount.ToString(), Width = size.Width, Height = size.Height, Position = point, ZIndex = childCount, BelongCanvas = this, //设置为当前Canvas IsReadOnly = this.IsReadOnly, //只读 Text = sText, BasicShapeType = basicShape, ShapePoints = DrawBasicShape.GetShape(basicShape, size), }; shape.DragDelta += DragDelta; shape.DragStarted += DragStarted; shape.DragCompleted += DragCompleted; bSaved = false; DragThumbs.Add(shape); this.Children.Add(shape); //添加到界面上 Canvas.SetZIndex(shape, shape.ZIndex); //设置界面ZIndex属性 shape.IsSelected = !IsReadOnly; return(shape); }
public bool LoadFile(string filePath) { if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { return(false); } XDocument xmlDoc = new XDocument(); xmlDoc = XDocument.Load(filePath); XElement root = xmlDoc.Elements("root").FirstOrDefault(); if (root == null) { return(false); } XElement drags = root.Elements("FlowDesigns").FirstOrDefault(); if (drags == null) { return(false); } RemoveAllDragThumb(); //清除所有 IEnumerable <XElement> nodes = drags.Elements(); foreach (XElement item in nodes) { string name = item.Attribute("Name")?.Value ?? ""; string position = item.Attribute("Position")?.Value ?? "0,0"; string size = item.Attribute("Size")?.Value ?? "10,10"; string source = item.Attribute("Source")?.Value ?? ""; //图片路径 string sBackground = item.Attribute("Background")?.Value ?? "#FF00ACFF"; //背景色 Brush background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBackground)); string sBorderBrush = item.Attribute("BorderBrush")?.Value ?? "White"; //边框 Brush borderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBorderBrush)); EmFlowCtrlType ctrlType = (EmFlowCtrlType) System.Enum.Parse(typeof(EmFlowCtrlType), item.Attribute("ItemType")?.Value ?? "None"); //控件类型 EmBasicShape shapeType = (EmBasicShape)System.Enum.Parse(typeof(EmBasicShape), item.Attribute("Shape")?.Value ?? "None"); DragThumb newThumb = new DragThumb(); if (ctrlType == EmFlowCtrlType.Image) { if (!source.Contains(":")) { source = System.Environment.CurrentDirectory + (source[0] == '/' ? "" : "/") + source; } if (File.Exists(source)) { newThumb = AddDragImage(name, SafeConverter.SafeToSize(size), SafeConverter.SafeToPoint(position), new BitmapImage(new Uri(source)), background, borderBrush); } } else if (ctrlType == EmFlowCtrlType.PolygonSharp) { newThumb = AddDragShape(name, shapeType, SafeConverter.SafeToSize(size), SafeConverter.SafeToPoint(position), background, borderBrush); } else if (ctrlType == EmFlowCtrlType.CircleSharp) { newThumb = AddDragCircle(name, SafeConverter.SafeToSize(size), SafeConverter.SafeToPoint(position), background, borderBrush); } else if (ctrlType == EmFlowCtrlType.Video) { newThumb = AddDragVideo(name, SafeConverter.SafeToSize(size), SafeConverter.SafeToPoint(position), source); } string sForeground = item.Attribute("Foreground")?.Value ?? "#FF000000"; //字体颜色 Brush foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sForeground)); newThumb.Foreground = foreground; string sFontWeight = item.Attribute("FontWeight")?.Value ?? "Normal"; //文本粗体 FontWeightConverter convert = new FontWeightConverter(); newThumb.FontWeight = (FontWeight)convert.ConvertFromString(sFontWeight); string sFontSize = item.Attribute("FontSize")?.Value ?? "12"; //文字大小 newThumb.FontSize = Double.Parse(sFontSize); newThumb.MonitorItem = SafeConverter.SafeToBool(item.Attribute("Monitor")); //是否监控 newThumb.ReadOnlyCanClick = SafeConverter.SafeToBool(item.Attribute("ReadOnlyCanClick")); //是否可以单击 string text = item.Attribute("Text")?.Value ?? ""; newThumb.Text = text; } return(true); }
public static PointCollection GetShape(EmBasicShape shape, Size size) { PointCollection points = new PointCollection(); switch (shape) { case EmBasicShape.Ellipse: break; case EmBasicShape.Triangle: //三角形 points.Add(new Point(size.Width / 2, 0)); points.Add(new Point(size.Width, size.Height)); points.Add(new Point(0, size.Height)); break; case EmBasicShape.Rectangle: //矩形 points.Add(new Point(0, 0)); points.Add(new Point(size.Width, 0)); points.Add(new Point(size.Width, size.Height)); points.Add(new Point(0, size.Height)); break; case EmBasicShape.Pentagon: //五边形 points.Add(new Point(size.Width * 0.5, 0)); points.Add(new Point(size.Width, size.Height * 0.4)); points.Add(new Point(size.Width * 0.8, size.Height)); points.Add(new Point(size.Width * 0.2, size.Height)); points.Add(new Point(0, size.Height * 0.4)); break; case EmBasicShape.Hexagon: //六边形 points.Add(new Point(size.Width * 0.25, 0)); points.Add(new Point(size.Width * 0.75, 0)); points.Add(new Point(size.Width, size.Height * 0.5)); points.Add(new Point(size.Width * 0.75, size.Height)); points.Add(new Point(size.Width * 0.25, size.Height)); points.Add(new Point(0, size.Height * 0.5)); break; case EmBasicShape.Star5: //五角星 points.Add(new Point(size.Width * 0.5, 0)); points.Add(new Point(size.Width * 0.675, size.Height * 0.35)); points.Add(new Point(size.Width, size.Height * 0.425)); points.Add(new Point(size.Width * 0.75, size.Height * 0.675)); points.Add(new Point(size.Width * 0.8, size.Height)); points.Add(new Point(size.Width * 0.8, size.Height)); points.Add(new Point(size.Width * 0.5, size.Height * 0.8)); points.Add(new Point(size.Width * 0.2, size.Height)); points.Add(new Point(size.Width * 0.275, size.Height * 0.675)); points.Add(new Point(size.Width * 0, size.Height * 0.425)); points.Add(new Point(size.Width * 0.325, size.Height * 0.35)); break; case EmBasicShape.Diamond: points.Add(new Point(size.Width * 0.5, 0)); points.Add(new Point(size.Width, size.Height * 0.5)); points.Add(new Point(size.Width * 0.5, size.Height)); points.Add(new Point(0, size.Height * 0.5)); break; case EmBasicShape.Parallelogram: //points.Add(new Point(size.Width * 0.5, size.Height * 0.25)); //points.Add(new Point(size.Width, size.Height * 0.25)); //points.Add(new Point(size.Width * 0.5, size.Height*0.75)); //points.Add(new Point(0, size.Height * 0.75)); points.Add(new Point(size.Width * 0.5, 0)); points.Add(new Point(size.Width, 0)); points.Add(new Point(size.Width * 0.5, size.Height)); points.Add(new Point(0, size.Height)); break; case EmBasicShape.Arrow: points.Add(new Point(size.Width * 0, size.Height * 0.375)); points.Add(new Point(size.Width * 0.65, size.Height * 0.375)); points.Add(new Point(size.Width * 0.65, size.Height * 0.2)); points.Add(new Point(size.Width * 1, size.Height * 0.5)); points.Add(new Point(size.Width * 0.65, size.Height * 0.8)); points.Add(new Point(size.Width * 0.65, size.Height * 0.625)); points.Add(new Point(size.Width * 0, size.Height * 0.625)); break; case EmBasicShape.DoubleArrow: points.Add(new Point(size.Width * 0, size.Height * 0.5)); points.Add(new Point(size.Width * 0.35, size.Height * 0.2)); points.Add(new Point(size.Width * 0.35, size.Height * 0.375)); points.Add(new Point(size.Width * 0.65, size.Height * 0.375)); points.Add(new Point(size.Width * 0.65, size.Height * 0.2)); points.Add(new Point(size.Width * 1, size.Height * 0.5)); points.Add(new Point(size.Width * 0.65, size.Height * 0.8)); points.Add(new Point(size.Width * 0.65, size.Height * 0.625)); points.Add(new Point(size.Width * 0.35, size.Height * 0.625)); points.Add(new Point(size.Width * 0.35, size.Height * 0.8)); break; case EmBasicShape.SlopeArrow: points.Add(new Point(size.Width * 0, size.Height * 0.5)); points.Add(new Point(size.Width * 0.65, size.Height * 0.375)); points.Add(new Point(size.Width * 0.65, size.Height * 0.2)); points.Add(new Point(size.Width * 1, size.Height * 0.5)); points.Add(new Point(size.Width * 0.65, size.Height * 0.8)); points.Add(new Point(size.Width * 0.65, size.Height * 0.625)); break; case EmBasicShape.ConnectionArrow: points.Add(new Point(size.Width * 0, size.Height * 0.5 - 0.5)); points.Add(new Point(size.Width - 8, size.Height * 0.5 - 0.5)); points.Add(new Point(size.Width - 8, size.Height * 0.5 - 4)); points.Add(new Point(size.Width, size.Height * 0.5)); points.Add(new Point(size.Width - 8, size.Height * 0.5 + 4)); points.Add(new Point(size.Width - 8, size.Height * 0.5)); points.Add(new Point(size.Width * 0, size.Height * 0.5)); break; default: break; } return(points); }
private void bPaste_OnItemClick(object sender, ItemClickEventArgs e) { string sCopyValue = Clipboard.GetText(); if (string.IsNullOrEmpty(sCopyValue)) { return; } cvMain.ClearAllSelectedThumb(); cvMain.bMultiSelect = true; string[] dragThumbs = sCopyValue.Split('@'); if ((dragThumbs.Length <= 1) || (dragThumbs[0] != "DragThumb")) //纯文本 { cvMain.AddDragShape("", EmBasicShape.Rectangle, new Size(100, 75), new Point(20, 20), Brushes.Transparent, Brushes.Transparent, sCopyValue); cvMain.bMultiSelect = false; return; } for (int i = 1; i < dragThumbs.Length; i++) { string[] values = dragThumbs[i].Split('|'); if (values.Length != 12) { continue; } EmFlowCtrlType ctrlType = (EmFlowCtrlType)System.Enum.Parse(typeof(EmFlowCtrlType), values[0]); //0控件类型 string position = values[1]; //1位置 Point pos = SafeConverter.SafeToPoint(position); pos.X += 20; pos.Y += 20; string size = values[2]; //2尺寸 string sBackground = values[3]; //背景色 string sBorderBrush = values[4]; //边框 string text = values[5]; //文本 string sForeground = values[6]; //字体颜色 string sFontWeight = values[7]; //文本粗体 string sFontSize = values[8]; //文字大小 EmBasicShape shapeType = (EmBasicShape)System.Enum.Parse(typeof(EmBasicShape), values[9]); //形状类型 string source = values[10]; //图片路径 Brush background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBackground)); Brush borderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBorderBrush)); Brush foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sForeground)); DragThumb newThumb = new DragThumb(); if (ctrlType == EmFlowCtrlType.Image) { if (File.Exists(source)) { newThumb = cvMain.AddDragImage((Guid.NewGuid().ToString("N")), SafeConverter.SafeToSize(size), pos, new BitmapImage(new Uri(source)), background, borderBrush); } } else if (ctrlType == EmFlowCtrlType.PolygonSharp) { newThumb = cvMain.AddDragShape((Guid.NewGuid().ToString("N")), shapeType, SafeConverter.SafeToSize(size), pos, background, borderBrush); } else if (ctrlType == EmFlowCtrlType.CircleSharp) { newThumb = cvMain.AddDragCircle((Guid.NewGuid().ToString("N")), SafeConverter.SafeToSize(size), pos, background, borderBrush); } newThumb.Text = text; newThumb.FontSize = Double.Parse(sFontSize); newThumb.Foreground = foreground; newThumb.FontWeight = (FontWeight)(new FontWeightConverter()).ConvertFromString(sFontWeight); } cvMain.bMultiSelect = false; }