Загрузка данных
namespace figuri
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(584, 461);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button2);
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Controls.Add(this.textBox2);
this.tabPage1.Controls.Add(this.label2);
this.tabPage1.Controls.Add(this.textBox1);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(576, 435);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Куб";
this.tabPage1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Location = new System.Drawing.Point(30, 200);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 30);
this.button2.TabIndex = 5;
this.button2.Text = "Очистить";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(30, 160);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 30);
this.button1.TabIndex = 4;
this.button1.Text = "Вычислить";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(200, 60);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox2.Size = new System.Drawing.Size(350, 330);
this.textBox2.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(197, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Результат:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 80);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(50, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "0";
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(30, 83);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Сторона a м:";
//
// tabPage2
//
this.tabPage2.Controls.Add(this.button4);
this.tabPage2.Controls.Add(this.button3);
this.tabPage2.Controls.Add(this.textBox5);
this.tabPage2.Controls.Add(this.label5);
this.tabPage2.Controls.Add(this.textBox4);
this.tabPage2.Controls.Add(this.label4);
this.tabPage2.Controls.Add(this.textBox3);
this.tabPage2.Controls.Add(this.label3);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(576, 435);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Цилиндр";
this.tabPage2.UseVisualStyleBackColor = true;
//
// button4
//
this.button4.Location = new System.Drawing.Point(30, 220);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(120, 30);
this.button4.TabIndex = 7;
this.button4.Text = "Очистить";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(30, 180);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(120, 30);
this.button3.TabIndex = 6;
this.button3.Text = "Вычислить";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(200, 60);
this.textBox5.Multiline = true;
this.textBox5.Name = "textBox5";
this.textBox5.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox5.Size = new System.Drawing.Size(350, 330);
this.textBox5.TabIndex = 5;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(197, 40);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(59, 13);
this.label5.TabIndex = 4;
this.label5.Text = "Результат:";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(120, 120);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(50, 20);
this.textBox4.TabIndex = 3;
this.textBox4.Text = "0";
this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(30, 123);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(68, 13);
this.label4.TabIndex = 2;
this.label4.Text = "Высота h м:";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(120, 80);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(50, 20);
this.textBox3.TabIndex = 1;
this.textBox3.Text = "0";
this.textBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(30, 83);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(70, 13);
this.label3.TabIndex = 0;
this.label3.Text = "Радиус r м:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 461);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Вычисление";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label5;
}
}
using System;
using System.Windows.Forms;
namespace figuri
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Аналог Команда1 (Вычислить для Куба)
// button1 - кнопка "Вычислить"
// textBox1 - поле ввода стороны
// textBox2 - поле вывода результата
private void button1_Click(object sender, EventArgs e)
{
if (!double.TryParse(textBox1.Text, out double storona))
{
MessageBox.Show("Введите корректное число для стороны куба!");
return;
}
if (storona == 0)
{
MessageBox.Show("Сторона куба не может быть равна нулю!");
textBox2.Text = "Сторона куба не может быть равна нулю!";
return;
}
double ploshad = storona * storona;
double ploshad2 = 6 * storona * storona;
double obem = storona * storona * storona;
textBox2.Text = "Входные данные:"
+ Environment.NewLine + "Сторона куба a = " + storona + " м"
+ Environment.NewLine
+ Environment.NewLine + "Площадь S одной грани = a*a = " + storona + "*" + storona + " = " + ploshad + " м²"
+ Environment.NewLine + "Площадь S полной поверхности = 6*a*a = 6*" + storona + "*" + storona + " = " + ploshad2 + " м²"
+ Environment.NewLine + "Объём V = a*a*a = " + storona + "*" + storona + "*" + storona + " = " + obem + " м³"
+ Environment.NewLine
+ Environment.NewLine + "Результаты:"
+ Environment.NewLine + "Площадь грани куба = " + ploshad + " м²"
+ Environment.NewLine + "Площадь полной поверхности куба = " + ploshad2 + " м²"
+ Environment.NewLine + "Объём куба = " + obem + " м³";
}
// Аналог Команда2 (Очистить для Куба)
// button2 - кнопка "Очистить"
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = "";
textBox1.Text = "0";
}
// Аналог Команда3 (Вычислить для Цилиндра)
// button3 - кнопка "Вычислить"
// textBox3 - поле ввода радиуса
// textBox4 - поле ввода высоты
// textBox5 - поле вывода результата
private void button3_Click(object sender, EventArgs e)
{
if (!double.TryParse(textBox3.Text, out double radius) ||
!double.TryParse(textBox4.Text, out double height))
{
MessageBox.Show("Введите корректные числа для радиуса и высоты!");
return;
}
if (radius == 0)
{
MessageBox.Show("Радиус не может быть равен нулю!");
textBox5.Text = "Радиус не может быть равен нулю!";
return;
}
if (height == 0)
{
MessageBox.Show("Высота не может быть равна нулю!");
textBox5.Text = "Высота не может быть равна нулю!";
return;
}
double pi = 3.14159;
// Точные значения
double ploshadBokTochn = 2 * pi * radius * height;
double ploshadOsnTochn = pi * radius * radius;
double ploshadPolnTochn = 2 * pi * radius * height + 2 * pi * radius * radius;
double obemTochn = pi * radius * radius * height;
// Округленные значения (аналог функции Окр в 1С)
double ploshadBok = Math.Round(ploshadBokTochn, 0, MidpointRounding.AwayFromZero);
double ploshadOsn = Math.Round(ploshadOsnTochn, 0, MidpointRounding.AwayFromZero);
double ploshadPoln = Math.Round(ploshadPolnTochn, 0, MidpointRounding.AwayFromZero);
double obem = Math.Round(obemTochn, 0, MidpointRounding.AwayFromZero);
textBox5.Text = "Входные данные:"
+ Environment.NewLine + "Радиус r = " + radius + " м"
+ Environment.NewLine + "Высота h = " + height + " м"
+ Environment.NewLine
+ Environment.NewLine + "Площадь боковой поверхности Sбок = 2πrh = 2*" + pi + "*" + radius + "*" + height + " = " + ploshadBokTochn + " м²"
+ Environment.NewLine + "Площадь основания Sосн = πr² = " + pi + "*" + radius + "*" + radius + " = " + ploshadOsnTochn + " м²"
+ Environment.NewLine + "Площадь полной поверхности Sполн = 2πrh + 2πr² = " + ploshadPolnTochn + " м²"
+ Environment.NewLine + "Объём V = πr²h = " + pi + "*" + radius + "*" + radius + "*" + height + " = " + obemTochn + " м³"
+ Environment.NewLine
+ Environment.NewLine + "Результаты:"
+ Environment.NewLine + "Площадь боковой поверхности = " + ploshadBok + " м²"
+ Environment.NewLine + "Площадь основания = " + ploshadOsn + " м²"
+ Environment.NewLine + "Площадь полной поверхности = " + ploshadPoln + " м²"
+ Environment.NewLine + "Объём цилиндра = " + obem + " м³";
}
// Аналог Команда4 (Очистить для Цилиндра)
// button4 - кнопка "Очистить"
private void button4_Click(object sender, EventArgs e)
{
textBox5.Text = "";
textBox3.Text = "0";
textBox4.Text = "0";
}
}
}