Winform:滚动文字提示

做成一个用户控件,需要一个Label、Timer基础控件,让计时器不断移动Label的位置就可以了。
1
using System;2
using System.Collections.Generic;3
using System.ComponentModel;4
using System.Drawing;5
using System.Data;6
using System.Text;7
using System.Windows.Forms;8

9
namespace pcd.WinControl10


{11
public partial class LabelTextMoving : UserControl12

{13
public LabelTextMoving()14

{15
InitializeComponent();16
}17

18
private void timer1_Tick(object sender, EventArgs e)19

{20
if (labMsg.Location.X < 0 && Math.Abs(labMsg.Location.X) - labMsg.Width >= 0)21

{22
labMsg.Location = new Point(panel1.Width, labMsg.Location.Y);23
return;24
}25
labMsg.Location = new Point(labMsg.Location.X - 5, labMsg.Location.Y);26
}27

28

29

Properties#region Properties30
[Category("Appearance"),31
Description("Label前景色")]32
public System.Drawing.Color LabelForeColor33

{34

get
{ return labMsg.ForeColor; }35

set
{ labMsg.ForeColor = value; }36
}37

38

39

40
[Category("Appearance"),41
Description("LabelText")]42
public string LabelText43

{44

get
{ return labMsg.Text; }45
set46

{47

48
labMsg.Text = value;49
if (value == "")50
timer1.Enabled = false;51
else timer1.Enabled = true;52
}53
}54

55
#endregion56
}57
}58

浙公网安备 33010602011771号