Exemple #1
0
        private void SetSelectionRect()
        {
            int x, y;
            int width, height;

            x = selectionStart.X > selectionEnd.X ? selectionEnd.X : selectionStart.X;
            y = selectionStart.Y > selectionEnd.Y ? selectionEnd.Y : selectionStart.Y;

            width  = selectionStart.X > selectionEnd.X ? selectionStart.X - selectionEnd.X : selectionEnd.X - selectionStart.X;
            height = selectionStart.Y > selectionEnd.Y ? selectionStart.Y - selectionEnd.Y : selectionEnd.Y - selectionStart.Y;

            selection = new Rectangle(x, y, width, height);


            Console.WriteLine(selection.Location);
            //-------------------------------------------------------------------------------------------------------------------

            foreach (Control item in this.Controls)
            {
                if (selection.Contains(item.Bounds))
                {
                    item.BackColor = Color.Yellow;
                    SelectedControls.Add(item);
                    PanelObjectHistory hx = new PanelObjectHistory(item.Left, item.Top, item);
                    hx.targetPanel.Location = item.Location;

                    _undoList.Add(hx);
                    _objHxList.Add(hx);
                    //Write_Json();
                }
                RefreshHxBox();
            }
        }
Exemple #2
0
        //read undo
        public void Read_Json()
        {
            List_UndoLocation.Clear();

            using (FileStream fs = new FileStream("Undo_Json.json", FileMode.Open))
                using (StreamReader file = new StreamReader(fs))
                    using (JsonReader w = new JsonTextReader(file))
                    {
                        JsonSerializer  Position  = new JsonSerializer();
                        List <Position> positions = JsonConvert.DeserializeObject <List <Position> >(file.ReadToEnd());
                        //Console.WriteLine(positions[0].X);
                        //----------------------------------------------------------------------------------------
                        for (int i = 0; i <= positions.Count - 1; i++)
                        {
                            Position po         = new Position();
                            int      myTag      = positions[i].T;
                            int      Location_x = positions[i].X;
                            int      Location_y = positions[i].Y;

                            foreach (Control item in this.Controls)
                            {
                                PanelObjectHistory hx = new PanelObjectHistory(Location_x, Location_y, item);
                                if (myTag == (int)item.Tag)
                                {
                                    _undoList.Add(hx);
                                }
                            }
                        }
                    }
        }
Exemple #3
0
        private void UserControl1_MouseDown(object sender, MouseEventArgs e)
        {
            MouseDownLocation = e.Location;
            Control item = (Control)sender;

            //case press ctrl
            if (Control.ModifierKeys == Keys.Control || e.Button == MouseButtons.Left)
            {
                L_x            = e.X;
                L_y            = e.Y;
                item.BackColor = Color.Yellow;

                if (!SelectedControls.Contains(item))
                {
                    SelectedControls.Add(item);
                    PanelObjectHistory hx = new PanelObjectHistory(item.Left, item.Top, item);
                    hx.targetPanel.Location = item.Location;

                    _undoList.Add(hx);
                    _objHxList.Add(hx);
                    //Write_Json();
                }
                RefreshHxBox();
            }
            //case don't press ctrl
            else if (e.Button == MouseButtons.Left)
            {
                item.BackColor = Color.Yellow;
                L_x            = e.X;
                L_y            = e.Y;

                //----------------------------------------------------------------------------
                if (!SelectedControls.Contains(item))
                {
                    SelectedControls.Add(item);
                    PanelObjectHistory hx = new PanelObjectHistory(item.Left, item.Top, item);
                    hx.targetPanel.Location = item.Location;

                    _undoList.Add(hx);
                    _objHxList.Add(hx);
                    //Write_Json();
                }
                RefreshHxBox();
            }
        }
Exemple #4
0
        private void UserControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
            {
                Console.WriteLine("A");
                if (this.Controls.Count > 0)
                {
                    foreach (Control item in this.Controls)
                    {
                        item.BackColor = Color.Yellow;

                        if (!SelectedControls.Contains(item))
                        {
                            PanelObjectHistory hx = new PanelObjectHistory(item.Left, item.Top, item);
                            SelectedControls.Add(item);
                            hx.targetPanel.Location = item.Location;
                            _undoList.Add(hx);
                            //Write_Json();
                        }
                    }
                }
                this.Focus();
                //Console.WriteLine(SelectedControls.Count);
            }

            else if (e.KeyCode == Keys.Delete)
            {
                //Console.WriteLine(SelectedControls.Count);
                foreach (Control item in SelectedControls)
                {
                    Controls.Remove(item);
                }
                SelectedControls.Clear();
                this.Focus();
            }
            //Undo
            else if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
            {
                Console.WriteLine("Z");
                Console.WriteLine("history ={0}", _undoList.Count);

                if (_undoList.Count > 0)
                {
                    for (int i = 0; i < _selectCount[_selectCount.Count - 1]; i++)
                    {
                        Console.WriteLine("Undo" + _undoList[_undoList.Count - 1].targetPanel.Location);
                        Control thisPo = _undoList[_undoList.Count - 1].targetPanel;
                        //----------------------------------------------------------------------------------

                        PanelObjectHistory hx        = new PanelObjectHistory(thisPo.Left, thisPo.Top, thisPo);
                        PanelObjectHistory lastestHx = _undoList[_undoList.Count - 1];
                        _redoList.Add(hx);
                        lastestHx.targetPanel.Location = new Point(lastestHx.x, lastestHx.y);
                        _undoList.RemoveAt(_undoList.Count - 1);
                        //-----------------------------------------------------------------------------------

                        Console.WriteLine("Redo" + _redoList[_redoList.Count - 1].targetPanel.Location);
                    }
                    _selectCount_redo.Add(_selectCount[_selectCount.Count - 1]);
                    _selectCount.RemoveAt(_selectCount.Count - 1);
                }

                //RefreshHxBox();
            }
            //Redo
            else if (e.KeyCode == Keys.Y && e.Modifiers == Keys.Control)
            {
                Console.WriteLine("Y");
                Console.WriteLine("history ={0}", _redoList.Count);
                if (_redoList.Count > 0)
                {
                    for (int i = 0; i < _selectCount_redo[_selectCount_redo.Count - 1]; i++)
                    {
                        Console.WriteLine("Redo" + _redoList[_redoList.Count - 1].targetPanel.Location);
                        Control thisPo = _redoList[_redoList.Count - 1].targetPanel;
                        //--------------------------------------------------------------------------------------

                        PanelObjectHistory hx        = new PanelObjectHistory(thisPo.Left, thisPo.Top, thisPo);
                        PanelObjectHistory lastestHx = _redoList[_redoList.Count - 1];
                        //_undoList.RemoveAt(_undoList.Count - 1);
                        _undoList.Add(hx);
                        ////lastestHx.targetPanel.Location = new Point(lastestHx.x, lastestHx.y);
                        lastestHx.targetPanel.Location = new Point(lastestHx.x, lastestHx.y);
                        //_redoList.Add(lastestHx);
                        _redoList.RemoveAt(_redoList.Count - 1);
                        //---------------------------------------------------------------------------------------

                        Console.WriteLine("Undo" + _undoList[_undoList.Count - 1].targetPanel.Location);
                    }
                    _selectCount.Add(_selectCount_redo[_selectCount_redo.Count - 1]);
                    _selectCount_redo.RemoveAt(_selectCount_redo.Count - 1);
                }
            }
        }