📄 movelinklabel.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace PowerNet.Mobile.Label.ClassLab
{
class MoveLinkLabel : LinkLabel
{
public static Thread moveThread;
public static string movingTitle;
public static MoveLinkLabel movingLabel;
public static bool mark = false;
private string title;
private int titleWidth;
public string Title
{
get
{
return this.title;
}
set
{
title = value;
this.Text = title;
titleWidth = (int)((new Form().CreateGraphics()).MeasureString(title, this.Font)).Width;
}
}
public MoveLinkLabel()
{
this.GotFocus += new EventHandler(MoveLinkLabel_GotFocus);
this.LostFocus += new EventHandler(MoveLinkLabel_LostFocus);
this.Click += new EventHandler(MoveLinkLabel_Click);
}
public string GetTitle()
{
return this.title;
}
private void MoveLinkLabel_Click(object sender, EventArgs e)
{
MessageBox.Show("yes");
}
private void MoveLinkLabel_LostFocus(object sender, EventArgs e)
{
if (this.titleWidth < this.Width)
return;
MoveLinkLabel.movingLabel.Text = MoveLinkLabel.movingLabel.GetTitle();
MoveLinkLabel.moveThread.Abort();
mark = false;
}
private void MoveLinkLabel_GotFocus(object sender, EventArgs e)
{
if (this.titleWidth < this.Width)
return;
MoveLinkLabel.movingLabel = this;
MoveLinkLabel.movingTitle = this.title;
if (mark)
{
MoveLinkLabel.moveThread.Abort();
}
mark = true;
MoveLinkLabel.moveThread = new Thread(new ThreadStart(MoveLinkLabel.TextChange));
MoveLinkLabel.moveThread.IsBackground = true;
MoveLinkLabel.moveThread.Start();
}
delegate void TextMoveDelegate(string text);
private static void TextMove(string text)
{
MoveLinkLabel.movingLabel.Text = text;
}
private static void TextChange()
{
int end = movingTitle.Length;
while (true)
{
Thread.Sleep(0);
for (int i = 0; i < end; i++)
{
TextMoveDelegate move = new TextMoveDelegate(TextMove);
MoveLinkLabel.movingLabel.Invoke(move, movingTitle.Substring(i, end - i));
Thread.Sleep(380);
}
}
}
}
}
/*
* for (int i = 0; i < 8; i++)
{
TextMoveDelegate move = new TextMoveDelegate(TextMove);
MoveLinkLabel.movingLabel.Invoke(move, i.ToString());
Thread.Sleep(2000);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -