Example 046 label movement and color change

Label class

https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.forms.label?view=netframework-4.8

The Label class is inherited from the Control class, and its main properties include:

  • Text: the displayed text content;
  • Left: the horizontal position of the label;
  • Top: the vertical position of the label;
  • Widh, the width of the label;
  • Height, the height of the label;
  • Forecolor foreground color etc.

The load event is a system event triggered when the dialog box is loaded. The process of using this event can set the initial value of the variable or control property.
In VB. NET, the Color class is used to represent colors, which is defined under the Sysm. Drawing namespace. A variety of colors have been defined in the Color class, such as Yellow, Yellow; Blue, Blue, etc.

Controls Attributes value Controls Attributes value
Label Name lblInformation Button Name btnResetLabel
Button Name btnMoveup Text restore
Text Move up Button name btnSetColorRed
Button Name btnMovedown Text Font red
text Move down Button name btnSetColorYellow
Button Name btnMoveLeft Text Font yellow
Text Shift left Button name  btnExit
Button Name btnMoveright   drop out
Text Right shift      

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblInformation.Width = 200
        lblInformation.Height = 50
        btnResetLabel.PerformClick()
    End Sub

    Private Sub btnMoveLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveLeft.Click
        lblInformation.Left -= 5
    End Sub

    Private Sub btnResetLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetLabel.Click
        lblInformation.Left = _
            (Me.Width - Me.DefaultMargin.Left - lblInformation.Width) / 2
        lblInformation.Top = 20
        lblInformation.ForeColor = Color.Blue
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click
        lblInformation.Top -= 5
    End Sub

    Private Sub btnMoveRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveRight.Click
        lblInformation.Left += 5
    End Sub

    Private Sub btnMoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveDown.Click
        lblInformation.Top += 5
    End Sub

    Private Sub SetColorRed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetColorRed.Click
        lblInformation.ForeColor = Color.Red
    End Sub

    Private Sub SetColorYellow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetColorYellow.Click
        lblInformation.ForeColor = Color.Yellow
    End Sub
End Class
 

 

 

Published 146 original articles · praised 0 · visits 2719

Guess you like

Origin blog.csdn.net/ngbshzhn/article/details/105638536