示例#1
0
 public Form1()
 {
     InitializeComponent();
     rectangles     = new RectangleDoc();
     DoubleBuffered = true;
     currentColor   = Color.Blue;
 }
示例#2
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         RectangleDoc.DeleteSelected();
         Invalidate(true);
     }
 }
示例#3
0
 private void newToolStripButton_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to start a new game?", "New game",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         RectangleDoc = new RectangleDoc(Color);
         Filename     = string.Empty;
         Invalidate(true);
     }
 }
示例#4
0
 public Form1()
 {
     InitializeComponent();
     Color               = Color.Blue;
     RectangleDoc        = new RectangleDoc(Color);
     Filename            = string.Empty;
     _teme1              = _teme2 = Point.Empty;
     _drawingContour     = true;
     this.DoubleBuffered = true;
 }
示例#5
0
        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (selectAllToolStripMenuItem.Text == "Select &All")
            {
                RectangleDoc.SelectAll(true);
                selectAllToolStripMenuItem.Text = "Unselect &All";
            }
            else
            {
                RectangleDoc.SelectAll(false);
                selectAllToolStripMenuItem.Text = "Select &All";
            }

            Invalidate();
        }
示例#6
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                RectangleDoc.Hit(e.X, e.Y);
                Invalidate();
            }
            else if (e.Button == MouseButtons.Left)
            {
                if (_teme1 == Point.Empty)
                {
                    _teme1          = new Point(e.X, e.Y);
                    _drawingContour = true;
                }
                else
                {
                    _teme2 = e.Location;
                    int   width  = Math.Abs(_teme2.X - _teme1.X);
                    int   height = Math.Abs(_teme2.Y - _teme1.Y);
                    Point teme;

                    if (_teme2.X < _teme1.X && _teme2.Y < _teme1.Y)
                    {
                        teme = _teme2;
                    }
                    else if (_teme2.X > _teme1.X && _teme2.Y < _teme1.Y)
                    {
                        teme = new Point(_teme1.X, _teme2.Y);
                    }
                    else if (_teme2.X < _teme1.X && _teme2.Y > _teme1.Y)
                    {
                        teme = new Point(_teme2.X, _teme1.Y);
                    }
                    else
                    {
                        teme = _teme1;
                    }

                    RectangleDoc.AddRectangle(teme, width, height, Color);
                    _drawingContour = false;
                    _teme1          = Point.Empty;
                    Invalidate(true);
                }
            }
        }
示例#7
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.White);
            RectangleDoc.Draw(e.Graphics);

            if (_drawingContour)
            {
                var pen = new Pen(Color.Gray, 2);
                pen.DashStyle = DashStyle.Dot;

                int width  = Math.Abs(_teme2.X - _teme1.X);
                int height = Math.Abs(_teme2.Y - _teme1.Y);
                if (_teme2.X < _teme1.X && _teme2.Y < _teme1.Y)
                {
                    e.Graphics.DrawRectangle(pen, _teme2.X, _teme2.Y, width, height);
                }
                else if (_teme2.X > _teme1.X && _teme2.Y < _teme1.Y)
                {
                    e.Graphics.DrawRectangle(pen, _teme1.X, _teme2.Y, width, height);
                }
                else if (_teme2.X < _teme1.X && _teme2.Y > _teme1.Y)
                {
                    e.Graphics.DrawRectangle(pen, _teme2.X, _teme1.Y, width, height);
                }
                else
                {
                    e.Graphics.DrawRectangle(pen, _teme1.X, _teme1.Y, width, height);
                }
                pen.Dispose();
            }

            if (Filename != string.Empty)
            {
                this.Text = $"Rectangles | {Filename.Substring(Filename.LastIndexOf(@"\") + 1)}";
            }
            else
            {
                this.Text = "Rectangles";
            }
        }
示例#8
0
 private void cutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     RectangleDoc.DeleteSelected();
     Invalidate(true);
 }
示例#9
0
 private void statusStrip1_Paint(object sender, PaintEventArgs e)
 {
     lblRectangles.Text = $"Rectangles: {RectangleDoc.RectanglesCount()}";
 }