This commit is contained in:
Anastasia Yazykova 2024-07-04 03:45:28 +04:00
parent a7254b9c40
commit 5f97ca592c
3 changed files with 137 additions and 1 deletions

26
Final/Final/Calculator.cs Normal file
View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Final
{
public class Calculator
{
public int Sum(int a, int b)
{
return a + b;
}
public int Sum(int a, int b, int c)
{
return a + b + c;
}
public double Sum(double a, double b)
{
return a + b;
}
}
}

View File

@ -46,12 +46,19 @@ namespace Final
listBox2 = new ListBox();
pictureBox1 = new PictureBox();
tabPage3 = new TabPage();
w = new Label();
textBox6 = new TextBox();
textBox5 = new TextBox();
textBox4 = new TextBox();
button8 = new Button();
colorDialog = new ColorDialog();
colorDialog1 = new ColorDialog();
textBox2 = new TextBox();
tabControl1.SuspendLayout();
tabPage1.SuspendLayout();
tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
tabPage3.SuspendLayout();
SuspendLayout();
//
// tabControl1
@ -211,6 +218,12 @@ namespace Final
//
// tabPage3
//
tabPage3.Controls.Add(textBox2);
tabPage3.Controls.Add(w);
tabPage3.Controls.Add(textBox6);
tabPage3.Controls.Add(textBox5);
tabPage3.Controls.Add(textBox4);
tabPage3.Controls.Add(button8);
tabPage3.Location = new Point(4, 34);
tabPage3.Name = "tabPage3";
tabPage3.Padding = new Padding(3);
@ -219,6 +232,54 @@ namespace Final
tabPage3.Text = "tabPage3";
tabPage3.UseVisualStyleBackColor = true;
//
// w
//
w.AutoSize = true;
w.Location = new Point(474, 462);
w.Name = "w";
w.Size = new Size(59, 25);
w.TabIndex = 9;
w.Text = "label1";
//
// textBox6
//
textBox6.Location = new Point(816, 152);
textBox6.Name = "textBox6";
textBox6.Size = new Size(150, 31);
textBox6.TabIndex = 8;
//
// textBox5
//
textBox5.Location = new Point(404, 152);
textBox5.Name = "textBox5";
textBox5.Size = new Size(150, 31);
textBox5.TabIndex = 7;
//
// textBox4
//
textBox4.Location = new Point(48, 152);
textBox4.Name = "textBox4";
textBox4.Size = new Size(150, 31);
textBox4.TabIndex = 6;
textBox4.TextChanged += textBox4_TextChanged;
//
// button8
//
button8.Location = new Point(454, 324);
button8.Name = "button8";
button8.Size = new Size(112, 34);
button8.TabIndex = 1;
button8.Text = "button8";
button8.UseVisualStyleBackColor = true;
button8.Click += button8_Click;
//
// textBox2
//
textBox2.Location = new Point(610, 456);
textBox2.Name = "textBox2";
textBox2.Size = new Size(150, 31);
textBox2.TabIndex = 10;
//
// Form1
//
AutoScaleDimensions = new SizeF(10F, 25F);
@ -233,6 +294,8 @@ namespace Final
tabPage2.ResumeLayout(false);
tabPage2.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
tabPage3.ResumeLayout(false);
tabPage3.PerformLayout();
ResumeLayout(false);
}
@ -256,5 +319,11 @@ namespace Final
private Button button6;
private Label l;
private ColorDialog colorDialog1;
private TextBox textBox6;
private TextBox textBox5;
private TextBox textBox4;
private Button button8;
private Label w;
private TextBox textBox2;
}
}

View File

@ -1,5 +1,6 @@
using System.Drawing;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
namespace Final
@ -60,7 +61,7 @@ namespace Final
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);
listBox2.Items.Add(rectangleWithOval);
}
else
{
@ -118,6 +119,46 @@ namespace Final
}
}
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
}
private void button8_Click(object sender, EventArgs e)
{
Calculator calculator = new Calculator();
if (int.TryParse(textBox4.Text, out int number1) &&
int.TryParse(textBox5.Text, out int number2))
{
if (int.TryParse(textBox6.Text, out int number3))
{
int result = calculator.Sum(number1, number2, number3);
textBox2.Text = $"Sum: {result}";
}
else
{
int result = calculator.Sum(number1, number2);
textBox2.Text = $"Sum: {result}";
}
}
else if (double.TryParse(textBox4.Text, out double doubleNumber1) &&
double.TryParse(textBox5.Text, out double doubleNumber2))
{
double result = calculator.Sum(doubleNumber1, doubleNumber2);
textBox2.Text = $"Sum (double): {result}";
}
else
{
textBox2.Text = "Invalid input";
}
}
}