Как сделать графический редактор с возможностью рисовать? - C#
Формулировка задачи:
Как сделать графический редактор в C#? с возможностью рисовать.
Решение задачи: «Как сделать графический редактор с возможностью рисовать?»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Practika2
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Color CurrentColor = Color.Black;
bool isPressed = false;
Point CurrentPoint;
Point PrevPoint;
Graphics g;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
g = pictureBox1.CreateGraphics();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void ВыходToolStripMenuItemClick(object sender, EventArgs e)
{
this.Close();
}
void PictureBox1MouseMove(object sender, MouseEventArgs e)
{
if(isPressed)
{
PrevPoint = CurrentPoint;
CurrentPoint = e.Location;
for_paint();
}
}
void PictureBox1MouseUp(object sender, MouseEventArgs e)
{
isPressed = false;
}
void PictureBox1MouseDown(object sender, MouseEventArgs e)
{
isPressed = true;
CurrentPoint = e.Location;
}
private void for_paint()
{
Pen p = new Pen(CurrentColor);
g.DrawLine(p, PrevPoint,CurrentPoint);
}
void ToolStripButton1Click(object sender, EventArgs e)
{
DialogResult D = colorDialog1.ShowDialog();
if(D == System.Windows.Forms.DialogResult.OK)
{
CurrentColor = colorDialog1.Color;
}
}
void ВыборЦветаФонаToolStripMenuItemClick(object sender, EventArgs e)
{
ColorDialog colorDialog1 = new ColorDialog();
colorDialog1.Color = pictureBox1.BackColor;
if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && colorDialog1.Color != pictureBox1.BackColor)
{
pictureBox1.BackColor = colorDialog1.Color;
}
}
}
}