예제 #1
0
 private void Remove(ControlWithImage controlWithImage)
 {
     DesignPanel.Controls.Remove(controlWithImage);
     _addedImages.Where(i => i != controlWithImage && i.Level > controlWithImage.Level).ForEach(i => i.Level--);
     _addedImages.Remove(controlWithImage);
     _lastLevel--;
 }
예제 #2
0
        public override object Clone()
        {
            var clone = new ControlWithImage(GetOriginalImage(), _designer)
            {
                Transparent       = Transparent,
                _addedToComponent = _addedToComponent,
                Region            = Region,
                Location          = Location
            };

            return(clone);
        }
예제 #3
0
        private void BrowseComponentImageDialog_FileOk(object sender, CancelEventArgs e)
        {
            var image   = new Bitmap(BrowseComponentImageDialog.FileName);
            var control = new ControlWithImage(image, this);

            if (MessageBox.Show("Do you want to make this image transparent?", "Transparent", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                control.Transparent = true;
            }

            DesignPanel.Controls.Add(control);
            control.Level = _lastLevel++;
            DesignPanel.Refresh();
            _addedImages.Add(control);
        }
예제 #4
0
        public int ProcessDesignNode(XmlNode designNode)
        {
            foreach (Control c in this.Controls)
            {
                if (c is ControlWithImage)
                {
                    ((ControlWithImage)c).DisposeImage();
                    Controls.Remove(c);
                }
            }

            DrawnFromCode = false;

            foreach (XmlAttribute a in designNode.Attributes)
            {
                if (a.Name == "code" && a.Value == "true")
                {
                    DrawnFromCode = true;

                    var path = string.Format("{0}\\Data\\{1}\\{2}Design.cs", ProjectPath, ArcDirectoryName, name);

                    if (!File.Exists(path))
                    {
                        var contents =
                            @"public stati void DrawComponent(" + GetType() + @" component, Graphics graphics) 
{
    // This is auto generated code. Please, edit only method body.
    // Define how component is drawn here.
}";
                        File.WriteAllText(path, contents);
                    }

                    return(PrecompileDesignCode());
                }
            }

            if (!DrawnFromCode)
            {
                var imageControls = new List <ControlWithImage>();

                foreach (XmlNode node in designNode.ChildNodes)
                {
                    if (node.Name == "image")
                    {
                        string fileName    = null;
                        int    x           = 0;
                        int    y           = 0;
                        int    level       = 0;
                        bool   transparent = false;

                        foreach (XmlNode property in node.ChildNodes)
                        {
                            switch (property.Name)
                            {
                            case "file":
                                fileName = property.InnerText;
                                break;

                            case "level":
                                level = Convert.ToInt32(property.InnerText);
                                break;

                            case "x":
                                x = Convert.ToInt32(property.InnerText);
                                break;

                            case "y":
                                y = Convert.ToInt32(property.InnerText);
                                break;

                            case "transparent":
                                transparent = Convert.ToBoolean(property.InnerText);
                                break;

                            default:
                                break;
                            }
                        }

                        CopyImageToTempFolder(fileName);
                        var image   = new Bitmap(string.Format("{0}/temp/{1}", ProjectPath, fileName));
                        var control = new ControlWithImage(image, null)
                        {
                            Transparent = transparent,
                            Location    = new Point(x, y),
                            Level       = level
                        };

                        imageControls.Add(control);
                        control.Draw();
                    }
                    else if (node.Name == "pin")
                    {
                        int    x       = 0;
                        int    y       = 0;
                        string pinName = null;

                        foreach (XmlNode property in node.ChildNodes)
                        {
                            switch (property.Name)
                            {
                            case "name":
                                pinName = property.InnerText;
                                break;

                            case "x":
                                x = Convert.ToInt32(property.InnerText);
                                break;

                            case "y":
                                y = Convert.ToInt32(property.InnerText);
                                break;

                            default:
                                break;
                            }
                        }

                        var pin = GetPin(pinName);
                        pin.Location = new Point(x, y);
                    }
                }

                int lowerBorder = imageControls.Select(c => c.Location.Y + c.Height).Max();
                int upperBorder = 0;
                int leftBorder  = 0;
                int rightBorder = imageControls.Select(c => c.Location.X + c.Width).Max();

                foreach (var p in GetAllPins())
                {
                    if (p.Location.X < leftBorder)
                    {
                        leftBorder = p.Location.X;
                    }
                    if (p.Location.X + p.Width > rightBorder)
                    {
                        rightBorder = p.Location.X + p.Width;
                    }
                    if (p.Location.Y < upperBorder)
                    {
                        upperBorder = p.Location.Y;
                    }
                    if (p.Location.Y + p.Height > lowerBorder)
                    {
                        lowerBorder = p.Location.Y + p.Height;
                    }
                }

                Size = new Size(rightBorder - leftBorder + 1, lowerBorder - upperBorder + 1);

                foreach (var c in imageControls)
                {
                    c.SetBounds(c.Location.X - leftBorder, c.Location.Y - upperBorder, c.Width, c.Height);
                    c.AddToSystemComponent(this);
                    if (Region == null)
                    {
                        Region = c.Region.Clone();
                    }
                    else
                    {
                        Region.Union(c.Region);
                    }
                }

                foreach (var p in GetAllPins())
                {
                    Region.Union(new Rectangle(p.Location.X, p.Location.Y, p.Size.Width, p.Size.Height));
                }

                imageControls.OrderBy(c => c.Level).ForEach(c => c.BringToFront());
                GetAllPins().ForEach(p => p.BringToFront());
            }

            return(0);
        }
예제 #5
0
 public void SendToBack(ControlWithImage controlWithImage)
 {
     controlWithImage.SendToBack();
     _addedImages.Where(i => i != controlWithImage && i.Level < controlWithImage.Level).ForEach(i => i.Level++);
     controlWithImage.Level = 0;
 }
예제 #6
0
 public void BringToFront(ControlWithImage controlWithImage)
 {
     controlWithImage.BringToFront();
     _addedImages.Where(i => i != controlWithImage && i.Level > controlWithImage.Level).ForEach(i => i.Level--);
     controlWithImage.Level = _lastLevel;
 }