在C# WinForm 輕松實現滾動字幕特效的關于窗體(tǐ)

發布時間:2010年12月24日      浏覽次數:1428 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CodingMouse.CMCSharpSDK.UI.Forms
{
/// <summary>
/// 關于本軟件界面
/// </summary>
public partial class frmAbout : Form
{
#region Private Members
List<Label> lblTxt = new List<Label>();
List<Label> lblScroll = new List<Label>();
int index = 0;
/// <summary>
/// 保存窗體(tǐ)舊(jiù)坐标的X軸值和Y軸值
/// </summary>
int _x, _y;
/// <summary>
/// 保存窗體(tǐ)是否可移動标識
/// </summary>
bool isMove = false;
/// <summary>
/// 保存鼠标指針指向的坐标點
/// </summary>
Point _mouseLocation;
#endregion
#region Public Methods
/// <summary>
/// 無參構造
/// </summary>
public frmAbout()
{
// 構建設計器控件
InitializeComponent();
for (int i = 0; i < 13; i++)
{
Label lbl = new Label();
lblTxt.Add(lbl);
lblTxt[i].Top = this.Height - 24;
lblTxt[i].Left = 24;
lblTxt[i].Visible = false;
lblTxt[i].BackColor = Color.Transparent;
lblTxt[i].ForeColor = Color.White;
lblTxt[i].AutoSize = true;
this.Controls.Add(lblTxt[i]);
}
lblTxt[0].Text = "産品名稱: CMCSharpSDK";
lblTxt[1].Text = "産品全稱: CodingMouse C# 開(kāi)發工(gōng)具包";
lblTxt[2].Text = "當前版本: 1.0.0.0";
lblTxt[3].Text = "";
lblTxt[4].Text = "程式設計: 鄧超 (網絡用名: CodingMouse)";
lblTxt[5].Text = "";
lblTxt[6].Text = " Qicq: 454811990";
lblTxt[7].Text = " E-mail: CodingMouse@gmail.com";
lblTxt[8].Text = " Blog: http://blog.csdn.net/CodingMouse";
lblTxt[9].Text = "";
lblTxt[10].Text = "測試環境: Microsoft Windows Server 2003 Enterprise Edition";
lblTxt[11].Text = " Microsoft Visual Studio 2005 Team Suite";
lblTxt[12].Text = " Microsoft SQL Server 2005 Enterprise Edition";
// 添加事件監聽(tīng)
lblTxt[7].Click += new EventHandler(frmAbout_Email_Click);
lblTxt[8].Click += new EventHandler(frmAbout_WebSite_Click);
lblTxt[7].MouseMove += new MouseEventHandler(frmAbout_Link_MouseMove);
lblTxt[8].MouseMove += new MouseEventHandler(frmAbout_Link_MouseMove);
lblTxt[7].MouseLeave += new EventHandler(frmAbout_Link_MouseLeave);
lblTxt[8].MouseLeave += new EventHandler(frmAbout_Link_MouseLeave);
lblScroll.Add(lblTxt[0]);
}
#endregion
#region Event Handlers
/// <summary>
/// 鏈接标簽鼠标移動事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_Link_MouseMove(object sender, MouseEventArgs e)
{
Label currentLabel = (sender as Label);
currentLabel.ForeColor = Color.Yellow;
currentLabel.Cursor = Cursors.Hand;
}
/// <summary>
/// 鏈接标簽鼠标移開(kāi)事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_Link_MouseLeave(object sender, EventArgs e)
{
Label currentLabel = (sender as Label);
currentLabel.ForeColor = Color.White;
currentLabel.Cursor = Cursors.Default;
}
/// <summary>
/// [E-mail]滾動标簽點擊事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_Email_Click(object sender, EventArgs e)
{
Process.Start("mailto:CodingMouse@gmail.com");
}
/// <summary>
/// [Blog]滾動标簽點擊事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_WebSite_Click(object sender, EventArgs e)
{
Process.Start("http://blog.csdn.net/CodingMouse");
}
/// <summary>
/// 計時器事件(調度信息字幕顯示)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tmrShow_Tick(object sender, EventArgs e)
{
// 控制字幕滾動
for (int i = 0; i < lblScroll.Count; i++)
{
lblScroll[i].Visible = true;
lblScroll[i].Top -= 1;
if (lblScroll[i] == lblTxt[(lblTxt.Count - 1)]
&& lblScroll[i].Top == this.Height - 84)
{
index = 0;
lblScroll.Add(lblTxt[0]);
}
if (lblScroll[i].Top < (lblTxt.Count - 1))
{
lblScroll[i].Visible = false;
lblScroll[i].Top = this.Height - (lblTxt.Count - 1) * 2;
lblScroll.RemoveAt(i);
}
}
if (index < (lblTxt.Count - 1))
{
if ((lblTxt[index].Top + lblTxt[index].Height) - lblTxt[index + 1].Top
== -(lblTxt.Count - 1))
{
lblScroll.Add(lblTxt[index + 1]);
index++;
}
}
}
/// <summary>
/// 窗體(tǐ)雙擊事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_DoubleClick(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 鼠标指針在窗體(tǐ)上方并按下(xià)按鍵事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_MouseDown(object sender, MouseEventArgs e)
{
// 僅響應鼠标左鍵點擊事件
if (e.Button == MouseButtons.Left)
{
// 保存舊(jiù)坐标
this._x = e.X;
this._y = e.Y;
// 标識窗體(tǐ)可移動
this.isMove = true;
}
}
/// <summary>
/// 鼠标指針在窗體(tǐ)上方并移動鼠标指針事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_MouseMove(object sender, MouseEventArgs e)
{
// 如果可移動
if (this.isMove)
{
// 根據舊(jiù)坐标的相對偏移位置移動窗體(tǐ)
// 方法一(yī):
// this.Left += e.X - this._x;
// this.Top += e.Y - this._y;
// 方法二:
this.SetDesktopLocation(this.Left + e.X - this._x, this.Top + e.Y - this._y);
}
// 保存鼠标指針坐标點
_mouseLocation = e.Location;
}
/// <summary>
/// 鼠标指針在窗體(tǐ)上方并釋放(fàng)按鍵事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_MouseUp(object sender, MouseEventArgs e)
{
// 标識窗體(tǐ)不可移動
this.isMove = false;
}
/// <summary>
/// 鼠标指針在窗體(tǐ)上移過并保持靜止狀态一(yī)段時間事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmAbout_MouseHover(object sender, EventArgs e)
{
this.toolTip.ToolTipIcon = ToolTipIcon.Info;
this.toolTip.ToolTipTitle = "關閉提示";
this.toolTip.Show(
"請雙擊鼠标鍵來關閉此窗體(tǐ) ...",
this, new Point(_mouseLocation.X + 6, _mouseLocation.Y + 6),
5000);
}
#endregion
}
}
免責聲明:本站相關技術文章信息部分(fēn)來自網絡,目的主要是傳播更多信息,如果您認爲本站的某些信息侵犯了您的版權,請與我(wǒ)(wǒ)們聯系,我(wǒ)(wǒ)們會即時妥善的處理,謝謝合作!