Displays images in a similar way to System.Windows.Forms.MessageBox.
Наследование: System.Windows.Forms.Form
Пример #1
0
        /// <summary>
        ///   Displays an image on the screen.
        /// </summary>
        ///
        /// <param name="title">The text to display in the title bar of the image box.</param>
        /// <param name="image">The image to show.</param>
        /// <param name="sizeMode">How to display the image inside the image box.</param>
        /// <param name="width">The width of the image box.</param>
        /// <param name="height">The height of the image box.</param>
        /// <param name="backColor">The background color to use in the window.
        ///   Default is <see cref="Color.Black"/>.</param>
        ///
        public static DialogResult Show(string title, Image image,
                                        PictureBoxSizeMode sizeMode, int width, int height, Color backColor)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            DialogResult result;

            if (width == 0 && height == 0)
            {
                switch (sizeMode)
                {
                case PictureBoxSizeMode.AutoSize:
                    width  = image.Width;
                    height = image.Height;
                    break;

                case PictureBoxSizeMode.CenterImage:
                case PictureBoxSizeMode.Normal:
                case PictureBoxSizeMode.StretchImage:
                case PictureBoxSizeMode.Zoom:
                    width  = 320;
                    height = 240;
                    break;
                }
            }

            using (ImageBox box = new ImageBox())
            {
                box.SuspendLayout();
                box.Text                = title;
                box.BackColor           = backColor;
                box.ClientSize          = new Size(width, height);
                box.pictureBox.SizeMode = sizeMode;
                box.pictureBox.Image    = image;
                box.ResumeLayout(false);

                result = box.ShowDialog();
            }

            return(result);
        }
Пример #2
0
        private static ImageBox show(string title, Image image,
                                     PictureBoxSizeMode sizeMode, int width, int height, Color backColor)
        {
            ImageBox form       = null;
            Thread   formThread = null;

            AutoResetEvent stopWaitHandle = new AutoResetEvent(false);

            GetDimensions(image, sizeMode, ref width, ref height);

            formThread = new Thread(() =>
            {
                Accord.Controls.Tools.ConfigureWindowsFormsApplication();

                // Show control in a form
                form                     = new ImageBox();
                form.Text                = title ?? "Image";
                form.formThread          = formThread;
                form.Text                = title;
                form.BackColor           = backColor;
                form.ClientSize          = new Size(width, height);
                form.pictureBox.SizeMode = sizeMode;
                form.pictureBox.Image    = image;
                form.ResumeLayout(false);

                stopWaitHandle.Set();

                Application.Run(form);
            });

            formThread.SetApartmentState(ApartmentState.STA);

            formThread.Start();

            stopWaitHandle.WaitOne();

            return(form);
        }
Пример #3
0
        /// <summary>
        ///   Displays an image on the screen.
        /// </summary>
        /// 
        /// <param name="title">The text to display in the title bar of the image box.</param>
        /// <param name="image">The image to show.</param>
        /// <param name="sizeMode">How to display the image inside the image box.</param>
        /// <param name="width">The width of the image box.</param>
        /// <param name="height">The height of the image box.</param>
        /// <param name="backColor">The background color to use in the window. 
        ///   Default is <see cref="Color.Black"/>.</param>
        /// 
        public static DialogResult Show(string title, Image image,
            PictureBoxSizeMode sizeMode, int width, int height, Color backColor)
        {
            if (image == null)
                throw new ArgumentNullException("image");

            DialogResult result;

            if (width == 0 && height == 0)
            {
                switch (sizeMode)
                {
                    case PictureBoxSizeMode.AutoSize:
                        width = image.Width;
                        height = image.Height;
                        break;

                    case PictureBoxSizeMode.CenterImage:
                    case PictureBoxSizeMode.Normal:
                    case PictureBoxSizeMode.StretchImage:
                    case PictureBoxSizeMode.Zoom:
                        width = 320;
                        height = 240;
                        break;
                }
            }

            using (ImageBox box = new ImageBox())
            {
                box.SuspendLayout();
                box.Text = title;
                box.BackColor = backColor;
                box.ClientSize = new Size(width, height);
                box.pictureBox.SizeMode = sizeMode;
                box.pictureBox.Image = image;
                box.ResumeLayout(false);

                result = box.ShowDialog();
            }

            return result;
        }