示例#1
0
        /// <summary>
        /// This is overridden to store a reference to the image area collection for use by the static
        /// <see cref="Areas"/> property above.
        /// </summary>
        /// <param name="context">The descriptor context</param>
        /// <param name="provider">The provider</param>
        /// <param name="value">The collection as an object</param>
        /// <returns>The edited collection as an object</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Areas = (ImageAreaCollection)value;

            object editedValue = base.EditValue(context, provider, value);

            Areas = null;

            return(editedValue);
        }
        /// <summary>
        /// This is overridden to store a reference to the image area collection for use by the static
        /// <see cref="Areas"/> property above.
        /// </summary>
        /// <param name="context">The descriptor context</param>
        /// <param name="provider">The provider</param>
        /// <param name="value">The collection as an object</param>
        /// <returns>The edited collection as an object</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Areas = (ImageAreaCollection)value;

            object editedValue = base.EditValue(context, provider, value);

            Areas = null;

            return editedValue;
        }
示例#3
0
        /// <summary>
        /// This is used to paint the image and the image area
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void pnlImage_Paint(object sender, PaintEventArgs e)
        {
            Graphics g        = e.Graphics;
            Point    ptOffset = new Point(pnlImage.AutoScrollPosition.X, pnlImage.AutoScrollPosition.Y);

            if (image != null)
            {
                this.Animate();
                ImageAnimator.UpdateFrames();

                g.DrawImage(image, ptOffset.X, ptOffset.Y, imageWidth, imageHeight);
            }

            // Draw the other areas for reference if requested
            if (chkShowAll.Checked)
            {
                ImageAreaCollection ic = ImageMapAreaEditorDlg.Areas;

                for (int nIdx = 0; nIdx < ic.Count; nIdx++)
                {
                    if (nIdx != areaIndex)
                    {
                        ic[nIdx].DrawFocusFrame(g, ptOffset);
                    }
                }
            }

            if (points.Count > 0)
            {
                switch (shape)
                {
                case ImageAreaShape.Rectangle:
                    UnsafeNativeMethods.DrawReversibleRectangle(g, points[0], points[1], ptOffset);
                    break;

                case ImageAreaShape.Circle:
                    UnsafeNativeMethods.DrawReversibleCircle(g, points[0], radius, ptOffset);
                    break;

                case ImageAreaShape.Ellipse:
                    UnsafeNativeMethods.DrawReversibleEllipse(g, points[0], points[1], ptOffset);
                    break;

                default:
                    // Note that the polygon isn't closed in the designer
                    UnsafeNativeMethods.DrawReversiblePolygon(g, points, false, ptOffset);
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// On load, set the information labels and load the image
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void ImageMapAreaEditorDlg_Load(object sender, EventArgs e)
        {
            try
            {
                this.Animate(false);

                if (image == null)
                {
                    // If there is no image at all, create a temporary image
                    if (imageName == null)
                    {
                        // Set a name so that the image is disposed of on close
                        imageName = "BLANK";

                        if (this.ImageHeight == 0)
                        {
                            this.ImageHeight = 300;
                        }

                        if (this.ImageWidth == 0)
                        {
                            this.ImageWidth = 500;
                        }

                        Bitmap bm = new Bitmap(this.ImageWidth, this.ImageHeight);

                        using (Graphics g = Graphics.FromImage(bm))
                        {
                            g.FillRectangle(Brushes.White, 0, 0, this.ImageWidth, this.ImageHeight);
                        }

                        image = (Image)bm;
                    }
                    else
                    {
                        image = Image.FromFile(imageName);
                    }

                    if (this.ImageWidth == 0)
                    {
                        this.ImageWidth = image.Width;
                    }

                    if (this.ImageHeight == 0)
                    {
                        this.ImageHeight = image.Height;
                    }
                }

                this.Animate();

                pnlImage.AutoScrollMinSize = new Size(imageWidth, imageHeight);
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "Unable to load image file: {0}",
                                              ex.ToString()), "Error Loading Image", MessageBoxButtons.OK, MessageBoxIcon.Error);

                btnCancel.PerformClick();
            }

            lblImageInfo.Text = String.Format(CultureInfo.InvariantCulture, "Image: {0}  Height: {1}  Width: {2}",
                                              Path.GetFileName(imageName), imageHeight, imageWidth);

            switch (shape)
            {
            case ImageAreaShape.Rectangle:
                lblInstructions.Text = "Click and drag to define rectangle area";
                break;

            case ImageAreaShape.Circle:
                lblInstructions.Text = "Click and drag to define circle area";
                break;

            case ImageAreaShape.Ellipse:
                lblInstructions.Text = "Click and drag to define ellipse area";
                break;

            default:
                lblInstructions.Text = "Click points to define the polygon";

                // Can't shrink or increase the dimensions of a polygon
                btnIncLeftTop.Visible                    = btnIncTop.Visible = btnIncRightTop.Visible = btnIncLeft.Visible =
                    btnIncAll.Visible                    = btnIncRight.Visible = btnIncLeftBottom.Visible = btnIncBottom.Visible =
                        btnIncRightBottom.Visible        = btnDecLeftTop.Visible = btnDecTop.Visible =
                            btnDecRightTop.Visible       = btnDecLeft.Visible = btnDecAll.Visible = btnDecRight.Visible =
                                btnDecLeftBottom.Visible = btnDecBottom.Visible = btnDecRightBottom.Visible = false;
                break;
            }

            // Locate the image area in the collection being edited based on the shape and coordinates.  We use
            // this to know which area not to draw when the "Show All" option is on.  We turn that on
            // automatically if the image map is a Windows Forms image map control and it is set to owner drawn.
            ImageAreaCollection ic = ImageMapAreaEditorDlg.Areas;

#if !IMAGEMAPWEB
            EWSoftware.ImageMaps.Windows.Forms.ImageMap im =
                (ic.ImageMapControl as EWSoftware.ImageMaps.Windows.Forms.ImageMap);

            if (im != null && im.OwnerDraw)
            {
                chkShowAll.Checked = true;
            }
#endif
            string coordinates = this.Coordinates;
            int    idx         = 0;

            foreach (IImageArea a in ic)
            {
                if (a.Shape == shape && a.Coordinates == coordinates)
                {
                    areaIndex = idx;
                }

                idx++;
            }
        }