From 0ac84cd6c7dd477e4b98522f6fe737b866988581 Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Thu, 4 Jul 2024 02:20:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Final/Final/Final.csproj | 15 +++ Final/Final/Form1.Designer.cs | 102 +++++++++++++++- Final/Final/Form1.cs | 77 +++++++++++- Final/Final/Properties/Resources.Designer.cs | 63 ++++++++++ Final/Final/Properties/Resources.resx | 120 +++++++++++++++++++ Final/Final/Rectangle.cs | 27 +++++ Final/Final/RectangleWithOval.cs | 29 +++++ 7 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 Final/Final/Properties/Resources.Designer.cs create mode 100644 Final/Final/Properties/Resources.resx create mode 100644 Final/Final/Rectangle.cs create mode 100644 Final/Final/RectangleWithOval.cs diff --git a/Final/Final/Final.csproj b/Final/Final/Final.csproj index e1a0735..244387d 100644 --- a/Final/Final/Final.csproj +++ b/Final/Final/Final.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/Final/Final/Form1.Designer.cs b/Final/Final/Form1.Designer.cs index 4532390..a354bf5 100644 --- a/Final/Final/Form1.Designer.cs +++ b/Final/Final/Form1.Designer.cs @@ -1,4 +1,6 @@ -namespace Final +using System.Windows.Forms; + +namespace Final { partial class Form1 { @@ -34,9 +36,19 @@ button1 = new Button(); listBox1 = new ListBox(); tabPage2 = new TabPage(); + button5 = new Button(); + textBox1 = new TextBox(); + textBoxH = new TextBox(); + textBoxW = new TextBox(); + button4 = new Button(); + button3 = new Button(); + listBox2 = new ListBox(); + pictureBox1 = new PictureBox(); tabPage3 = new TabPage(); tabControl1.SuspendLayout(); tabPage1.SuspendLayout(); + tabPage2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); SuspendLayout(); // // tabControl1 @@ -94,6 +106,14 @@ // // tabPage2 // + tabPage2.Controls.Add(button5); + tabPage2.Controls.Add(textBox1); + tabPage2.Controls.Add(textBoxH); + tabPage2.Controls.Add(textBoxW); + tabPage2.Controls.Add(button4); + tabPage2.Controls.Add(button3); + tabPage2.Controls.Add(listBox2); + tabPage2.Controls.Add(pictureBox1); tabPage2.Location = new Point(4, 34); tabPage2.Name = "tabPage2"; tabPage2.Padding = new Padding(3); @@ -102,6 +122,75 @@ tabPage2.Text = "1 задание"; tabPage2.UseVisualStyleBackColor = true; // + // button5 + // + button5.Location = new Point(918, 470); + button5.Name = "button5"; + button5.Size = new Size(138, 62); + button5.TabIndex = 9; + button5.Text = "Квадрат с овалом"; + button5.UseVisualStyleBackColor = true; + button5.Click += button5_Click; + // + // textBox1 + // + textBox1.Location = new Point(168, 172); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(299, 31); + textBox1.TabIndex = 8; + // + // textBoxH + // + textBoxH.Location = new Point(168, 101); + textBoxH.Name = "textBoxH"; + textBoxH.Size = new Size(299, 31); + textBoxH.TabIndex = 7; + // + // textBoxW + // + textBoxW.Location = new Point(168, 23); + textBoxW.Name = "textBoxW"; + textBoxW.Size = new Size(299, 31); + textBoxW.TabIndex = 6; + // + // button4 + // + button4.Location = new Point(602, 470); + button4.Name = "button4"; + button4.Size = new Size(112, 62); + button4.TabIndex = 5; + button4.Text = "Квадрат"; + button4.UseVisualStyleBackColor = true; + button4.Click += button4_Click; + // + // button3 + // + button3.Location = new Point(735, 470); + button3.Name = "button3"; + button3.Size = new Size(138, 62); + button3.TabIndex = 4; + button3.Text = "Квадрат с овалом"; + button3.UseVisualStyleBackColor = true; + button3.Click += button3_Click; + // + // listBox2 + // + listBox2.FormattingEnabled = true; + listBox2.ItemHeight = 25; + listBox2.Location = new Point(9, 470); + listBox2.Name = "listBox2"; + listBox2.Size = new Size(519, 129); + listBox2.TabIndex = 1; + // + // pictureBox1 + // + pictureBox1.BackColor = Color.DarkGray; + pictureBox1.Location = new Point(521, 6); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new Size(619, 428); + pictureBox1.TabIndex = 0; + pictureBox1.TabStop = false; + // // tabPage3 // tabPage3.Location = new Point(4, 34); @@ -122,6 +211,9 @@ Text = "Form1"; tabControl1.ResumeLayout(false); tabPage1.ResumeLayout(false); + tabPage2.ResumeLayout(false); + tabPage2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); ResumeLayout(false); } @@ -134,5 +226,13 @@ private Button button2; private Button button1; private TabPage tabPage3; + private ListBox listBox2; + private PictureBox pictureBox1; + private Button button3; + private Button button4; + private TextBox textBoxH; + private TextBox textBoxW; + private TextBox textBox1; + private Button button5; } } \ No newline at end of file diff --git a/Final/Final/Form1.cs b/Final/Final/Form1.cs index ba8bac9..bb01fc2 100644 --- a/Final/Final/Form1.cs +++ b/Final/Final/Form1.cs @@ -1,16 +1,23 @@ +using System.Drawing; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; + namespace Final { public partial class Form1 : Form { - List ones; + private List rectangles; + private Random rand; + private Color selectedColor = Color.Red; public Form1() { ones = new List(); - + rectangles = new List(); + rand = new Random(); InitializeComponent(); } @@ -36,5 +43,71 @@ namespace Final listBox1.Items.Add(ones[i].ToString()); } } + private void ChooseColor() + { + using (ColorDialog colorDialog = new ColorDialog()) + { + if (colorDialog.ShowDialog() == DialogResult.OK) + { + selectedColor = colorDialog.Color; + } + } + } + private void button3_Click(object sender, EventArgs e) + { + if (int.TryParse(textBoxW.Text, out int width) && int.TryParse(textBoxH.Text, out int height)) + { + Point position = new Point(rand.Next(0, pictureBox1.Width - width), rand.Next(0, pictureBox1.Height - height)); + RectangleWithOval rectangleWithOval = new RectangleWithOval(width, height, position, selectedColor); + rectangles.Add(rectangleWithOval); + listBox1.Items.Add(rectangleWithOval); + } + else + { + MessageBox.Show(", ."); + } + } + + private void button4_Click(object sender, EventArgs e) + { + if (int.TryParse(textBoxW.Text, out int width) && int.TryParse(textBoxH.Text, out int height)) + { + Point position = new Point(rand.Next(0, pictureBox1.Width - width), rand.Next(0, pictureBox1.Height - height)); + Rectangle rectangle = new Rectangle(width, height, position); + rectangles.Add(rectangle); + listBox2.Items.Add(rectangle); + } + else + { + MessageBox.Show(", ."); + } + } + + private void button5_Click(object sender, EventArgs e) + { + if (listBox2.SelectedItem is Rectangle rectangle) + { + if (pictureBox1.Image != null) + { + pictureBox1.Image.Dispose(); + } + + pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); + using (Graphics g = Graphics.FromImage(pictureBox1.Image)) + { + g.Clear(Color.White); // + rectangle.Draw(g); + } + + pictureBox1.Refresh(); // PictureBox + } + else + { + MessageBox.Show(", ."); + } + } } + + + } \ No newline at end of file diff --git a/Final/Final/Properties/Resources.Designer.cs b/Final/Final/Properties/Resources.Designer.cs new file mode 100644 index 0000000..a880488 --- /dev/null +++ b/Final/Final/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Final.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Final.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Final/Final/Properties/Resources.resx b/Final/Final/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Final/Final/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Final/Final/Rectangle.cs b/Final/Final/Rectangle.cs new file mode 100644 index 0000000..69988b8 --- /dev/null +++ b/Final/Final/Rectangle.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Final +{ + public class Rectangle + { + public int Width { get; set; } + public int Height { get; set; } + public Point Position { get; set; } + + public Rectangle(int width, int height, Point position) + { + Width = width; + Height = height; + Position = position; + } + + public virtual void Draw(Graphics g) + { + g.DrawRectangle(Pens.Black, Position.X, Position.Y, Width, Height); + } + } +} diff --git a/Final/Final/RectangleWithOval.cs b/Final/Final/RectangleWithOval.cs new file mode 100644 index 0000000..1aea97d --- /dev/null +++ b/Final/Final/RectangleWithOval.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Final +{ + public class RectangleWithOval : Rectangle + { + public Color OvalColor { get; set; } + + public RectangleWithOval(int width, int height, Point position, Color color) + : base(width, height, position) + { + OvalColor = color; + } + + public override void Draw(Graphics g) + { + base.Draw(g); + using (Brush brush = new SolidBrush(OvalColor)) + { + g.FillEllipse(brush, Position.X, Position.Y, Width, Height); + } + } + + } +}