Найти тему
Горизонт

Загадка схемы кода.

В схеме кода, с которой можно познакомиться далее, нет обработчика события перемещения разделительной линии в сплит контейнере. И кроме прочего, поэтому, вообще говоря: не бывалое бывает,- и это, как раз то, что демонстрирует, экземплифицирует видео по ссылке. Разделительный контейнер не красит, ни окращивает, и не является инструментом рисовования, и разве что привходящим образом. А Вы как думаете, напишите в комментариях.

Ссыла на видео на канале в Ю-тьб: https://youtu.be/9QGn72Rg1z4

Схема кода программы. Сплин контейнер, две панели, в каждом из которых по одному пеналу для Окон картинок, одно из которых не в доке в пенале, ради полос прокрутки. При определенных условиях, что показаны на видео: линейный, градиентный, фон правого от зрителя окна каринок, при протягивании разделительной линии, передается левому окну. Дальнейшее менее удивительно, в упомянутом смысле, но зато может быть полезно для "грунтовки" фона холста пррисовки.

Imports System.Drawing.Drawing2D

Public Class Form1

Private Const CORNER_RADIUS As Integer = 9

Private BmSource As Bitmap

Private BmDest As Bitmap

Private Corners As Point()

Private DragCorner As Long

Private ContrlMouse As Boolean

Private ReadOnly Random As New Random

' The original image that is maintained in order to revert.

Private originalImage As Image = Nothing

' The current image that it being edited and updated.

Private currentImage As Image = Nothing

' The Bitmap and Graphics objects we will draw on.

Private m_Bitmap As Bitmap

Private m_Graphics As Graphics

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click

Close()

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

'вращение

' присвоение значения выполнения переменным и константам вращения картинки

BmSource = New Bitmap(PictureBox1.Image)

BmDest = New Bitmap((BmSource.Width), (BmSource.Height))

Corners = New Point() {New Point(0, 0), New Point(BmSource.Width, 0), New Point(0, BmSource.Height)}

DragCorner = -1

' Выводим картинку.

WarpImage()

Dim i111 As Integer

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox1.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox1.Sorted = True

' выбор пункта

ToolStripComboBox1.SelectedItem = Color.Red

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox7.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox7.Sorted = True

' выбор пункта

ToolStripComboBox7.SelectedItem = Color.Green

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox8.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox8.Sorted = True

' выбор пункта

ToolStripComboBox8.SelectedItem = Color.Blue

Dim i1 As Integer

For i1 = 1 To 33

ToolStripComboBox2.Items.Add(i1)

Next

ToolStripComboBox2.SelectedItem = 3

For i1 = 1 To 33

ToolStripComboBox3.Items.Add(i1)

Next

ToolStripComboBox3.SelectedItem = 3

For i1 = 1 To 33

ToolStripComboBox4.Items.Add(i1)

Next

ToolStripComboBox4.SelectedItem = 10

For i1 = 1 To 33

ToolStripComboBox5.Items.Add(i1)

Next

ToolStripComboBox5.SelectedItem = 10

For i1 = 1 To 33

ToolStripComboBox6.Items.Add(i1)

Next

ToolStripComboBox6.SelectedItem = 10

MakeNewBitmap()

End Sub

Private Sub MakeNewBitmap()

' Get the drawing surface's size.

Dim wid As Integer = PictureBox2.ClientSize.Width

Dim hgt As Integer = PictureBox2.ClientSize.Height

' Make a Bitmap and Graphics to fit.

m_Bitmap = New Bitmap(wid, hgt)

m_Graphics = Graphics.FromImage(m_Bitmap)

' Clear the drawing area.

m_Graphics.Clear(Me.BackColor)

' Display the result.

PictureBox2.Image = m_Bitmap

PictureBox2.Refresh()

End Sub

Private Sub WarpImage()

Using m_Graphics = Graphics.FromImage(PictureBox1.Image)

' Создадим объект Graphics для картинки.

Dim gr_dest As Graphics = Graphics.FromImage(BmDest)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox2.ClientSize.Width, PictureBox2.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

' Копируем картинку-источник в целевую картинку,

'gr_dest.Clear(PictureBox2.BackColor)

gr_dest.DrawImage(BmSource, Corners)

' Рисуем три метки-окружности.

Dim i As Long

For i = 0 To 2

Dim pn As New Pen(CType(ToolStripComboBox1.SelectedItem, Color), CType(ToolStripComboBox2.SelectedItem, Integer))

gr_dest.DrawEllipse(pn,

Corners(CInt(i)).X - CORNER_RADIUS,

Corners(CInt(i)).Y - CORNER_RADIUS,

2 * CORNER_RADIUS, 2 * CORNER_RADIUS)

Next i

' Показываем результат.

PictureBox2.Image = BmDest

PictureBox2.Refresh()

End Using

End Sub

Private Sub InsertImageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InsertImageToolStripMenuItem.Click

Try

InsertImage()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Sub InsertImage()

Try

' originalImage = GetImage()

' currentImage = CType(originalImage.Clone(), Image)

' Using m_BitmapAs New Bitmap(currentImage)

' PictureBox2.Image = image1

' End Using

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

BmSource = New Bitmap(PictureBox1.Image)

BmDest = New Bitmap((BmSource.Width), (BmSource.Height))

Corners = New Point() {New Point(CType(ToolStripComboBox5.SelectedItem, Integer), CType(ToolStripComboBox6.SelectedItem, Integer)), New Point(BmSource.Width, CType(ToolStripComboBox3.SelectedItem, Integer)), New Point(CType(ToolStripComboBox4.SelectedItem, Integer), BmSource.Height)}

DragCorner = -1

' Выводим картинку.

WarpImage()

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDown

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

Dim i As Long

' Если мышь рядом с одной из меток.

For i = 0 To 2

If (Math.Abs(Corners(CInt(i)).X - e.X) < CORNER_RADIUS) And

(Math.Abs(Corners(CInt(i)).Y - e.Y) < CORNER_RADIUS) Then

' Начинаем перетаскивать угол.

DragCorner = i

Exit For

End If

Next i

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

' Проверка, перетаскиваем ли угол картинки.

If DragCorner < 0 Then Exit Sub

Corners(CInt(DragCorner)).X = e.X

If Corners(CInt(DragCorner)).X < 0 Then

Corners(CInt(DragCorner)).X = 0

ElseIf Corners(CInt(DragCorner)).X > BmDest.Width Then

Corners(CInt(DragCorner)).X = BmDest.Width

End If

Corners(CInt(DragCorner)).Y = e.Y

If Corners(CInt(DragCorner)).Y < 0 Then

Corners(CInt(DragCorner)).Y = 0

ElseIf Corners(CInt(DragCorner)).Y > BmDest.Height Then

Corners(CInt(DragCorner)).Y = BmDest.Height

End If

WarpImage()

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseUp

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

DragCorner = -1

' PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub Delate1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles Delate1ToolStripMenuItem.Click

Try

GetObject1()

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Function GetObject1() As Graphics

Dim bmp As Bitmap

bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)

PictureBox1.Image = bmp

Dim G As Graphics

G = Graphics.FromImage(bmp)

Return G

End Function

Private Sub DelateToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DelateToolStripMenuItem.Click

Try

GetObject2()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Function GetObject2() As Graphics

Dim bmp As Bitmap

bmp = New Bitmap(PictureBox2.Width, PictureBox2.Height)

PictureBox2.Image = bmp

Dim G As Graphics

G = Graphics.FromImage(bmp)

Return G

End Function

Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click

Try

If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

' Open Image

originalImage = CType(Image.FromFile(OpenFileDialog1.FileName), Bitmap)

currentImage = CType(originalImage.Clone(), Image)

m_Bitmap = New Bitmap(currentImage)

PictureBox1.Image = m_Bitmap

Else

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDoubleClick

Try

If e.Button = MouseButtons.Right Then

ContrlMouse = True

SaveWImage()

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub SaveRotatePictureToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveRotatePictureToolStripMenuItem.Click

Try

SaveWImage()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Sub SaveWImage()

Try

'Save Image

If SaveFileDialog1.ShowDialog() = DialogResult.OK Then

PictureBox2.Image.Save(SaveFileDialog1.FileName, GetImageFormat1())

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Function GetImageFormat1() As Imaging.ImageFormat

Try

Select Case SaveFileDialog1.FilterIndex

Case 1

Return Imaging.ImageFormat.Jpeg

Case 2

Return Imaging.ImageFormat.Png

Case 3

Return Imaging.ImageFormat.Gif

Case 4

Return Imaging.ImageFormat.Tiff

Case Else

Return Imaging.ImageFormat.Bmp

End Select

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

'Создание функции управления выбором случая расширения файла

Return Nothing

End Function

Private Sub BackColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BackColorToolStripMenuItem.Click

Try

Dim cdlg As New ColorDialog()

If cdlg.ShowDialog() = DialogResult.OK Then

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

'm_Graphics.Clear(cdlg.Color)

PictureBox2.BackColor = cdlg.Color

PictureBox2.Invalidate()

End Using

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub GradientBackColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GradientBackColorToolStripMenuItem.Click

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox2.ClientSize.Width, PictureBox2.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub GradientBackColorPB1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GradientBackColorPB1ToolStripMenuItem.Click

Try

Using m_Graphics = Graphics.FromImage(PictureBox1.Image)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

PictureBox1.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

End Class

Imports System.Drawing.Drawing2D

Public Class Form1

Private Const CORNER_RADIUS As Integer = 9

Private BmSource As Bitmap

Private BmDest As Bitmap

Private Corners As Point()

Private DragCorner As Long

Private ContrlMouse As Boolean

Private ReadOnly Random As New Random

' The original image that is maintained in order to revert.

Private originalImage As Image = Nothing

' The current image that it being edited and updated.

Private currentImage As Image = Nothing

' The Bitmap and Graphics objects we will draw on.

Private m_Bitmap As Bitmap

Private m_Graphics As Graphics

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click

Close()

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

'вращение

' присвоение значения выполнения переменным и константам вращения картинки

BmSource = New Bitmap(PictureBox1.Image)

BmDest = New Bitmap((BmSource.Width), (BmSource.Height))

Corners = New Point() {New Point(0, 0), New Point(BmSource.Width, 0), New Point(0, BmSource.Height)}

DragCorner = -1

' Выводим картинку.

WarpImage()

Dim i111 As Integer

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox1.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox1.Sorted = True

' выбор пункта

ToolStripComboBox1.SelectedItem = Color.Red

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox7.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox7.Sorted = True

' выбор пункта

ToolStripComboBox7.SelectedItem = Color.Green

For i111 = 1 To 167

If i111 <> Nothing Then _

ToolStripComboBox8.Items.Add(Color.FromKnownColor((CType(i111, KnownColor))))

Next

'Сортировать записи в алфавитном порядке:

ToolStripComboBox8.Sorted = True

' выбор пункта

ToolStripComboBox8.SelectedItem = Color.Blue

Dim i1 As Integer

For i1 = 1 To 33

ToolStripComboBox2.Items.Add(i1)

Next

ToolStripComboBox2.SelectedItem = 3

For i1 = 1 To 33

ToolStripComboBox3.Items.Add(i1)

Next

ToolStripComboBox3.SelectedItem = 3

For i1 = 1 To 33

ToolStripComboBox4.Items.Add(i1)

Next

ToolStripComboBox4.SelectedItem = 10

For i1 = 1 To 33

ToolStripComboBox5.Items.Add(i1)

Next

ToolStripComboBox5.SelectedItem = 10

For i1 = 1 To 33

ToolStripComboBox6.Items.Add(i1)

Next

ToolStripComboBox6.SelectedItem = 10

MakeNewBitmap()

End Sub

Private Sub MakeNewBitmap()

' Get the drawing surface's size.

Dim wid As Integer = PictureBox2.ClientSize.Width

Dim hgt As Integer = PictureBox2.ClientSize.Height

' Make a Bitmap and Graphics to fit.

m_Bitmap = New Bitmap(wid, hgt)

m_Graphics = Graphics.FromImage(m_Bitmap)

' Clear the drawing area.

m_Graphics.Clear(Me.BackColor)

' Display the result.

PictureBox2.Image = m_Bitmap

PictureBox2.Refresh()

End Sub

Private Sub WarpImage()

Using m_Graphics = Graphics.FromImage(PictureBox1.Image)

' Создадим объект Graphics для картинки.

Dim gr_dest As Graphics = Graphics.FromImage(BmDest)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox2.ClientSize.Width, PictureBox2.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

' Копируем картинку-источник в целевую картинку,

'gr_dest.Clear(PictureBox2.BackColor)

gr_dest.DrawImage(BmSource, Corners)

' Рисуем три метки-окружности.

Dim i As Long

For i = 0 To 2

Dim pn As New Pen(CType(ToolStripComboBox1.SelectedItem, Color), CType(ToolStripComboBox2.SelectedItem, Integer))

gr_dest.DrawEllipse(pn,

Corners(CInt(i)).X - CORNER_RADIUS,

Corners(CInt(i)).Y - CORNER_RADIUS,

2 * CORNER_RADIUS, 2 * CORNER_RADIUS)

Next i

' Показываем результат.

PictureBox2.Image = BmDest

PictureBox2.Refresh()

End Using

End Sub

Private Sub InsertImageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InsertImageToolStripMenuItem.Click

Try

InsertImage()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Sub InsertImage()

Try

' originalImage = GetImage()

' currentImage = CType(originalImage.Clone(), Image)

' Using m_BitmapAs New Bitmap(currentImage)

' PictureBox2.Image = image1

' End Using

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

BmSource = New Bitmap(PictureBox1.Image)

BmDest = New Bitmap((BmSource.Width), (BmSource.Height))

Corners = New Point() {New Point(CType(ToolStripComboBox5.SelectedItem, Integer), CType(ToolStripComboBox6.SelectedItem, Integer)), New Point(BmSource.Width, CType(ToolStripComboBox3.SelectedItem, Integer)), New Point(CType(ToolStripComboBox4.SelectedItem, Integer), BmSource.Height)}

DragCorner = -1

' Выводим картинку.

WarpImage()

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDown

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

Dim i As Long

' Если мышь рядом с одной из меток.

For i = 0 To 2

If (Math.Abs(Corners(CInt(i)).X - e.X) < CORNER_RADIUS) And

(Math.Abs(Corners(CInt(i)).Y - e.Y) < CORNER_RADIUS) Then

' Начинаем перетаскивать угол.

DragCorner = i

Exit For

End If

Next i

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

' Проверка, перетаскиваем ли угол картинки.

If DragCorner < 0 Then Exit Sub

Corners(CInt(DragCorner)).X = e.X

If Corners(CInt(DragCorner)).X < 0 Then

Corners(CInt(DragCorner)).X = 0

ElseIf Corners(CInt(DragCorner)).X > BmDest.Width Then

Corners(CInt(DragCorner)).X = BmDest.Width

End If

Corners(CInt(DragCorner)).Y = e.Y

If Corners(CInt(DragCorner)).Y < 0 Then

Corners(CInt(DragCorner)).Y = 0

ElseIf Corners(CInt(DragCorner)).Y > BmDest.Height Then

Corners(CInt(DragCorner)).Y = BmDest.Height

End If

WarpImage()

'PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseUp

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

DragCorner = -1

' PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub Delate1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles Delate1ToolStripMenuItem.Click

Try

GetObject1()

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Function GetObject1() As Graphics

Dim bmp As Bitmap

bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)

PictureBox1.Image = bmp

Dim G As Graphics

G = Graphics.FromImage(bmp)

Return G

End Function

Private Sub DelateToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DelateToolStripMenuItem.Click

Try

GetObject2()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Function GetObject2() As Graphics

Dim bmp As Bitmap

bmp = New Bitmap(PictureBox2.Width, PictureBox2.Height)

PictureBox2.Image = bmp

Dim G As Graphics

G = Graphics.FromImage(bmp)

Return G

End Function

Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click

Try

If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

' Open Image

originalImage = CType(Image.FromFile(OpenFileDialog1.FileName), Bitmap)

currentImage = CType(originalImage.Clone(), Image)

m_Bitmap = New Bitmap(currentImage)

PictureBox1.Image = m_Bitmap

Else

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub PictureBox2_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDoubleClick

Try

If e.Button = MouseButtons.Right Then

ContrlMouse = True

SaveWImage()

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub SaveRotatePictureToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveRotatePictureToolStripMenuItem.Click

Try

SaveWImage()

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Sub SaveWImage()

Try

'Save Image

If SaveFileDialog1.ShowDialog() = DialogResult.OK Then

PictureBox2.Image.Save(SaveFileDialog1.FileName, GetImageFormat1())

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Function GetImageFormat1() As Imaging.ImageFormat

Try

Select Case SaveFileDialog1.FilterIndex

Case 1

Return Imaging.ImageFormat.Jpeg

Case 2

Return Imaging.ImageFormat.Png

Case 3

Return Imaging.ImageFormat.Gif

Case 4

Return Imaging.ImageFormat.Tiff

Case Else

Return Imaging.ImageFormat.Bmp

End Select

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

'Создание функции управления выбором случая расширения файла

Return Nothing

End Function

Private Sub BackColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BackColorToolStripMenuItem.Click

Try

Dim cdlg As New ColorDialog()

If cdlg.ShowDialog() = DialogResult.OK Then

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

'm_Graphics.Clear(cdlg.Color)

PictureBox2.BackColor = cdlg.Color

PictureBox2.Invalidate()

End Using

End If

Catch ex As Exception

MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub GradientBackColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GradientBackColorToolStripMenuItem.Click

Try

Using m_Graphics = Graphics.FromImage(PictureBox2.Image)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox2.ClientSize.Width, PictureBox2.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

PictureBox2.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

Private Sub GradientBackColorPB1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GradientBackColorPB1ToolStripMenuItem.Click

Try

Using m_Graphics = Graphics.FromImage(PictureBox1.Image)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

Dim GrBrush As LinearGradientBrush

Dim Rect = New Rectangle(0, 0, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height)

GrBrush = New LinearGradientBrush(Rect, CType(ToolStripComboBox7.SelectedItem, Color), CType(ToolStripComboBox8.SelectedItem, Color), NumericUpDown1.Value)

m_Graphics.FillRectangle(GrBrush, Rect)

PictureBox1.Refresh()

End Using

Catch ex As Exception

MessageBox.Show(ex.Message, "Mistake", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

End Try

End Sub

End Class