实例050选择字体

控件 属性 控件 属性
label name lblPrompt label name lblFont
  text 您好   text 字体
label name lblColor lalbel name lblFontSize
  text 字体颜色   text 字体大小
domainUpDown name dudFont domainUpDown name dudFontColor
NumericUpDown name nudFontSize      

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dudFont.Items.Add("隶书")
        dudFont.Items.Add("宋体")
        dudFont.SelectedIndex = 0

        nudFontSize.Maximum = 120
        nudFontSize.Minimum = 20

        dudFontColor.Items.Clear()
        dudFontColor.Items.Add("红色")
        dudFontColor.Items.Add("蓝色")
        dudFontColor.Items.Add("黄色")
        dudFontColor.SelectedIndex = 1

        lblObject.Text = "您好!"
    End Sub

    Private Sub dudFont_SelectedItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dudFont.SelectedItemChanged
        If nudFontSize.Value > 0 Then
            Dim MyFontFamily As New FontFamily(dudFont.Text)
            Dim myFont As New Font(MyFontFamily, nudFontSize.Value, FontStyle.Bold, GraphicsUnit.Pixel)
            lblObject.Font = myFont
        End If
    End Sub

    Private Sub nudFontSize_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudFontSize.ValueChanged
        Dim MyFontFamily As New FontFamily(dudFont.Text)
        Dim myFont As New Font(MyFontFamily, nudFontSize.Value, FontStyle.Bold, GraphicsUnit.Pixel)
        lblObject.Font = myFont
    End Sub

    Private Sub dudFontColor_SelectedItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dudFontColor.SelectedItemChanged
        Select Case dudFontColor.Text
            Case "红色"
                lblObject.ForeColor = Color.Red
            Case "蓝色"
                lblObject.ForeColor = Color.Blue
            Case "黄色"
                lblObject.ForeColor = Color.Yellow
        End Select
    End Sub
End Class
 

 

 

相关文章:

  • 2021-10-04
  • 2021-07-10
  • 2021-07-17
  • 2021-10-04
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2021-12-06
  • 2022-01-01
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案