Вы изучаете сборку графической программы, написанной на Delphi. При нажатии на кнопку btnCrop пользователь может вырезать часть выделенного изображения: procedure frmMain.btnCrop_Click(sender: TObject; e: EventArgs);var rectangle2: Rectangle; rectangle1: Rectangle; bitmap1: Bitmap; graphics1: Graphics; exception1: Exception;begin try if (self.cropWidth < 1) then MessageBox.Show(' Выделите область, перемещая курсор! ', ' Нет области для выделения! ', MessageBoxButtons.OK, MessageBoxIcon.Hand) else begin rectangle2 := Rectangle.Create(self.cropX, self.cropY, self.cropWidth, self.cropHeight); rectangle1 := rectangle2; bitmap1 := Bitmap.Create(self.p.Image, self.p.Width, self.p.Height); self.cropBitmap := Bitmap.Create(self.cropWidth, self.cropHeight); graphics1 := Graphics.FromImage(self.cropBitmap); graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel); self.pbCrop.Image := self.cropBitmap end except on exception2: Exception do begin ProjectData.SetProjectError(exception2); exception1 := exception2; MessageBox.Show(exception1.Message, ' Ошибка ', MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError end endend;
Выберите правильный перевод этого фрагмента кода на языке C#:
(Отметьте один правильный вариант ответа.)
Варианты ответа
private void btnCrop_Click(object sender, EventArgs e){ try { if (this.cropWidth < 1) { MessageBox.Show("Выделите область, перемещая курсор!", " Нет области для выделения!", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { Rectangle rectangle2 = new Rectangle(this.cropX, this.cropY, this.cropWidth, this.cropHeight); Rectangle rectangle1 = rectangle2; Bitmap bitmap1 = new Bitmap(this.p.Image, this.p.Width, this.p.Height); this.cropBitmap = bitmap1(this.p.Image, this.cropWidth, this.cropHeight); Graphics graphics1 = Graphics.FromImage(this.cropBitmap); graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel); this.pbCrop.Image = this.cropBitmap; } } catch (Exception exception2) { ProjectData.SetProjectError(exception2); Exception exception1 = exception2; MessageBox.Show(exception1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError(); }}
private void btnCrop_Click(object sender, EventArgs e){ try { if (this.cropWidth < 1) { MessageBox.Show("Выделите область, перемещая курсор!", " Нет области для выделения!", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { Rectangle rectangle2 = new Rectangle(this.cropX, this.cropY, this.cropWidth, this.cropHeight); Rectangle rectangle1 = rectangle2; Bitmap bitmap1 = new Bitmap(this.p.Image, this.p.Width, this.p.Height); this.cropBitmap = bitmap1(this.cropWidth, this.cropHeight); Graphics graphics1 = Graphics.FromImage(this.cropBitmap); graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel); this.pbCrop.Image = this.cropBitmap; } } catch (Exception exception2) { ProjectData.SetProjectError(exception2); Exception exception1 = exception2; MessageBox.Show(exception1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError(); }}
private void btnCrop_Click(object sender, EventArgs e){ try { if (this.cropWidth < 1) { MessageBox.Show("Выделите область, перемещая курсор!", " Нет области для выделения!", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { Rectangle rectangle2 = new Rectangle(this.cropX, this.cropY, this.cropWidth, this.cropHeight); Rectangle rectangle1 = rectangle2; Bitmap bitmap1 = new Bitmap(this.p.Image, this.p.Width, this.p.Height); this.cropBitmap = bitmap1(this.p.Image); Graphics graphics1 = Graphics.FromImage(this.cropBitmap); graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel); this.pbCrop.Image = this.cropBitmap; } } catch (Exception exception2) { ProjectData.SetProjectError(exception2); Exception exception1 = exception2; MessageBox.Show(exception1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError(); }}
private void btnCrop_Click(object sender, EventArgs e){ try { if (this.cropWidth < 1) { MessageBox.Show("Выделите область, перемещая курсор!", " Нет области для выделения!", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { Rectangle rectangle2 = new Rectangle(this.cropX, this.cropY, this.cropWidth, this.cropHeight); Rectangle rectangle1 = rectangle2; Bitmap bitmap1 = new Bitmap(this.p.Image, this.p.Width, this.p.Height); this.cropBitmap = new Bitmap(this.cropWidth, this.cropHeight); Graphics graphics1 = Graphics.FromImage(this.cropBitmap); graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel); this.pbCrop.Image = this.cropBitmap; } } catch (Exception exception2) { ProjectData.SetProjectError(exception2); Exception exception1 = exception2; MessageBox.Show(exception1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError(); }}(Верный ответ)