📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WinApp9_13统计成绩
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 24);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(62, 24);
this.label2.TabIndex = 2;
this.label2.Text = "label2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(16, 152);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(62, 24);
this.label3.TabIndex = 3;
this.label3.Text = "label3";
//
// listBox1
//
this.listBox1.ColumnWidth = 80;
this.listBox1.ItemHeight = 18;
this.listBox1.Location = new System.Drawing.Point(16, 40);
this.listBox1.MultiColumn = true;
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(528, 76);
this.listBox1.TabIndex = 4;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(10, 21);
this.ClientSize = new System.Drawing.Size(592, 184);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Text="成绩统计";
label2.Text="各科总分:";
label3.Text="总平均分:";
string [ ]name=new string[4]{"张三","李四","王五","赵六"};
double [ ,] grade=new double[4,3]{{78,96.5,75}
,{85,75,96}
,{99,89,88}
,{69,72,80}};
double [ ]sum=new double[4];
double [ ]total=new double[3];
label1.Text="姓名 语文 数学 物理 总分";
for(int i=0;i<4;i=i+1)
{
listBox1.Items.Add(name[i].ToString( ));
for(int j=0;j<3;j=j+1)
{
sum[i]=sum[i]+grade[i,j];
total[j]=total[j]+grade[i,j];
}
}
label3.Text+=Convert.ToString((sum[0]+sum[1]+sum[2]+sum[3])/4);
// Shutdown the painting of the ListBox as items are added.
listBox1.BeginUpdate();
// Loop through and add 50 items to the ListBox.
for (int i = 0; i<3; i++)
{
for(int j=0;j<4;j++)
listBox1.Items.Add(grade[j,i].ToString());
}
for(int i=0;i<sum.Length;i=i+1)
listBox1.Items.Add(sum[i].ToString());
// Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate();
for(int i=0;i<total.Length;i=i+1)
label2.Text+=total[i]+" ";
// Select three items from the ListBox.
//listBox1.SetSelected(1, true);
//listBox1.SetSelected(3, true);
//listBox1.SetSelected(5, true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -