?? 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 + -