Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Звіт Чуй.docx
Скачиваний:
6
Добавлен:
08.11.2019
Размер:
6.73 Mб
Скачать

Робота зі складними об’єктами

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication5

{

public partial class Form1 : Form

{

int xc=100, yc=100;

class Man

{

Point o;

Color c;

public Man(Point O, Color C)

{

o = O;

c = C;

}

public void DrawBody(Graphics g)

{

Rectangle rf = new Rectangle(0, 0, 500, 400);

System.Drawing.SolidBrush bf = new System.Drawing.SolidBrush(Color.Green);

g.FillRectangle(bf, rf);

int head = 80;

Rectangle recthead = new Rectangle(o.X, o.Y, head, head);

System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush(Color.Khaki);

System.Drawing.SolidBrush brusheye2 = new System.Drawing.SolidBrush(Color.Black);

Pen pen1 = new Pen (brusheye2);

g.FillEllipse(brush1, recthead);

Rectangle recbody = new Rectangle(o.X+head*1/7, o.Y+head*21/26, head*5/7, head*5/7);

g.FillRectangle(brush1, recbody);

Rectangle recfoot = new Rectangle(o.X, o.Y + head * 21 / 26 + head * 5/7, head, head * 1 / 15);

System.Drawing.SolidBrush brushf = new System.Drawing.SolidBrush(Color.Black);

g.FillRectangle(brushf, recfoot);

Rectangle recthand1 = new Rectangle(o.X + head * 1 / 7 - 10, o.Y + head * 21 / 26, 10, 40);

g.FillRectangle(brush1, recthand1);

Rectangle recthand2 = new Rectangle(o.X + head *6 / 7, o.Y + head * 21 / 26, 10, 40);

g.FillRectangle(brush1, recthand2);

Rectangle recthand3 = new Rectangle(o.X + head * 1 / 7 - 11, o.Y + head * 21 / 26 + 35, 12, 12);

g.FillEllipse(brush1, recthand3);

Rectangle recthand4 = new Rectangle(o.X + head * 21 / 26+2, o.Y + head * 21 / 26 + 35, 12, 12);

g.FillEllipse(brush1, recthand4);

Rectangle eye1 = new Rectangle(o.X + head * 2 / 7-5, o.Y + head * 2 / 7, 25, 25);

System.Drawing.SolidBrush brusheye = new System.Drawing.SolidBrush(Color.White);

g.FillEllipse(brusheye, eye1);

Rectangle eye2 = new Rectangle(o.X + head * 2 / 7+20, o.Y + head * 2 / 7, 25, 25);

g.FillEllipse(brusheye, eye2);

Rectangle eye3 = new Rectangle(o.X + head * 2 / 7 + 5, o.Y + head * 2 / 7 + 10, 3, 3);

g.FillEllipse(brusheye2, eye3);

Rectangle eye4 = new Rectangle(o.X + head * 2 / 7 + 30, o.Y + head * 2 / 7 + 10, 3, 3);

g.FillEllipse(brusheye2, eye4);

Rectangle rot = new Rectangle(o.X + head * 2 / 7 + 10, o.Y + head * 2 / 7 + 35, 18, 2);

g.FillEllipse(brusheye2, rot);

g.DrawEllipse(pen1, recthead);

}

}

class Cloth

{

private Point o;

private Color c;

public Cloth(Point O, Color C)

{

o = O;

c = C;

}

public void DrawTrousers(Graphics g)

{

int head = 80;

System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush(c);

Rectangle rect = new Rectangle(o.X + head * 1 / 7, o.Y + head+33, head * 5 / 7, 8);

g.FillRectangle(brush1, rect);

}

bool isChacked = false;

public void DrawTshirt(Graphics g)

{

int head = 80;

System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush(c);

Rectangle recbody = new Rectangle(o.X + head * 1 / 7, o.Y + head * 21 / 26, head * 5 / 7, head * 5 / 7-8);

g.FillRectangle(brush1, recbody);

Rectangle recthand1 = new Rectangle(o.X + head * 1 / 7 - 10, o.Y + head * 21 / 26, 10, 40);

g.FillRectangle(brush1, recthand1);

Rectangle recthand2 = new Rectangle(o.X + head * 6 / 7, o.Y + head * 21 / 26, 10, 40);

g.FillRectangle(brush1, recthand2);

System.Drawing.SolidBrush brushb = new System.Drawing.SolidBrush(Color.Khaki);

Rectangle recthead = new Rectangle(o.X, o.Y, head, head);

g.FillEllipse(brushb, recthead);

Rectangle eye1 = new Rectangle(o.X + head * 2 / 7 - 5, o.Y + head * 2 / 7, 25, 25);

System.Drawing.SolidBrush brusheye = new System.Drawing.SolidBrush(Color.White);

g.FillEllipse(brusheye, eye1);

Rectangle eye2 = new Rectangle(o.X + head * 2 / 7 + 20, o.Y + head * 2 / 7, 25, 25);

g.FillEllipse(brusheye, eye2);

System.Drawing.SolidBrush brusheye2 = new System.Drawing.SolidBrush(Color.Black);

Pen pen1 = new Pen(brusheye2);

Rectangle eye3 = new Rectangle(o.X + head * 2 / 7 + 5, o.Y + head * 2 / 7 + 10, 3, 3);

g.FillEllipse(brusheye2, eye3);

Rectangle eye4 = new Rectangle(o.X + head * 2 / 7 + 30, o.Y + head * 2 / 7 + 10, 3, 3);

g.FillEllipse(brusheye2, eye4);

Rectangle rot = new Rectangle(o.X + head * 2 / 7 + 10, o.Y + head * 2 / 7 + 35, 18, 2);

g.FillEllipse(brusheye2, rot);

g.DrawEllipse(pen1, recthead);

if (isChacked == true)

{

g.DrawImage(Image.FromFile("D:\\Chuy\\1\\Новая папка\\People\\pic6.jpg"), o.X - 13, o.Y - 19);

}

}

public void DrawHead(Graphics g)

{

int head = 80;

g.DrawImage(Image.FromFile("D:\\Chuy\\1\\Новая папка\\People\\pic6.jpg"), o.X-13, o.Y-19);

}

public void DrawBoroda(Graphics g)

{

int head = 80;

int age = 30;

System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush(Color.Black);

Pen p1 = new Pen(brush1);

g.DrawLine(p1,o.X + head/2, o.Y + 70, o.X + head/2, o.Y + +70+ age);

g.DrawLine(p1, o.X + head / 2 - 5, o.Y + 70 -5 , o.X + head / 2 -5, o.Y + +70 + age -5);

g.DrawLine(p1, o.X + head / 2 + 5, o.Y + 70 - 5, o.X + head / 2 + 5, o.Y + +70 + age - 5);

}

}

void Draw(int x, int y)

{

Point p = new Point();

p.X = x;

p.Y = y;

Graphics g = pictureBox1.CreateGraphics();

Man hum1 = new Man(p, Color.Khaki);

hum1.DrawBody(g);

}

public Form1()

{

InitializeComponent();

}

private void створитиЛюдинуToolStripMenuItem_Click(object sender, EventArgs e)

{

Draw(100,100);

Bitmap bmp = new Bitmap(447, 371);

pictureBox1.Image = bmp;

bmp.Save("file.bmp");

Draw(100, 100);

}

private void штаниToolStripMenuItem_Click(object sender, EventArgs e)

{

Color col = Color.Blue;

if (colorDialog1.ShowDialog() == DialogResult.OK)

{

col = colorDialog1.Color;

}

Point p = new Point();

p.X = xc;

p.Y = yc;

Graphics g = pictureBox1.CreateGraphics();

Cloth t = new Cloth(p, col);

t.DrawTrousers(g);

}

private void курткаToolStripMenuItem_Click(object sender, EventArgs e)

{

Color col = Color.Blue;

if (colorDialog1.ShowDialog() == DialogResult.OK)

{

col = colorDialog1.Color;

}

Point p = new Point();

p.X = xc;

p.Y = yc;

Graphics g = pictureBox1.CreateGraphics();

Cloth t = new Cloth(p, col);

t.DrawTshirt(g);

}

int l = 0;

private void діалогToolStripMenuItem_Click(object sender, EventArgs e)

{

if (l == 0)

{

textBox1.Text += "Як тебе звати?";

textBox1.Text += Environment.NewLine;

l++;

}

}

private void button1_Click(object sender, EventArgs e)

{

if (l==1)

{

textBox1.Text += Environment.NewLine;

textBox1.Text += "Привіт, " + textBox1.Lines[1] + " Розкажи щось про себе.";

textBox1.Text += Environment.NewLine;

l++;

}

else

{

textBox1.Text += Environment.NewLine;

textBox1.Text += "З тобою так цікаво";

textBox1.Text += Environment.NewLine;

}

}

bool isDown = false;

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

isDown = true;

}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)

{

if (isDown)

{

Draw(e.X, e.Y);

}

}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

{

isDown = false;

}

Draw(e.X, e.Y);

xc = e.X;

yc = e.Y;

}

bool isChacked = false;

private void шапкаToolStripMenuItem_Click(object sender, EventArgs e)

{

Color col = Color.Blue;

Point p = new Point();

p.X = xc;

p.Y = yc;

Graphics g = pictureBox1.CreateGraphics();

Cloth t = new Cloth(p, col);

t.DrawHead(g);

if (isChacked == false)

isChacked = true;

else

isChacked = false;

}

private void вікToolStripMenuItem_Click(object sender, EventArgs e)

{

Color col = Color.Blue;

Point p = new Point();

p.X = xc;

p.Y = yc;

Graphics g = pictureBox1.CreateGraphics();

Cloth t = new Cloth(p, col);

t.DrawBoroda(g);

}

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]