第四章 方法和数组 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";
}
}
}
}
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";
}
}
}
}
相关文章推荐
- 第四章 分治策略 4.1 最大子数组问题 (暴力求解算法)
- 第四章 分治策略 4.1 最大子数组问题 (暴力求解算法)
- java byte数组与int,long,short,byte的转换实现方法
- Java替换int数组中重复数据的方法示例
- Java 8中的long, int, short, char 转byte数组方法
- Java基础-第四章(方法和数组)
- 数据类型int跟byte[]数组互转的方法!
- MyBatis-xml配置SQL文件中,传入List数组、基本类型String、int……、与自定义类型的方法
- 一个用来快速生成指定大小的随机不重复int数组的实用方法
- ArrayCopy方法int数组、String数组使用实例
- string[]数组转为int[]数组方法
- java 从int数组中获取最大数的方法
- 读取文件内容到int数组的函数处理方法
- JAVA将 带有空格或特殊字符的字符串转换成int数组的方法
- 将int数组与字符串中的数字互转的方法
- java编程:输入int数组的方法二(知道长度)
- java中将Object转换成 String类型和int类型的方法 和Object数组转换成String数组的方法
- string转int/float/double、int/float/double转string、转字符串数组的方法:stoi、stringstream、scanf、to_string、sprintf
- int数组转化成List<Integer>简便的方法
- 第四章 分治策略 4.1 最大子数组问题(自己想的,不知道是不是减治法)