private void размерХолстаToolStripMenuItem_Click(object sender, EventArgs e) { CanvasSize cs = new CanvasSize(); cs.CanvasWidth = ((Canvas)ActiveMdiChild).CanvasWidth; cs.CanvasHeight = ((Canvas)ActiveMdiChild).CanvasHeight; if (cs.ShowDialog() == DialogResult.OK) { ((Canvas)ActiveMdiChild).CanvasWidth = cs.CanvasWidth; ((Canvas)ActiveMdiChild).CanvasHeight = cs.CanvasHeight; } }
private void ChangeSizeButton_Click(object sender, EventArgs e) { CanvasSize form = new CanvasSize(ActiveMdiChild.Size.Width, ActiveMdiChild.Size.Height); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ActiveMdiChild.Size = new Size(form.SizeWidth, form.SizeHeight); (ActiveMdiChild.Controls[0] as PictureBox).Size = new Size(form.SizeWidth, form.SizeHeight); Bitmap image = new Bitmap(form.SizeWidth, form.SizeHeight); using (var graphics = Graphics.FromImage(image)) { graphics.Clear(Color.White); //graphics.DrawImage((ActiveMdiChild.Controls[0] as PictureBox).Image, // new Rectangle(new Point(0, 0), new Size((ActiveMdiChild.Controls[0] as PictureBox).Image.Width, // (ActiveMdiChild.Controls[0] as PictureBox).Image.Height))); } (ActiveMdiChild.Controls[0] as PictureBox).Image = image; } }
} //выход #endregion Файл #region исунок private void размерХолстаToolStripMenuItem_Click(object sender, EventArgs e) //размер холста { try { CanvasSize cs = new CanvasSize(ActiveMdiChild.Size.Width, ActiveMdiChild.Size.Height); if (cs.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ActiveMdiChild.Size = new Size(cs.SizeWidth, cs.SizeHeight); (ActiveMdiChild.Controls[0] as PictureBox).Size = new Size(cs.SizeWidth, cs.SizeHeight); Bitmap image = new Bitmap(cs.SizeWidth, cs.SizeHeight); using (var graphics = Graphics.FromImage(image)) { graphics.Clear(Color.White); graphics.DrawImage((ActiveMdiChild.Controls[0] as PictureBox).Image, new Rectangle(new Point(0, 0), new Size((ActiveMdiChild.Controls[0] as PictureBox).Image.Width, (ActiveMdiChild.Controls[0] as PictureBox).Image.Height))); } (ActiveMdiChild.Controls[0] as PictureBox).Image = image; } } catch (Exception) { MessageBox.Show("Сначала создайте холст"); } }