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; }
/// <summary> /// Заменят текущий холст /// </summary> /// <param name="canvas">Холст на который надо заменить текущий</param> private void ReplaceCanvas(MyCanvas canvas) { this.RemoveCanvas(); this._myCanvas = canvas; this.InitCanvas(); this._isDitry = false; }
} //Имя файла с которым идёт работа #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); }
/// <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; }
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); } }
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); } }
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); }