Чтение онлайн

ЖАНРЫ

C# для профессионалов. Том II

Ватсон Карли

Шрифт:

/// </summary>

private void InitializeComponent {

this.txtNumber = new System.Windows.Forms.TextBox;

this.txtSign = new System.Windows.Forms.TextBox;

this.cmdShowResults = new System.Windows.Forms.Button;

this.label3 = new System.Windows.Forms.Label;

this.label4 = new System.Windows.Forms.Label;

this.label1 = new System.Windows.Forms.Label;

this.label2 = new System.Windows.Forms.Label;

this.txtResult = new System.Windows.Forms.TextBox;

this.SuspendLayout;

//

// txtNumber

//

this.txtNumber.Location = new System.Drawing.Point(160, 24);

this.txtNumber.Name = "txtNumber";

this.txtNumber.TabIndex = 0;

this.txtNumber.Text = "";

//

// txtSign

//

this.txtSign.Enabled = false;

this.txtSign.Location = new System.Drawing.Point(160, 136);

this.txtSign.Name = "txtSign";

this.tхtSign.TabIndех = 1;

this.txtSign.Text = "";

//

// cmdShowResults

//

this.cmdShowResults.Location = new System.Drawing.Point(24, 96);

this.cmdShowResults.Name = "cmdShowResults";

this.cmdShowResults.Size = new System.Drawing.Size(88, 23);

this.cmdShowResults.TabIndex = 3;

this.cmdShowResults.Text = "Show Results";

this.cmdShowResults.Click +=

new System.EventHandler(this.OnClickShowResults);

//

// label3

//

this.label3.Location = new System.Drawing.Point(72, 24);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(80, 23);

this.label3.TabIndex = 6;

this.label3.Text = "Input a number";

//

// label4

//

this.label4.Location = new System.Drawing.Point(80, 184);

this.label4.Name = "label4";

this.label4.Size = new System.Drawing.Size(80, 16);

this.label4.TabIndex = 7;

this.label4.Text = "Square root is";

//

// label1

//

this.label1.Location = new System.Drawing.Point(112, 136);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(40, 23);

this.label1.TabIndex = 4;

this.label1.Text = "Sign is";

//

// label2

//

this.label2.Location = new System.Drawing.Point(48, 184);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(8, 8);

this.label2.TabIndex = 5;

//

// txtResult

//

this.txtResult.Enabled = false;

this.txtResult.Location = new System.Drawing.Point(160, 184);

this.txtResult.Name = "txtResult";

this.txtResult.TabIndex = 2;

this.txtResult.Text = "";

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 269);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.label4, this.label3, this.label2, this.label1,

this.cmdShowResults, this.txtResult, this.txtSign, this.txtNumber

});

this.Name = "Form1";

this.Text = "Square Root C# Sample";

this.ResumeLayout(false);

}

#endregion

/// <summary>

///
Обработчик событий для нажатия пользователем кнопки Show Results

/// Выводит квадратный корень и знак числа

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void OnClickShowResults(object sender, System.EventArgs e) {

float NumberInput = float.Parse(this.txtNumber.Text);

if (NumberInput < 0) {

this.txtSign.Text = "Negative";

this.txtResult.Text = Math.Sqrt(-NumberInput) + " i";

} else if (NumberInput == 0) {

txtSign.Text = "Zero";

txtResult.Text = "0";

} else {

this.txtSign.Text = "Positive";

this.txtResult.Text = Math.Sqrt(NumberInput).ToString;

}

}

 }

 class MainEntryClass {

/// <summary>

/// Основная точка входа приложения.

Поделиться с друзьями: