コード例 #1
0
ファイル: ImageCropper.cs プロジェクト: sujeffreyl/libpalaso
        protected override void OnPaint(PaintEventArgs e)
        {
            if (_croppingImage == null || _sourceImageArea.Width == 0)
            {
                return;
            }

            try
            {
                e.Graphics.FillRectangle(Brushes.Gray, ClientRectangle);
                e.Graphics.DrawImage(
                    _croppingImage,
                    _sourceImageArea,
                    new Rectangle(                     // Source
                        0, 0,
                        _croppingImage.Width, _croppingImage.Height),
                    GraphicsUnit.Pixel);

                using (Brush brush = new Pen(Color.FromArgb(150, Color.LightBlue)).Brush)
                {
                    e.Graphics.FillRectangle(brush, _leftGrip.InnerEdge, _bottomGrip.InnerEdge,
                                             _rightGrip.InnerEdge - _leftGrip.InnerEdge
                                             /*this avoids overlapp which makes it twice as light*/
                                             , Height - _bottomGrip.InnerEdge);
                    e.Graphics.FillRectangle(brush, _leftGrip.InnerEdge, 0, _rightGrip.InnerEdge - _leftGrip.InnerEdge,
                                             _topGrip.InnerEdge);
                    e.Graphics.FillRectangle(brush, 0, 0, _leftGrip.InnerEdge, Height);
                    e.Graphics.FillRectangle(brush, _rightGrip.InnerEdge, 0, Width - _rightGrip.InnerEdge, Height);
                }
                e.Graphics.DrawRectangle(Pens.LightBlue, _leftGrip.Right, _topGrip.Bottom,
                                         _rightGrip.Left - _leftGrip.Right, _bottomGrip.Top - _topGrip.Bottom);

                _bottomGrip.Paint(e.Graphics);
                _topGrip.Paint(e.Graphics);
                _leftGrip.Paint(e.Graphics);
                _rightGrip.Paint(e.Graphics);
            }
            catch (Exception error)
            {
                Debug.Fail(error.Message);
                // UserControl does not have UseCompatibleTextRendering.
                TextRenderer.DrawText(e.Graphics, "Error in OnPaint()", SystemFonts.DefaultFont, new Point(20, 20), Color.Red);
                //swallow in release build
            }
        }