Загрузка данных


using System;
using System.Drawing;
using System.Windows.Forms;

namespace ПлотниковТоросян
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // Обработчик загрузки формы (настраиваем текст при запуске)
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Извлечение квадратного корня";
            button1.Text = "Извлечь корень";
            textBox1.Clear(); 
            label1.Text = ""; 
        }

        // Обработчик нажатия на кнопку
        private void button1_Click(object sender, EventArgs e)
        {
            double num;
            // Проверяем, ввел ли пользователь число
            bool isNum = double.TryParse(textBox1.Text, out num);

            if (isNum == false)
            {
                // Если введено не число - выводим ошибку красным цветом
                label1.Text = "Следует вводить числа";
                label1.ForeColor = Color.Red;
                return; // Выходим из метода, чтобы не считать корень
            }

            // Если число введено верно, считаем корень
            double rez = Math.Sqrt(num);
            
            // Возвращаем черный цвет тексту
            label1.ForeColor = Color.Black;
            
            // Формируем строку ответа
            label1.Text = $"Корень из {num} равен {rez}";
        }
    }
}



namespace ПлотниковТоросян
{
    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.textBox1 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(50, 50);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(200, 20);
            this.textBox1.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(50, 90);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "label1";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(50, 130);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(100, 30);
            this.button1.TabIndex = 2;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(350, 250);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button1;
    }
}