示例#1
0
        private event ColorChanged DrawingBackColorChanged;   //Инициируется при смена фона замкнутых фигур

        #endregion

        #region CTOR
        public frmMain()
        {
            InitializeComponent();

            //Добавление и инициализация холста

            this._myCanvas = new MyCanvas(Program.DEFAULT_DRAWING_WIDTH, Program.DEFAULT_DRAWING_HEIGHT);
            this.InitCanvas();

            this._drawingHelper = new DrawingHelper();

            //Свяжем кнопки с перечисленим инструментов

            this.tsbtnPen.Tag      = DrawingTools.PEN;
            this.tsbtnLine.Tag     = DrawingTools.LINE;
            this.tsbtnRectange.Tag = DrawingTools.RECTANGLE;
            this.tsbtnEllipse.Tag  = DrawingTools.ELLIPSE;

            //Установим начальные цвета элементов управления выбора цвета

            this.tsbtnForeColor.BackColor = this._foreColor;
            this.tsbtnBackColor.BackColor = this._backColor;

            //Текущий инструмент по-умолчанию

            this.tsbtnPen.Checked  = true;
            this._activeToolButton = this.tsbtnPen;
        }
示例#2
0
 /// <summary>
 /// Заменят текущий холст
 /// </summary>
 /// <param name="canvas">Холст на который надо заменить текущий</param>
 private void ReplaceCanvas(MyCanvas canvas)
 {
     this.RemoveCanvas();
     this._myCanvas = canvas;
     this.InitCanvas();
     this._isDitry = false;
 }
示例#3
0
        }                                       //Имя файла с которым идёт работа

        #endregion

        #region METHODS

        public MyCanvas CreateDrawing()
        {
            MyCanvas      result          = null;
            frmNewDrawing newDrawingDiaog = new frmNewDrawing();

            if (newDrawingDiaog.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }
            result        = new MyCanvas(newDrawingDiaog.DrawingWidth, newDrawingDiaog.DrawingHeight);
            this.FileName = null;

            return(result);
        }
示例#4
0
        /// <summary>
        /// Удалить холст из формы редактора, отписавшись от событий
        /// </summary>
        private void RemoveCanvas()
        {
            //Отписываемся от событий

            this.DrawingToolChanged      -= this._myCanvas.OnToolChanged;
            this.DrawingForeColorChanged -= this._myCanvas.OnForeColorChanged;
            this.DrawingBackColorChanged -= this._myCanvas.OnBackColorChanged;

            this._myCanvas.DrawingChanged            -= this.OnDrawingChanged;
            this._myCanvas.MousePositionCoordChanged -= this.OnMousePositionChanged;
            this._myCanvas.InverseProressChanged     -= this.OnInverseProgressChanged;
            this._myCanvas.BeginInverse -= this.OnBeginInverse;
            this._myCanvas.EndInverse   -= this.OnEndInverse;

            this.pnBase.Controls.Clear();
            this._myCanvas = null;
        }
示例#5
0
 private void openControl_Click(object sender, EventArgs e)
 {
     if (this.AskUserOfLosingChanges() == true)
     {
         return;
     }
     try
     {
         MyCanvas canvas = this._drawingHelper.OpenDrawing();
         if (canvas == null)
         {
             return;
         }
         this.ReplaceCanvas(canvas);
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Error opening file\n{0}", ex.Message);
         MessageBox.Show("Can't open file", Program.APP_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
示例#6
0
 public bool SaveDrawing(MyCanvas canvas, bool isSaveAs)
 {
     if (isSaveAs == true || this.FileName == null)
     {
         using (SaveFileDialog saveDialog = new SaveFileDialog()
         {
             AddExtension = true, DefaultExt = ".bmp", InitialDirectory = Application.StartupPath, Filter = this._saveFilter
         })
         {
             if (saveDialog.ShowDialog() != DialogResult.OK)
             {
                 return(false);
             }
             this.FileName = saveDialog.FileName;
         }
     }
     using (Bitmap currentDrawing = canvas.Drawing)
     {
         string extention = Path.GetExtension(this.FileName);
         currentDrawing.Save(this.FileName, this._extentionFormat[extention]);
         return(true);
     }
 }
示例#7
0
        public MyCanvas OpenDrawing()
        {
            MyCanvas result;
            string   tmpFileName;

            using (OpenFileDialog openDialog = new OpenFileDialog()
            {
                InitialDirectory = Application.StartupPath, Filter = this._openFilter
            })
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }
                tmpFileName = openDialog.FileName;
            }
            using (Image openedImage = Image.FromFile(tmpFileName))
            {
                result = new MyCanvas(openedImage);
            }
            this.FileName = tmpFileName;
            return(result);
        }