protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            //Simply changes the default value. Users will have the oppurtunity to change
            //it when the event is raised.
            e.DrawDefault = true;

            base.OnDrawColumnHeader(e);

            //Implements the flat header style
            if (e.DrawDefault && HeaderAppearance == ListViewHeaderAppearance.Flat)
            {
                using (var b = new SolidBrush(FlatHeaderBackColor))
                    e.Graphics.FillRectangle(b, e.Bounds);

                TextFormatFlags flags =
                    TextFormatFlags.VerticalCenter |
                    TextFormatFlags.EndEllipsis |
                    LayoutAndPaintUtils.ConvertToTextFormatFlags(e.Header.TextAlign); //Header.TextAlign is already Rtl translated

                TextRenderer.DrawText(e.Graphics, e.Header.Text, Font, e.Bounds, FlatHeaderForeColor, flags);

                //Drawing handled, so tell the system to draw nothing
                e.DrawDefault = false;
            }
        }
Example #2
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);
        }
        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);
        }
        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);
        }
Example #5
0
 private void InvalidateNonClient()
 {
     LayoutAndPaintUtils.InvalidateNonClient(this);
 }
Example #6
0
        /// <summary>
        /// Returns a <see cref="Point"/> relative to the snapshot bounds
        /// where the color will be obtained.
        /// </summary>
        private Point GetSnapShotSelectedPixelLocation()
        {
            var snapBounds = new Rectangle(Point.Empty, _snapshot.Size);

            return(LayoutAndPaintUtils.GetRectangleCenter(snapBounds));
        }