Exemplo n.º 1
0
        private void imageBox_MouseClick(object sender, MouseEventArgs e)
        {
            try {
                switch (typeEdit)
                {
                    case "drawText":
                        timer1.Enabled = false;
                        listGObject.Add(drawText(e.X, e.Y, stf.text, blackPen ));
                        drawCollection(listGObject, blackPen);
                       // typeEdit = null;
                        break;

                    case "drawRetangle":
                        timer1.Enabled = false;
                        g.Clear(foneColor);
                        listGObject.Add(drawRetangle(e.X, e.Y, blackPen));
                        drawCollection(listGObject, blackPen); // рисуем фигуры

                        typeEdit = null; // фигура поставлена
                        break;

                    case "edit":
                        if (checkBox1.Checked) deleteGraphicsPath(searchGpaphicsPath(listGObject, e.X, e.Y));
                        else
                        {
                            gObject = searchGpaphicsPath(listGObject, e.X, e.Y);
                            listGObject.Remove(gObject);
                            lenght = gObject.lenght();
                            height = gObject.height();
                            stf.text = gObject.text;
                            typeEdit = "editMove";
                            timer1.Enabled = true;
                        }
                        break;

                    case "editMove":
                        firstStart = true;
                        switch (gObject.type)
                        {
                            case "line":
                                gObject.setLine(bx, by, bx + lenght, by + height);
                                g.DrawPath(clearPen, gObject.gPath);
                                gObject.setLine(e.X, e.Y, e.X + lenght, e.Y + height);
                                bx = e.X;
                                by = e.Y;
                                g.DrawPath(blackPen, gObject.gPath);
                                listGObject.Add(gObject);
                                typeEdit = "edit";
                                timerStop = true;
                                break;

                            case "retangle":
                                gObject.setRetangle(bx, by, gObject.x2, gObject.y2);
                                g.DrawPath(clearPen, gObject.gPath);
                                gObject.setRetangle(e.X, e.Y, gObject.x2, gObject.y2);
                                bx = e.X;
                                by = e.Y;
                                g.DrawPath(blackPen, gObject.gPath);
                                listGObject.Add(gObject);
                                typeEdit = "edit";
                                timerStop = true;
                                break;

                            case "text":
                                drawText(bx, by, stf.text, clearPen);
                               listGObject.Add(drawText(e.X, e.Y, stf.text, clearPen));
                                typeEdit = "edit";
                                timerStop = true;
                                break;
                            case "lineAndText":
                                drawLineAndText(bx, by, bx + lenght, by + height, stf.text, clearPen);
                                listGObject.Add(drawLineAndText(e.X, e.Y, x1 + lenght, by + height, stf.text, blackPen));
                                typeEdit = "edit";
                                timerStop = true;
                                break;

                        }
                        break;
                    default:
                        return;
                }
            }
            catch (System.ArgumentNullException) { typeEdit = "edit"; }
            catch (System.NullReferenceException) { typeEdit = "edit"; }
        }
        private void imageBox_MouseClick(object sender, MouseEventArgs e)
        {
            try {
                if (typeEdit == 5)
                {
                    if (gObject.type == "line")
                    {
                        gObject.setLine(bx, by, bx + lenght, by + height);
                        g.DrawPath(clearPen, gObject.gPath);
                        gObject.setLine(e.X, e.Y, e.X + lenght, e.Y + height);
                        bx = e.X;
                        by = e.Y;
                        g.DrawPath(blackPen, gObject.gPath);
                        listGObject.Add(gObject);
                        typeEdit = 0;
                        timer1.Enabled = false;
                    }
                    if (gObject.type == "retangle")
                    {
                        gObject.setRetangle(bx, by, gObject.x2, gObject.y2);
                        g.DrawPath(clearPen, gObject.gPath);
                        gObject.setRetangle(e.X, e.Y, gObject.x2, gObject.y2);
                        bx = e.X;
                        by = e.Y;
                        g.DrawPath(blackPen, gObject.gPath);
                        listGObject.Add(gObject);
                        typeEdit = 0;
                        timer1.Enabled = false;
                    }

                }

                if (typeEdit == 3)
                {
                    if (checkBox1.Checked) deleteGraphicsPath(searchGpaphicsPath(listGObject, e.X, e.Y));
                    else
                    {
                        gObject = searchGpaphicsPath(listGObject, e.X, e.Y);
                        listGObject.Remove(gObject);
                        lenght = gObject.lenght();
                        height = gObject.height();
                        typeEdit = 5;
                        timer1.Enabled = true;
                    }

                    //  MessageBox.Show("тычок:  " + e.X + "-" + e.Y );
                }

            }
            catch (System.ArgumentNullException) { typeEdit = 3; }
            catch (System.NullReferenceException) { typeEdit = 3; }

            if (typeEdit == 2) // если фигура выбрана
                {

                    timer1.Enabled = false;
                    g.Clear(foneColor);
                    listGObject.Add(drawRetangle(e.X, e.Y, blackPen));
                    drawCollection(listGObject, blackPen); // рисуем фигуры

                    typeEdit = 0; // фигура поставлена
                }
        }