您的位置:首页 > 其它

第四章 方法和数组 Fig 4.1 SquareInt.cs

2009-04-21 19:03 148 查看
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace SquareInt
{
/// <summary>
/// summary description fro SquareInt.
/// </summary>
public class SquareInt :System.Windows.Forms.Form
{
private System.Windows.Forms.Button calculateButton;
private System.Windows.Forms.Label outputLabel;
///<summary>
///Required descriptioin variable
///</summary>
private System.ComponentModel.Container components = null;

public SquareInt()
{
//
// required for windows form designer support
//
InitializeComponent();
}
/// <summary>
///Clean up any resource being used
///</summary>
protected override void Dispose( bool disposing )
{
if(disposing)
{
if( components != null )
{
components.Dispose();

}

}
base.Dispose(disposing);

}
# region Windows Form Designer generated code

///<summary>
///required method for description of suport
///</summary>
private void InitializeComponent()
{
this.calculateButton =
new System.Windows.Forms.Button();
this.outputLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// calculateButton
//
this.calculateButton.Location =
new System.Drawing.Point(32, 8);
this.calculateButton.Name = "CalculateButton";
this.calculateButton.Size =
new System.Drawing.Size(120, 23);
this.calculateButton.TabIndex = 0;
this.calculateButton.Text ="Calculate Squares";
this.calculateButton.Click +=
new System.EventHandler(this.calculateButton_Click);
//
//outputLable
//
this.outputLabel.Location=
new System.Drawing.Point(16, 48);
this.outputLabel.Name ="outputLable";
this.outputLabel.Size =
new System.Drawing.Size(152,144);
this.outputLabel.TabIndex = 1;
//
// Square Int
//
this.AutoScaleBaseSize =
new System.Drawing.Size(5, 13);
this.ClientSize =
new System.Drawing.Size(184,197);
this.Controls.AddRange(
new System.Windows.Forms.Control[] {
this.outputLabel,
this.calculateButton});
this.Name = "SquareInt";
this.Text = "SquareInt";
this.ResumeLayout(false);

}
#endregion
///<summary>
///the main entry point for the application
///</summary>

[STAThread]
static void Main()
{
Application.Run( new SquareInt());
}
// Square method definition

int Square( int y)
{
return y*y;
}

private void calculateButton_Click(
object sender , System.EventArgs e)
{
outputLabel.Text = "";

// loop 10 times
for (int counter = 1; counter <= 10; counter++)
{
int result = Square(counter);

outputLabel.Text += " The square of " + counter + "is " +result + "/n";

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: