전광판처럼 움직이는 라벨 만들기
움직이는 라벨을 만들어 봅시다...
3개의 라벨을 만들고 폼 로드시 각 자리를 잡아주는데 그 자리는 첫번째 라벨은 폼의 끝에.
두번째 라벨은 폼의 너비 * 2 만큼의 자리에 세번째 라벨은 폼의 너비 * 3만큼의 자리에 위치 시키고
타이머를 이용 1픽셀?씩 계속 이동시킵니다.
그리고 라벨의 Left 값이 가장 긴 라벨의 - 값보다 작아지면 다시 폼의 너비 * 3의 위치로 이동시킵니다.
아래는 그 소스 입니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace movelbl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
lbl1.Left = lbl1.Left - 1;
lbl2.Left = lbl2.Left - 1;
lbl3.Left = lbl3.Left - 1;
if (lbl1.Left < -lbl3.Width)
lbl1.Left = this.Width * 3 - lbl3.Width;
if (lbl2.Left < -lbl3.Width)
lbl2.Left = this.Width * 3 - lbl3.Width;
if (lbl3.Left < -lbl3.Width)
lbl3.Left = this.Width * 3 - lbl3.Width;
}
private void Form1_Load(object sender, EventArgs e)
{
lbl1.Top = this.Height / 3;
lbl1.Left = this.Width;
lbl2.Top = this.Height / 3;
lbl2.Left = this.Width * 2;
lbl3.Top = this.Height / 3;
lbl3.Left = this.Width * 3;
timer1.Enabled = true;
}
}
}