C# 怎么编 急救!!

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:24:28
刚学的
它没还没介绍弄按钮这种已经要建WINDOWS APPLICATIONG的程序了
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class SquareInt : System.Windows.Forms.Form
{
private System.Windows.Forms.Button calculateButton;
private System.Windows.Forms.Label outputLabel;

// Visual Studio .NET generated code
[STAThread]
static void Main()
{
Application.Run( new SquareInt() );
}

// Square method definition
int Square( int y )
{
return y * y; // return square of y

} // end method Square

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

// loop 10 times
for ( int counter = 1; counter <= 10; counter++ )
{
// calculate square of counter and store in result

建一个windows窗体的项目,按钮(Name属性设为calculateButton) label(Name属性设为outputLabel)这种需要自己拖进来
双击按钮进入代码编辑窗口输入private void calculateButton_Click( object sender, System.EventArgs e ) (系统自动产生的)
{
outputLabel.Text = "";

// loop 10 times
for ( int counter = 1; counter <= 10; counter++ )
{
// calculate square of counter and store in result
int result = Square( counter );

// append result to outputLabel
outputLabel.Text += "The square of " + counter +
" is " + result + "\n";
}

} // end method calculateButton_Click

在下面输入

// Square method definition
int Square( int y )
{
return y * y; // return square of y

} // end method Square

这样就OK了

如果你用vs2005 的话
1:简单了 新建一个 windows窗体的项目
2:calculateButton_Click 这应该是单击事件 双击Button 代码写在里面
label 需要自已拖

当然要新建个项目 需要的按扭需要自己拖 要在哪一个按扭中输入语言 直接双击就OK了