示例#1
0
        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);
        }
示例#2
0
        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;
        }