📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace youxi
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Timers.Timer timer1;
private System.Windows.Forms.Label lblTitle;
private System.Windows.Forms.Label lblLocation;
private System.Windows.Forms.Label lblDorection;
private System.Windows.Forms.Label lblMsg;
bool runLeft=true;
/// <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.lblTitle = new System.Windows.Forms.Label();
this.lblLocation = new System.Windows.Forms.Label();
this.lblDorection = new System.Windows.Forms.Label();
this.lblMsg = new System.Windows.Forms.Label();
this.timer1 = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
this.SuspendLayout();
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.BackColor = System.Drawing.Color.Red;
this.lblTitle.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lblTitle.ForeColor = System.Drawing.Color.Blue;
this.lblTitle.Location = new System.Drawing.Point(0, 8);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(176, 40);
this.lblTitle.TabIndex = 0;
this.lblTitle.Text = "跑马灯实例";
//
// lblLocation
//
this.lblLocation.AutoSize = true;
this.lblLocation.Location = new System.Drawing.Point(8, 88);
this.lblLocation.Name = "lblLocation";
this.lblLocation.Size = new System.Drawing.Size(85, 17);
this.lblLocation.TabIndex = 1;
this.lblLocation.Text = "跑马灯 位置:";
//
// lblDorection
//
this.lblDorection.AutoSize = true;
this.lblDorection.Location = new System.Drawing.Point(144, 88);
this.lblDorection.Name = "lblDorection";
this.lblDorection.Size = new System.Drawing.Size(66, 17);
this.lblDorection.TabIndex = 2;
this.lblDorection.Text = "目前方向:";
//
// lblMsg
//
this.lblMsg.Location = new System.Drawing.Point(64, 176);
this.lblMsg.Name = "lblMsg";
this.lblMsg.TabIndex = 3;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 271);
this.Controls.Add(this.lblMsg);
this.Controls.Add(this.lblDorection);
this.Controls.Add(this.lblLocation);
this.Controls.Add(this.lblTitle);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
lblMsg.Location=new Point(150,150);
lblMsg.BackColor=Color.Aqua;
lblMsg.AutoSize=true;
lblMsg.Font=new Font("楷体",20,FontStyle.Bold);
lblMsg.Text="全OK信息网";
timer1.Enabled=true;
timer1.Interval=10;
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lblLocation.Text="跑马灯位置:"+lblMsg.Left.ToString();
if(runLeft)
{
lblMsg.Left-=1;
lblDorection.Text="目前方向:往左移";
if(lblMsg.Left<=0)
runLeft=false;
}
else
{
lblMsg.Left+=1;
lblDorection.Text="目前方向:往右移";
if(lblMsg.Left+lblMsg.Width>=this.Width)
runLeft=true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -