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

Аллюзии C#

using System;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Drawing.Imaging;

using System.Windows.Forms;

private readonly Pen pen1 = new Pen(Color.Black);

private Graphics graphics;

private bool isDrawing = false;

public int x_MD_1, y_MD_1;

private void Form1_Load(object sender, EventArgs e)

{

try

{

radioButton1.Checked = true;

StartNewDrawing();

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

private void StartNewDrawing()

{

Bitmap bm = new Bitmap(pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height);

graphics = Graphics.FromImage(bm);

graphics.Clear(BackColor);

pictureBox1.Image = bm;

pictureBox1.Refresh();

}

private void NewToolStripMenuItem_Click(object sender, EventArgs e)

{

try

{

StartNewDrawing();

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

private void PictureBox1_MouseDown(object sender, MouseEventArgs e)

{

try

{

if (e.Button == MouseButtons.Left)

{

if (radioButton3.Checked)

{

isDrawing = true;

x_MD_1 = e.X;

y_MD_1 = e.Y;

}

}

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

private void PictureBox1_MouseMove(object sender, MouseEventArgs e)

{

try

{

if (e.Button == MouseButtons.Left)

{

if (radioButton3.Checked)

{

if (!isDrawing) return;

}

}

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

private void PictureBox1_MouseUp(object sender, MouseEventArgs e)

{

try

{

if (e.Button == MouseButtons.Left)

{

if (radioButton3.Checked)

{

using (Graphics graphics = Graphics.FromImage(pictureBox1.Image))

{

graphics.SmoothingMode = SmoothingMode.AntiAlias;

graphics.DrawLine(pen1, x_MD_1, y_MD_1, e.X, e.Y);

}

// Refresh.

pictureBox1.Refresh();

}

}

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

private void NumericUpDown1_ValueChanged_1(object sender, EventArgs e)

{

try

{

pen1.Width = (int)numericUpDown1.Value;

}

catch (Exception Исключение)

{

// Отчет о других ошибках:

MessageBox.Show(Исключение.Message, "ошибка",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

"СТЛА"

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