Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lab_6
{
public partial class Form1 : Form
{
Color line = Color.Blue;
Color fill = Color.Gold;
Color animal = Color.Gray;
Bitmap A = null;
Graphics g;
bool open = false;
public Form1()
{
InitializeComponent();
g = panel1.CreateGraphics();
}
private void button1_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) // цвет выбран?
{
int R, G, B;
line = colorDialog1.Color; // цвет RGB
R = line.R;
G = line.G;
B = line.B;
}
panel1.Invalidate();
}
private void button2_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) // цвет выбран?
{
int R, G, B;
fill = colorDialog1.Color; // цвет RGB
R = fill.R;
G = fill.G;
B = fill.B;
}
panel1.Invalidate();
}
private void button3_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) // цвет выбран?
{
int R, G, B;
animal = colorDialog1.Color; // цвет RGB
R = animal.R;
G = animal.G;
B = animal.B;
}
panel1.Invalidate();
}
private void button4_Click(object sender, EventArgs e)
{
if (timer1.Enabled == false) timer1.Start();
else timer1.Stop();
}
private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
String path = openFileDialog1.FileName;
A = new Bitmap(path);
panel1.BackgroundImage = A;
panel1.Invalidate();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
int x = panel1.Width / 2;
int y = panel1.Height / 2;
Pen pen1 = new Pen(line, 3);
Brush brush1 = new SolidBrush(fill);
Brush brush2 = new SolidBrush(fill);
Brush brush3 = new SolidBrush(animal);
g.DrawPolygon(pen1, new Point[]{
new Point(x-30,y-60),new Point(x-30,y+50),new Point(x+30,y+50),new Point(x+30,y-60)});//прямоугольник
g.DrawPolygon(pen1, new Point[]{
new Point(x-40,y+50),new Point(x-40,y+60),new Point(x+40,y+60),new Point(x+40,y+50)});//низ
g.FillEllipse(brush1, x - 10, y - 40, 20, 20);//1
g.DrawRectangle(pen1, x - 10, y - 100, 20, 20);
g.FillPolygon(brush1, new Point[]{
new Point(x-40,y-60),new Point(x,y-80),new Point(x+40,y-60)});
if (!open) g.FillEllipse(brush1, x - 10, y - 40, 20, 20);
else
{
g.FillEllipse(brush2, x - 10, y - 10, 20, 20);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (open) open = false;
else open = true;
panel1.Invalidate();
}
}
}