我必须在.NET Windows应用程序中创建一个选取框。用C#做到最好的是什么?
答案 0 :(得分:4)
只需放置ProgressBar
控件,然后将Style
更改为Marquee
即可。你会立即看到动画。
如果您指的是文本选框,只需放置Label
控件并使用Timer Class来增加标签的Location.X
属性。当X坐标等于控件的大小时,只需将其重置并重新开始。
答案 1 :(得分:4)
这里是关于如何在C#
中进行选框的简单代码 private int xPos=0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Width == xPos)
{
//repeat marquee
this.lblMarquee.Location = new System.Drawing.Point(0, 40);
xPos = 0;
}
else
{
this.lblMarquee.Location = new System.Drawing.Point(xPos, 40);
xPos++;
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
答案 2 :(得分:0)
private void button_Click(object sender, EventArgs e)
{
int j = 100;
for (int i = 0; i < j; i++)
{
Thread.Sleep(5);
label3.Location = new System.Drawing.Point(0 + i, 111);
label3.Visible = true;
}
for (int i = j; i-- > 0; )
{
Thread.Sleep(15);
label3.Location = new System.Drawing.Point(0 + i, 111);
label3.Visible = true;
if (i < 1)
button_Click(sender, e);
}
}