Вы изучаете сборку графической программы, написанной на языке VisualBasic. При нажатии на кнопку btnCrop пользователь может вырезать часть выделенного изображения: Private Sub btnCrop_Click(ByVal sender As Object, ByVal e As EventArgs) Try If (Me.cropWidth < 1) Then MessageBox.Show("Выделите область, перемещая курсор!", "Нет области для выделения!", MessageBoxButtons.OK, MessageBoxIcon.Hand) Else Dim rectangle2 As New Rectangle(Me.cropX, Me.cropY, Me.cropWidth, Me.cropHeight) Dim rectangle1 As Rectangle = rectangle2 Dim bitmap1 As New Bitmap(Me.p.Image, Me.p.Width, Me.p.Height) Me.cropBitmap = New Bitmap(Me.cropWidth, Me.cropHeight) Dim graphics1 As Graphics = Graphics.FromImage(Me.cropBitmap) graphics1.DrawImage(bitmap1, 0, 0, rectangle1, GraphicsUnit.Pixel) Me.pbCrop.Image = Me.cropBitmap End If Catch exception2 As Exception ProjectData.SetProjectError(exception2) Dim exception1 As Exception = exception2 MessageBox.Show(exception1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand) ProjectData.ClearProjectError End TryEnd Sub
Выберите правильный перевод этого фрагмента кода на языке 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 = 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(); }}(Верный ответ)
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 = 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(); }}