Inheritance: System.Windows.Forms.PictureBox
Example #1
0
        public void SizeMode_SetterGetterTest()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
            }
        }
Example #2
0
        public void SizeMode_SetterGetterTest()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
            }
        }
Example #3
0
        public void SizeMode_ErrorImageTest2()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.ShowErrorImage();

                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.CenterImage, ((PictureBox)picbox).SizeMode);
            }
        }
Example #4
0
        public void SizeMode_ErrorImageTest2()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.ShowErrorImage();

                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.CenterImage, ((PictureBox)picbox).SizeMode);
            }
        }
Example #5
0
        public void SizeMode_RestoreTest()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                picbox.ShowErrorImage();

                picbox.Image = TestUtils.CreateDummyImage();

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
            }
        }
Example #6
0
        public void SizeMode_RestoreTest()
        {
            using (var picbox = new OTPictureBox())
            {
                picbox.SizeMode = PictureBoxSizeMode.Zoom;

                picbox.ShowErrorImage();

                picbox.Image = TestUtils.CreateDummyImage();

                Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
                Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
            }
        }
Example #7
0
        public async Task SetImageFromAsync_ErrorTest()
        {
            using (var picbox = new OTPictureBox())
            {
                // Mono でのテスト実行時にデッドロックする問題の対策
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

                var tcs = new TaskCompletionSource <MemoryImage>();

                var setImageTask = picbox.SetImageFromTask(() => tcs.Task);

                Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);

                tcs.SetException(new InvalidImageException());
                await setImageTask;

                Assert.Equal(picbox.ErrorImage, ((PictureBox)picbox).Image);
            }
        }
Example #8
0
        public async Task SetImageFromAsync_Test()
        {
            using (var picbox = new OTPictureBox())
            {
                // Mono でのテスト実行時にデッドロックする問題の対策
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

                var tcs = new TaskCompletionSource <MemoryImage>();

                var setImageTask = picbox.SetImageFromTask(() => tcs.Task);

                Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);

                var image = TestUtils.CreateDummyImage();
                tcs.SetResult(image);
                await setImageTask;

                Assert.Equal(image, picbox.Image);
            }
        }
Example #9
0
        public async Task SetImageFromAsync_Test()
        {
            using (var picbox = new OTPictureBox())
            {
                // Mono でのテスト実行時にデッドロックする問題の対策
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

                var tcs = new TaskCompletionSource<MemoryImage>();

                var setImageTask = picbox.SetImageFromTask(() => tcs.Task);

                Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);

                var image = TestUtils.CreateDummyImage();
                tcs.SetResult(image);
                await setImageTask;

                Assert.Equal(image, picbox.Image);
            }
        }
Example #10
0
        public async Task SetImageFromAsync_ErrorTest()
        {
            using (var picbox = new OTPictureBox())
            {
                // Mono でのテスト実行時にデッドロックする問題の対策
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

                var tcs = new TaskCompletionSource<MemoryImage>();

                var setImageTask = picbox.SetImageFromTask(() => tcs.Task);

                Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);

                tcs.SetException(new InvalidImageException());
                await setImageTask;

                Assert.Equal(picbox.ErrorImage, ((PictureBox)picbox).Image);
            }
        }
Example #11
0
        public static void Show(OTPictureBox picbox, Point originPos)
        {
            if (picbox == null || picbox.Image == null)
                throw new ArgumentNullException("picbox");

            if (picbox.IsDisposed)
                throw new ObjectDisposedException("picbox");

            // ポップアップ表示中は、サムネイル枠の画像を乗っ取ってダミーとすり替えておく
            var thumbnail = picbox.Image;
            picbox.Image = null;

            var popup = new ThumbnailZoomWindow(thumbnail, (ThumbnailInfo)picbox.Tag, picbox.RectangleToScreen(picbox.Bounds), picbox.PointToScreen(originPos))
            {
                BackColor = picbox.BackColor,
            };
            popup.Disposed += (s, e) =>
            {
                // 乗っ取った画像は、サムネイル枠に戻せるなら戻し、戻せないなら破棄する
                if (!picbox.IsDisposed)
                    picbox.Image = thumbnail;
                else
                    thumbnail.Dispose();
            };

            popup.Show();
            picbox.Update();
        }
Example #12
0
        protected ThumbnailZoomWindow(MemoryImage thumbnail, ThumbnailInfo thumbInfo, Rectangle startupBounds, Point originPos)
        {
            this.startupBounds = startupBounds;
            this.originPos = originPos;

            using (ControlTransaction.Layout(this, false))
            {
                this.DoubleBuffered = true;

                this.TopMost = true;
                this.FormBorderStyle = FormBorderStyle.None;
                this.ShowInTaskbar = false;

                this.StartPosition = FormStartPosition.Manual;
                this.Bounds = startupBounds;

                this.Capture = true;

                this.MouseMove += ThumbnailZoomWindow_MouseMove;
                this.MouseUp += ThumbnailZoomWindow_MouseUp;

                var picbox = new OTPictureBox()
                {
                    Name = "picbox",
                    Image = thumbnail,
                    Tag = thumbInfo,
                    SizeMode = PictureBoxSizeMode.Zoom,
                    WaitOnLoad = false,
                    Dock = DockStyle.Fill,
                };
                this.Controls.Add(picbox);

                picbox.MouseMove += ThumbnailZoomWindow_MouseMove;
                picbox.MouseUp += ThumbnailZoomWindow_MouseUp;
            }
        }
Example #13
0
        private async Task SetThumbnailImageAsync(OTPictureBox picbox, ThumbnailInfo thumbInfo,
            CancellationToken cancelToken)
        {
            try
            {
                picbox.ShowInitialImage();

                picbox.MouseDown += this.pictureBox_MouseDown;
                picbox.MouseUp += this.pictureBox_MouseUp;

                picbox.Image = await thumbInfo.LoadThumbnailImageAsync(cancelToken);

                cancelToken.ThrowIfCancellationRequested();

                picbox.MouseMove += this.pictureBox_MouseMove;

                if (this.ThumbnailLoadCompleted != null)
                    this.ThumbnailLoadCompleted(picbox, EventArgs.Empty);
            }
            catch (Exception)
            {
                picbox.ShowErrorImage();
                try
                {
                    throw;
                }
                catch (HttpRequestException) { }
                catch (InvalidImageException) { }
                catch (TaskCanceledException) { }
                catch (WebException) { }
            }
        }
Example #14
0
 private async Task SetThumbnailImageAsync(OTPictureBox picbox, ThumbnailInfo thumbInfo,
     CancellationToken cancelToken)
 {
     try
     {
         picbox.ShowInitialImage();
         picbox.Image = await thumbInfo.LoadThumbnailImageAsync(cancelToken);
     }
     catch (Exception)
     {
         picbox.ShowErrorImage();
         try
         {
             throw;
         }
         catch (HttpRequestException) { }
         catch (InvalidImageException) { }
         catch (TaskCanceledException) { }
     }
 }