📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ForNextExample
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblMeter;
private System.Windows.Forms.Button btnForNext;
private System.Windows.Forms.Button btnDoLoop;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources 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 Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblMeter = new System.Windows.Forms.Label();
this.btnForNext = new System.Windows.Forms.Button();
this.btnDoLoop = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblMeter
//
this.lblMeter.BackColor = System.Drawing.Color.Blue;
this.lblMeter.Location = new System.Drawing.Point(100, 100);
this.lblMeter.Name = "lblMeter";
this.lblMeter.Size = new System.Drawing.Size(100, 17);
this.lblMeter.TabIndex = 0;
//
// btnForNext
//
this.btnForNext.Location = new System.Drawing.Point(88, 125);
this.btnForNext.Name = "btnForNext";
this.btnForNext.Size = new System.Drawing.Size(125, 23);
this.btnForNext.TabIndex = 1;
this.btnForNext.Text = "Run a For Loop";
this.btnForNext.Click += new System.EventHandler(this.btnForNext_Click);
//
// btnDoLoop
//
this.btnDoLoop.Location = new System.Drawing.Point(88, 160);
this.btnDoLoop.Name = "btnDoLoop";
this.btnDoLoop.Size = new System.Drawing.Size(125, 23);
this.btnDoLoop.TabIndex = 2;
this.btnDoLoop.Text = "Run a Do Loop";
this.btnDoLoop.Click += new System.EventHandler(this.btnDoLoop_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnDoLoop,
this.btnForNext,
this.lblMeter});
this.Name = "Form1";
this.Text = "For Statement Example";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnForNext_Click(object sender, System.EventArgs e)
{
for (int intLabelWidth=1; intLabelWidth<=100; intLabelWidth++)
{
lblMeter.Width = intLabelWidth;
lblMeter.Refresh();
for (long lngPauseCounter=1; lngPauseCounter<=600000; lngPauseCounter++);
}
}
private void btnDoLoop_Click(object sender, System.EventArgs e)
{
int intLabelWidth=1;
while (intLabelWidth != 100)
{
lblMeter.Width = intLabelWidth;
lblMeter.Refresh();
intLabelWidth++;
for (long lngPauseCounter=1; lngPauseCounter<=600000; lngPauseCounter++);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -