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

Аллюзии VB.

Imports System.Drawing.Drawing2D

Imports System.Drawing.Imaging

Public Class Form1

Private m_Bitmap As Bitmap

Private m_Graphics As Graphics

Private m_Drawing As Boolean

ReadOnly penLine As New Pen(Color.Black)

Private m_X As Integer

Private m_Y As Integer

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

Try

MakeNewBitmap()

Dim i1 As Integer

For i1 = 1 To 300

ToolStripComboBox1.Items.Add(i1)

Next

ToolStripComboBox1.SelectedItem = 1

Catch ex As Exception

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

End Try

End Sub

Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewToolStripMenuItem.Click

Try

MakeNewBitmap()

Catch ex As Exception

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

End Try

End Sub

Private Sub MakeNewBitmap()

Dim wid As Integer = PictureBox1.ClientSize.Width

Dim hgt As Integer = PictureBox1.ClientSize.Height

m_Bitmap = New Bitmap(wid, hgt)

m_Graphics = Graphics.FromImage(m_Bitmap)

m_Graphics.Clear(Me.BackColor)

PictureBox1.Image = m_Bitmap

PictureBox1.Refresh()

End Sub

Private Sub PenColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PenColorToolStripMenuItem.Click

Try

Dim cdlg As New ColorDialog()

If cdlg.ShowDialog() = DialogResult.OK Then

penLine.Color = cdlg.Color

End If

Catch ex As Exception

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

End Try

End Sub

Private Sub ToolStripComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ToolStripComboBox1.SelectedIndexChanged

Try

penLine.Width = ToolStripComboBox1.SelectedIndex

Catch ex As Exception

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

End Try

End Sub

Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown

Try

If e.Button = MouseButtons.Left Then

If RadioButton2.Checked Then

m_Drawing = True

m_X = e.X

m_Y = e.Y

End If

End If

Catch ex As Exception

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

End Try

End Sub

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove

Try

If e.Button = MouseButtons.Left Then

If RadioButton2.Checked Then

If Not m_Drawing Then Return

End If

End If

Catch ex As Exception

End Try

End Sub

Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp

Try

If e.Button = MouseButtons.Left Then

If RadioButton2.Checked Then

m_Drawing = True

Using m_Graphics = Graphics.FromImage(PictureBox1.Image)

m_Graphics.SmoothingMode = SmoothingMode.AntiAlias

m_Graphics.DrawLine(penLine, m_X, m_Y, e.X, e.Y)

End Using

' Display the result.

PictureBox1.Refresh()

End If

End If

Catch ex As Exception

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

End Try

End Sub

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

Close()

End Sub

End Class

"СТЛА"

Караваев В.Г.