Загрузка данных
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.tabPageKub = new System.Windows.Forms.TabPage();
this.btnClearKub = new System.Windows.Forms.Button();
this.btnCalcKub = new System.Windows.Forms.Button();
this.txtResultKub = new System.Windows.Forms.TextBox();
this.labelResultKub = new System.Windows.Forms.Label();
this.txtSide = new System.Windows.Forms.TextBox();
this.labelSide = new System.Windows.Forms.Label();
this.tabPageCilindr = new System.Windows.Forms.TabPage();
this.btnClearCil = new System.Windows.Forms.Button();
this.btnCalcCil = new System.Windows.Forms.Button();
this.txtResultCil = new System.Windows.Forms.TextBox();
this.labelResultCil = new System.Windows.Forms.Label();
this.txtHeight = new System.Windows.Forms.TextBox();
this.labelHeight = new System.Windows.Forms.Label();
this.txtRadius = new System.Windows.Forms.TextBox();
this.labelRadius = new System.Windows.Forms.Label();
this.tabControl1.SuspendLayout();
this.tabPageKub.SuspendLayout();
this.tabPageCilindr.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPageKub);
this.tabControl1.Controls.Add(this.tabPageCilindr);
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(600, 450);
this.tabControl1.TabIndex = 0;
//
// tabPageKub
//
this.tabPageKub.Controls.Add(this.btnClearKub);
this.tabPageKub.Controls.Add(this.btnCalcKub);
this.tabPageKub.Controls.Add(this.txtResultKub);
this.tabPageKub.Controls.Add(this.labelResultKub);
this.tabPageKub.Controls.Add(this.txtSide);
this.tabPageKub.Controls.Add(this.labelSide);
this.tabPageKub.Location = new System.Drawing.Point(4, 22);
this.tabPageKub.Name = "tabPageKub";
this.tabPageKub.Padding = new System.Windows.Forms.Padding(3);
this.tabPageKub.Size = new System.Drawing.Size(592, 424);
this.tabPageKub.TabIndex = 0;
this.tabPageKub.Text = "Куб";
this.tabPageKub.UseVisualStyleBackColor = true;
//
// btnClearKub
//
this.btnClearKub.Location = new System.Drawing.Point(30, 200);
this.btnClearKub.Name = "btnClearKub";
this.btnClearKub.Size = new System.Drawing.Size(120, 30);
this.btnClearKub.TabIndex = 5;
this.btnClearKub.Text = "Очистить";
this.btnClearKub.UseVisualStyleBackColor = true;
this.btnClearKub.Click += new System.EventHandler(this.btnClearKub_Click);
//
// btnCalcKub
//
this.btnCalcKub.Location = new System.Drawing.Point(30, 160);
this.btnCalcKub.Name = "btnCalcKub";
this.btnCalcKub.Size = new System.Drawing.Size(120, 30);
this.btnCalcKub.TabIndex = 4;
this.btnCalcKub.Text = "Вычислить";
this.btnCalcKub.UseVisualStyleBackColor = true;
this.btnCalcKub.Click += new System.EventHandler(this.btnCalcKub_Click);
//
// txtResultKub
//
this.txtResultKub.Location = new System.Drawing.Point(200, 60);
this.txtResultKub.Multiline = true;
this.txtResultKub.Name = "txtResultKub";
this.txtResultKub.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResultKub.Size = new System.Drawing.Size(350, 330);
this.txtResultKub.TabIndex = 3;
//
// labelResultKub
//
this.labelResultKub.AutoSize = true;
this.labelResultKub.Location = new System.Drawing.Point(197, 40);
this.labelResultKub.Name = "labelResultKub";
this.labelResultKub.Size = new System.Drawing.Size(59, 13);
this.labelResultKub.TabIndex = 2;
this.labelResultKub.Text = "Результат:";
//
// txtSide
//
this.txtSide.Location = new System.Drawing.Point(120, 80);
this.txtSide.Name = "txtSide";
this.txtSide.Size = new System.Drawing.Size(50, 20);
this.txtSide.TabIndex = 1;
this.txtSide.Text = "0";
this.txtSide.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// labelSide
//
this.labelSide.AutoSize = true;
this.labelSide.Location = new System.Drawing.Point(30, 83);
this.labelSide.Name = "labelSide";
this.labelSide.Size = new System.Drawing.Size(71, 13);
this.labelSide.TabIndex = 0;
this.labelSide.Text = "Сторона a м:";
//
// tabPageCilindr
//
this.tabPageCilindr.Controls.Add(this.btnClearCil);
this.tabPageCilindr.Controls.Add(this.btnCalcCil);
this.tabPageCilindr.Controls.Add(this.txtResultCil);
this.tabPageCilindr.Controls.Add(this.labelResultCil);
this.tabPageCilindr.Controls.Add(this.txtHeight);
this.tabPageCilindr.Controls.Add(this.labelHeight);
this.tabPageCilindr.Controls.Add(this.txtRadius);
this.tabPageCilindr.Controls.Add(this.labelRadius);
this.tabPageCilindr.Location = new System.Drawing.Point(4, 22);
this.tabPageCilindr.Name = "tabPageCilindr";
this.tabPageCilindr.Padding = new System.Windows.Forms.Padding(3);
this.tabPageCilindr.Size = new System.Drawing.Size(592, 424);
this.tabPageCilindr.TabIndex = 1;
this.tabPageCilindr.Text = "Цилиндр";
this.tabPageCilindr.UseVisualStyleBackColor = true;
//
// btnClearCil
//
this.btnClearCil.Location = new System.Drawing.Point(30, 220);
this.btnClearCil.Name = "btnClearCil";
this.btnClearCil.Size = new System.Drawing.Size(120, 30);
this.btnClearCil.TabIndex = 7;
this.btnClearCil.Text = "Очистить";
this.btnClearCil.UseVisualStyleBackColor = true;
this.btnClearCil.Click += new System.EventHandler(this.btnClearCil_Click);
//
// btnCalcCil
//
this.btnCalcCil.Location = new System.Drawing.Point(30, 180);
this.btnCalcCil.Name = "btnCalcCil";
this.btnCalcCil.Size = new System.Drawing.Size(120, 30);
this.btnCalcCil.TabIndex = 6;
this.btnCalcCil.Text = "Вычислить";
this.btnCalcCil.UseVisualStyleBackColor = true;
this.btnCalcCil.Click += new System.EventHandler(this.btnCalcCil_Click);
//
// txtResultCil
//
this.txtResultCil.Location = new System.Drawing.Point(200, 60);
this.txtResultCil.Multiline = true;
this.txtResultCil.Name = "txtResultCil";
this.txtResultCil.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResultCil.Size = new System.Drawing.Size(350, 330);
this.txtResultCil.TabIndex = 5;
//
// labelResultCil
//
this.labelResultCil.AutoSize = true;
this.labelResultCil.Location = new System.Drawing.Point(197, 40);
this.labelResultCil.Name = "labelResultCil";
this.labelResultCil.Size = new System.Drawing.Size(59, 13);
this.labelResultCil.TabIndex = 4;
this.labelResultCil.Text = "Результат:";
//
// txtHeight
//
this.txtHeight.Location = new System.Drawing.Point(120, 120);
this.txtHeight.Name = "txtHeight";
this.txtHeight.Size = new System.Drawing.Size(50, 20);
this.txtHeight.TabIndex = 3;
this.txtHeight.Text = "0";
this.txtHeight.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// labelHeight
//
this.labelHeight.AutoSize = true;
this.labelHeight.Location = new System.Drawing.Point(30, 123);
this.labelHeight.Name = "labelHeight";
this.labelHeight.Size = new System.Drawing.Size(68, 13);
this.labelHeight.TabIndex = 2;
this.labelHeight.Text = "Высота h м:";
//
// txtRadius
//
this.txtRadius.Location = new System.Drawing.Point(120, 80);
this.txtRadius.Name = "txtRadius";
this.txtRadius.Size = new System.Drawing.Size(50, 20);
this.txtRadius.TabIndex = 1;
this.txtRadius.Text = "0";
this.txtRadius.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// labelRadius
//
this.labelRadius.AutoSize = true;
this.labelRadius.Location = new System.Drawing.Point(30, 83);
this.labelRadius.Name = "labelRadius";
this.labelRadius.Size = new System.Drawing.Size(70, 13);
this.labelRadius.TabIndex = 0;
this.labelRadius.Text = "Радиус r м:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(600, 450);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Вычисление";
this.tabControl1.ResumeLayout(false);
this.tabPageKub.ResumeLayout(false);
this.tabPageKub.PerformLayout();
this.tabPageCilindr.ResumeLayout(false);
this.tabPageCilindr.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPageKub;
private System.Windows.Forms.TabPage tabPageCilindr;
private System.Windows.Forms.TextBox txtSide;
private System.Windows.Forms.Label labelSide;
private System.Windows.Forms.TextBox txtResultKub;
private System.Windows.Forms.Label labelResultKub;
private System.Windows.Forms.Button btnCalcKub;
private System.Windows.Forms.Button btnClearKub;
private System.Windows.Forms.TextBox txtResultCil;
private System.Windows.Forms.Label labelResultCil;
private System.Windows.Forms.TextBox txtHeight;
private System.Windows.Forms.Label labelHeight;
private System.Windows.Forms.TextBox txtRadius;
private System.Windows.Forms.Label labelRadius;
private System.Windows.Forms.Button btnCalcCil;
private System.Windows.Forms.Button btnClearCil;
}
}
using System;
using System.Windows.Forms;
namespace figuri
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Аналог Команда1 (Вычислить для Куба)
private void btnCalcKub_Click(object sender, EventArgs e)
{
// Пытаемся преобразовать текст в число
if (!double.TryParse(txtSide.Text, out double storona))
{
MessageBox.Show("Введите корректное число для стороны куба!");
return;
}
if (storona == 0)
{
MessageBox.Show("Сторона куба не может быть равна нулю!");
txtResultKub.Text = "Сторона куба не может быть равна нулю!";
return;
}
double ploshad = storona * storona;
double ploshad2 = 6 * storona * storona;
double obem = storona * storona * storona;
txtResultKub.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 (Очистить для Куба)
private void btnClearKub_Click(object sender, EventArgs e)
{
txtResultKub.Text = "";
txtSide.Text = "0";
}
// Аналог Команда3 (Вычислить для Цилиндра)
private void btnCalcCil_Click(object sender, EventArgs e)
{
if (!double.TryParse(txtRadius.Text, out double radius) ||
!double.TryParse(txtHeight.Text, out double height))
{
MessageBox.Show("Введите корректные числа для радиуса и высоты!");
return;
}
if (radius == 0)
{
MessageBox.Show("Радиус не может быть равен нулю!");
txtResultCil.Text = "Радиус не может быть равен нулю!";
return;
}
if (height == 0)
{
MessageBox.Show("Высота не может быть равна нулю!");
txtResultCil.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);
txtResultCil.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 (Очистить для Цилиндра)
private void btnClearCil_Click(object sender, EventArgs e)
{
txtResultCil.Text = "";
txtRadius.Text = "0";
txtHeight.Text = "0";
}
}
}