반응형
* VBNET 움직이는 라벨 만들기 예제...
-사용한 컨트롤 : Label 1 개, Panel 1개, Timer 1개
전체 소스 코드
Form1.vb
Public Class Form1
Dim iLocationX As Integer = 1
Dim iLocationY As Integer = 0
Dim bCheck As Boolean = True
Dim iSpeed As Integer = 5
Dim iOffset As Integer = 10
Public Sub New()
' 이 호출은 Windows Form 디자이너에 필요합니다.
InitializeComponent()
' InitializeComponent() 호출 뒤에 초기화 코드를 추가하십시오.
'라벨 Location Y 지정
iLocationY = (panel1.Height - panel1.Location.Y) / 2
Dim p As Point = New Point(iLocationX, iLocationY)
label1.Location = p
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
timer1.Start()
End Sub
Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
MyBase.OnClosed(e)
timer1.Stop()
End Sub
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
'앞으로
If bCheck Then
Dim iMove As Integer = iLocationX + label1.Width + iOffset
Dim iEnd As Integer = panel1.Width
If iMove <= iEnd Then
iLocationX += iSpeed
Dim p As Point = New Point(iLocationX, iLocationY)
label1.Location = p
Else '끝지점에 도달 했으면...
bCheck = False
End If
Else '뒤로
'처음으로 다시 왔으면...
If iLocationX <= panel1.Location.X Then
bCheck = True
Else
iLocationX -= iSpeed
Dim p As Point = New Point(iLocationX, iLocationY)
label1.Location = p
End If
End If
End Sub
End Class
*예제 결과
반응형
'VB.NET Programming' 카테고리의 다른 글
[VBNET] [API] 화면 캡쳐 방지 (Screen Capture Prevention) (0) | 2020.05.26 |
---|---|
[VBNET] [Control] Listview - BeginUpdate, EndUpdate 조회 속도 비교 (0) | 2020.05.22 |
[VBNET] [Control] Listview - Button, Progressbar, TextBox 컨트롤 삽입 (0) | 2020.05.18 |
[VBNET] [Control] Listview - 그룹화 항목 만들기 (0) | 2020.05.14 |
[VBNET] EXE File iCon 가져오기 (0) | 2020.05.12 |