📚 Hub Books: Онлайн-чтение книгРазная литератураИнтернет-журнал "Домашняя лаборатория", 2007 №9 - Журнал «Домашняя лаборатория»

Интернет-журнал "Домашняя лаборатория", 2007 №9 - Журнал «Домашняя лаборатория»

Шрифт:

-
+

Интервал:

-
+
1 ... 401 402 403 404 405 406 407 408 409 ... 415
Перейти на страницу:

              }

              void moveTop()

              {

                    //Move top

                    current.Show(graphic, clearPen, clearBrush)

                    current.Move(0,-20);

                    current.Show(graphic, pen, brush);

              }

              private void menuItem22_Click(object sender, System.EventArgs e)

              {

                    moveDown ();

              }

              void moveDown()

              {

                    //Move down

                    current.Show(graphic, clearPen, clearBrush)

                    current.Move(0, 20);

                    current.Show(graphic, pen, brush);

              }

              private void menuItem23_Click(object sender, System.EventArgs e)

              {

                    //choose color

                    ColorDialog dialog = new ColorDialog();

                    if (dialog.ShowDialog() ==DialogResult.OK) color =dialog.Color;

                    pen = new Pen (color); brush = new SolidBrush(color);

              }

              private void menuItem24_Click(object sender, System.EventArgs e)

              {

                    //Red color

                    color =Color.Red;

                    pen = new Pen(color); brush = new SolidBrush(color);

              }

              private void menuItem25_Click(object sender, System.EventArgs e)

              {

                    //Green color

                    color =Color.Green;

                    pen = new Pen(color); brush = new SolidBrush(color);

              }

              private void menuItem26_Click(object sender, System.EventArgs e)

              {

                    //Blue color

                    color =Color.Blue;

                    pen = new Pen(color); brush = new SolidBrush(color);

              }

              private void menuItem27_Click(object sender, System.EventArgs e)

              {

                    //Black color

                    color =Color.Black;

                    pen = new Pen (color); brush = new SolidBrush(color);

              }

              private void menuItem28_Click(object sender, System.EventArgs e)

              {

                    //Gold color

                    color =Color.Gold;

                    pen = new Pen(color); brush = new SolidBrush(color);

              }

              private void menuItem29_Click(object sender, System.EventArgs e)

              {

                    //put_left: добавление фигуры в список

                    listFigure.put_left(current);

              }

              private void menuItem30_Click(object sender, System.EventArgs e)

              {

                    //put_right: добавление фигуры в список

                    listFigure.put_right(current);

              }

              private void menuItem31_Click(object sender, System.EventArgs e)

              {

                   //remove: удаление фигуры из списка

                   if(!listFigure.empty()) listFigure.remove ();

              }

              private void menuItem32_Click (object sender, System.EventArgs e)

              {

                    goPrev();

              }

              void goPrev()

              {

                    //go_prev: передвинуть курсор влево

                    if(!(listFigure.Index == 1))

                    {

                         listFigure.go_prev();

                         current = listFigure.item();

                     }

               }

               private void menuItem33_Click(object sender, System.EventArgs e)

               {

                      goNext();

               }

               void goNext()

               {

                     //go_next: передвинуть курсор вправо

                     if(!(listFigure.Index == listFigure.Count))

                     {

                          listFigure.go_next();

                          current = listFigure.item();

                     }

               }

               private void menuItem34_Click(object sender, System.EventArgs e)

               {

                     //go_first

                     listFigure.start();

                     if(!listFigure.empty())

                           current = listFigure.item();

               }

               private void menuItem35_Click(object sender, System.EventArgs e)

               {

                     //go_last

                     listFigure.finish();

                     if(!listFigure.empty())

                           current = listFigure.item();

                }

                private void menuItem15_Click(object sender, System.EventArgs e)

                {

                     showList ();

                }

                void showList ()

                {

                     //Show List

                     listFigure.start();

                     while(listFigure.Index <= listFigure.Count)

                     {

                           current = listFigure.item();

                           current.Show(graphic,pen,brush);

                           listFigure.go_next();

                     }

                     listFigure.finish ();

                }

                private void menuItem16_Click(object sender,

                     System.EventArgs e)

                {

                     clearList ();

                }

                void clearList ()

                {

                     //Clear List

                     listFigure.start();

                     while(!listFigure.empty())

                     {

                          current = listFigure.item();

                          current.Show(graphic,clearPen,clearBrush);

                          listFigure.remove ();

                     }

                }

                private void Form1_MouseMove (object sender,

                     System.Windows.Forms.MouseEventArgs e)

                {

                     if((current!= null) && current.dragged_figure)

                     {

                          current.Show(graphic,clearPen,clearBrush);

                          Point pt = new Point(e.X, e.Y);

                          current.center_figure = pt;

                          current.Show(graphic,pen,brush);

                     }

                }

                private void Form1_MouseUp(object sender,

                     System.Windows.Forms.MouseEventArgs e)

                {

                     current.dragged_figure = false;

                }

                private void Form1_MouseDown(object sender,

                     System.Windows.Forms.MouseEventArgs e)

                {

                     Point mousePoint = new Point (e.X, e.Y);

                     Rectangle figureRect = current.Region_Capture();

                     if ((current!= null) &&

                        (figureRect.Contains(mousePoint)))

                        current.dragged_figure = true;

                }

                protected override void

                     OnPaint(System.Windows.Forms.PaintEventArgs e)

                {

                     //show current figure

                      current.Show(graphic, pen, brush);

                }

                private void toolBar1_ButtonClick(object sender,

                      System.Windows.Forms.ToolBarButtonClickEventArgs e)

                {

                      int buttonNumber =

                          toolBar1.Buttons.IndexOf(e.Button);

                      switch (buttonNumber)

                      {

                           case 0:

                                 createEllipse (); break;

                           case 1:

                                 createCircle(); break;

                           case 2:

                                 createLittleCircle(); break;

                           case 3:

                                 createRectangle(); break;

                           case 4:

                                 createSquare(); break;

                           case 5:

                                 createPerson (); break;

                           case 6:

                                 showCurrent (); break;

                           case 7:

                                 clearCurrent (); break;

                           case 8:

                                 showList (); break;

                           case 9:

                                 clearList (); break;

                           case 10:

                                 incScale (); break;

                           case 11:

                                 decScale (); break;

                           case 12:

                                 moveLeft (); break;

                           case 13:

                                 moveRight (); break;

                           case 14:

                                 moveTop (); break;

                           case 15:

                                 moveDown (); break;

                           case 16:

                                 goNext(); break;

                           case 17:

                                 goPrev (); break;

                     }

              }

      }

}

Команд меню и кнопок в нашем интерфейсе много, поэтому много и обработчиков событий, что приводит к разбуханию кода. Но каждый из обработчиков событий довольно прост. Ограничусь кратким описанием главного меню:

• команды пункта главного меню Create позволяют создавать геометрические фигуры разных классов;

• команды пункта главного меню Show позволяют

1 ... 401 402 403 404 405 406 407 408 409 ... 415
Перейти на страницу:

Комментарии

Обратите внимание, что комментарий должен быть не короче 20 символов. Покажите уважение к себе и другим пользователям!

Никто еще не прокомментировал. Хотите быть первым, кто выскажется?