private void FileNew_Click(object sender, EventArgs e) { // Tạo File vẽ mới - Hỏi Save File trước khi thực hiện // Tạo DrawBox mới: tô màu nền trắng, xóa list Undo, Redo và FilePath var AskForSave = MessageBox.Show(@"Do you want to Save this Image?", @"Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (AskForSave == DialogResult.Cancel) { return; } else if (AskForSave == DialogResult.Yes) { FileSave_Click(null, null); } drawBox.Size = new Size(700, 300); drawBox.Image = new Bitmap(drawBox.Width, drawBox.Height); drawBox.ClearUndoRedo(); Region region = new Region(new Rectangle(0, 0, drawBox.Width, drawBox.Height)); Graphics _g = Graphics.FromImage(drawBox.Image); _g.FillRegion(new SolidBrush(Color.White), region); FilePath = null; this.Text = "MyPaint"; }
//Constructor tạo DrawBox public DrawBox() { UndoList = new Stack <Bitmap>(); RedoList = new Stack <Bitmap>(); Size = new Size(700, 300); Image = new Bitmap(Width, Height); Region region = new Region(new Rectangle(0, 0, Width, Height)); _g = Graphics.FromImage(Image); _g.FillRegion(new SolidBrush(Color.White), region); }