Esempio n. 1
0
        private void SmoothRotate(BackgroundWorker worker, DoWorkEventArgs e)
        {
            var angle        = int.Parse(AngleTextBox.Text);
            var centerX      = (_square.BottomLeft.X + _square.UpperRight.X) / 2;
            var centerY      = (_square.BottomLeft.Y + _square.UpperRight.Y) / 2;
            var centerPoint  = new PointF(centerX, centerY);
            var resultSquare = new Square();

            _squares.Add(_square);
            for (float i = 1; i <= angle; ++i)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                resultSquare = SquareRotator.Rotate(_square, centerPoint, (int)i);
                _squares.Add(resultSquare);
                PictureBox.Image = SquarePainter.Paint(_squares, _pen, PictureBox.Width, PictureBox.Height);
                _squares.RemoveAt(_squares.Count - 1);
                worker.ReportProgress((int)(i / angle * 100));
                Thread.Sleep(Convert.ToInt32(e.Argument));
            }

            _squares.Add(resultSquare);
            _square = resultSquare;
        }
Esempio n. 2
0
        private void PaintSquare()
        {
            if (UpperLeftCornerXTextBox.Text.Length == 0)
            {
                UpperLeftCornerXTextBox.Text = "0";
            }

            if (UpperLeftCornerYTextBox.Text.Length == 0)
            {
                UpperLeftCornerYTextBox.Text = "0";
            }

            if (SideTextBox.Text.Length == 0)
            {
                SideTextBox.Text = "0";
            }

            RotateButton.Enabled = true;
            _squares.Add(_square);
            _image = SquarePainter.Paint(_squares, _pen, PictureBox.Width, PictureBox.Height);
            _squares.RemoveAt(_squares.Count - 1);
            PictureBox.Image = _image;
        }