コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (_isCapturing && _snapshot != null)
            {
                //Draw the screenshot scaled
                e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                var snapBounds = new Rectangle
                {
                    Width  = _snapshot.Width * Zoom,
                    Height = _snapshot.Height * Zoom
                };
                e.Graphics.DrawImage(_snapshot, snapBounds);
                e.Graphics.InterpolationMode = InterpolationMode.Default;

                //Draw the square around the middle pixel
                var pt = GetSnapShotSelectedPixelLocation();
                LayoutAndPaintUtils.ScalePoint(ref pt, Zoom);
                var rectBounds = new Rectangle
                {
                    X      = pt.X - Zoom / 2,
                    Y      = pt.Y - Zoom / 2,
                    Width  = Zoom - 1,
                    Height = Zoom - 1
                };
                //In both cases, minus 1 is the typical GDI+ compensation
                //Use a black and white dotted pattern to ensure the
                //rectangle is visible with all background colors.
                using (var p = new Pen(Color.Black))
                {
                    p.DashStyle = DashStyle.Dot;
                    e.Graphics.DrawRectangle(p, rectBounds);
                    p.DashOffset = 1F;
                    p.Color      = Color.White;
                    e.Graphics.DrawRectangle(p, rectBounds);
                }
            }
            else
            {
                //Draw the placeholder icon
                var imgRect = ClientRectangle;
                imgRect.Inflate(-5, -5);
                e.Graphics.Clear(BackColor);
                e.Graphics.DrawImage(_icon, imgRect);
            }

            base.OnPaint(e);
        }
コード例 #2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Focus();

                _panning = true;

                //"Unscale" the provided point so that the panning follow the mouse.
                var scaleFactor = GetControlScaleFactor();
                var location    = e.Location;
                LayoutAndPaintUtils.ScalePoint(ref location, new SizeF(1 / scaleFactor, 1 / scaleFactor));

                _startingPoint = new Point(location.X - _movingPoint.X,
                                           location.Y - _movingPoint.Y);
            }

            base.OnMouseDown(e);
        }
コード例 #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_panning && PannablePictureBoxImage.Image != null && e.Button == MouseButtons.Left)
            {
                //"Unscale" the provided point so that the panning follow the mouse.
                var scaleFactor = GetControlScaleFactor();
                var location    = e.Location;
                LayoutAndPaintUtils.ScalePoint(ref location, new SizeF(1 / scaleFactor, 1 / scaleFactor));

                _movingPoint = new Point(location.X - _startingPoint.X,
                                         location.Y - _startingPoint.Y);

                if (_movingPoint.X + PannablePictureBoxImage.Width > _maxWidth * 2)
                {
                    _movingPoint.X = _maxWidth * 2 - PannablePictureBoxImage.Width;
                }
                if (_movingPoint.Y + PannablePictureBoxImage.Height > _maxHeight * 2)
                {
                    _movingPoint.Y = _maxHeight * 2 - PannablePictureBoxImage.Height;
                }
                if (_movingPoint.X < _minWidth * 2)
                {
                    _movingPoint.X = _minWidth * 2;
                }
                if (_movingPoint.Y < _minHeight * 2)
                {
                    _movingPoint.Y = _minHeight * 2;
                }

                PannablePictureBoxImage.X = _movingPoint.X;
                PannablePictureBoxImage.Y = _movingPoint.Y;

                Invalidate(ImageRectangle);
            }

            base.OnMouseMove(e);
        }