Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- bool Drow;
- Pen pen = new Pen(Color.Black);
- Font font = new Font("Times New Roman", 12.0f);
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.Text = "Painting";
- button1.Text = "Paint";
- button2.Text = "Clear";
- button3.Text = "Color";
- button4.Text = "Text";
- button5.Text = "Font";
- button6.Text = "Save Picture";
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox1.SelectedIndex == 0)
- {
- textBox1.Visible = true;
- textBox2.Visible = true;
- textBox3.Visible = true;
- textBox4.Visible = true;
- textBox5.Visible = false;
- textBox6.Visible = false;
- checkBox1.Visible = false;
- }
- if (comboBox1.SelectedIndex == 1)
- {
- textBox1.Visible = true;
- textBox2.Visible = true;
- textBox3.Visible = true;
- textBox4.Visible = true;
- textBox5.Visible = true;
- textBox6.Visible = true;
- checkBox1.Visible = false;
- }
- if (comboBox1.SelectedIndex == 2)
- {
- textBox1.Visible = true;
- textBox2.Visible = true;
- textBox3.Visible = true;
- textBox4.Visible = true;
- textBox5.Visible = false;
- textBox6.Visible = false;
- checkBox1.Visible = true;
- }
- if (comboBox1.SelectedIndex == 3)
- {
- textBox1.Visible = true;
- textBox2.Visible = true;
- textBox3.Visible = true;
- textBox4.Visible = true;
- textBox5.Visible = false;
- textBox6.Visible = false;
- checkBox1.Visible = true;
- }
- button1.Enabled = true;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Graphics Graf = pictureBox1.CreateGraphics();
- Graf = pictureBox1.CreateGraphics();
- if (comboBox1.SelectedIndex == 0) Graf.DrawLine(pen,
- Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text));
- if (comboBox1.SelectedIndex == 1)
- {
- Graf.DrawLine(pen, Convert.ToInt32(textBox1.Text),
- Convert.ToInt32(textBox4.Text),
- Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox5.Text));
- Graf.DrawLine(pen, Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox5.Text),
- Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox6.Text));
- Graf.DrawLine(pen, Convert.ToInt32(textBox3.Text),
- Convert.ToInt32(textBox6.Text),
- Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox4.Text));
- }
- if (comboBox1.SelectedIndex == 2)
- {
- if (checkBox1.Checked)
- {
- if (colorDialog1.ShowDialog() == DialogResult.Cancel)
- return;
- Brush zal = new SolidBrush(colorDialog1.Color);
- Graf.FillEllipse(zal, Convert.ToInt32(textBox1.Text),
- Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text));
- }
- else
- {
- //Pen ElPen = new Pen(Color.Black);
- Graf.DrawEllipse(pen, Convert.ToInt32(textBox1.Text),
- Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text));
- }
- }
- if (comboBox1.SelectedIndex == 3)
- {
- Graf.DrawRectangle(pen, Convert.ToInt32(textBox1.Text),
- Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text));
- }
- pictureBox1.Update();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Graphics GC = pictureBox1.CreateGraphics();
- GC.Clear(SystemColors.Window);
- }
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- Graphics graf = pictureBox1.CreateGraphics();
- if (Drow == true)
- {
- graf.FillEllipse(Brushes.Violet, e.X, e.Y, Convert.ToInt32(numericUpDown1.Value),
- Convert.ToInt32(numericUpDown1.Value)); // толщина кисти
- }
- }
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- Drow = true;
- }
- private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
- {
- Drow = false;
- }
- private void button4_Click(object sender, EventArgs e)
- {
- String Text = String.Format("{0}", textBox7.Text);
- Brush Кисть = new SolidBrush(Color.LimeGreen);
- Graphics G = pictureBox1.CreateGraphics();
- G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
- G.DrawString(Text, font, Кисть, Convert.ToInt32(textBox8.Text), Convert.ToInt32(textBox9.Text)); // Координаты размещения текста
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (colorDialog1.ShowDialog() == DialogResult.Cancel)
- {
- return;
- }
- pen.Color = colorDialog1.Color;
- }
- private void button5_Click(object sender, EventArgs e)
- {
- if (fontDialog1.ShowDialog() == DialogResult.Cancel)
- {
- return;
- }
- font = fontDialog1.Font;
- }
- private void button6_Click(object sender, EventArgs e)
- {
- Rectangle r = pictureBox1.RectangleToScreen(pictureBox1.ClientRectangle);
- Bitmap b = new Bitmap(r.Width, r.Height);
- Graphics g = Graphics.FromImage(b);
- g.CopyFromScreen(r.Location, new Point(0, 0), r.Size);
- SaveFileDialog savedialog = new SaveFileDialog();
- if (savedialog.ShowDialog() == DialogResult.OK)
- {
- b.Save(savedialog.FileName);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement