程序设计与实践(VB.NET)
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人

三、代码设计

1.双击Form1窗体,输入Form1_Load事件中的代码,其代码如下所示。

    Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As
      System.EventArgs)Handles MyBase.Load
      Me.ComboBox1.Items.Add("long")
      Me.ComboBox1.Items.Add("short")
      Me.ComboBox1.Items.Add("timedate")
      Me.ComboBox1.Items.Add("custom1")
      Me.ComboBox1.Items.Add("custom2")
      Me.ComboBox1.Items.Add("custom3")
      Me.ComboBox1.Items.Add("custom4")
      '添加日期显示格式
      Me.ComboBox2.Items.Add("下拉菜单式")
      Me.ComboBox2.Items.Add("单击/选择式")
      '添加起始星期
      Me.ComboBox1.SelectedIndex = 0
      Me.ComboBox2.SelectedIndex = 0
      Me.TextBox1.Text = TimeOfDay
    End Sub

2.ComboBox1_SelectedIndexChanged事件中的代码如下所示。

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
      ByVal e As System.EventArgs)Handles ComboBox1.SelectedIndexChanged
      Select Case Me.ComboBox1.SelectedIndex
        Case 0
          Me.DateTimePicker1.Format = DateTimePickerFormat.Long
        Case 1
          Me.DateTimePicker1.Format = DateTimePickerFormat.Short
        Case 2
          Me.DateTimePicker1.Format = DateTimePickerFormat.Time
        Case 3
          Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
          Me.DateTimePicker1.CustomFormat = "MMM dd,yyy - ddd"
        Case 4
          Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
          Me.DateTimePicker1.CustomFormat = "ddd,hh:mm:ss,tt"
        Case 5
          Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
          Me.DateTimePicker1.CustomFormat = "dddd,HH:mm:ss,tt"
        Case 6
          Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
          Me.DateTimePicker1.CustomFormat = "dddd,HH:m:ss,t"
      End Select
      Me.TextBox1.Text = TimeOfDay
    End Sub

3.ComboBox2_SelectedIndexChanged事件中的代码如下所示。

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object,
      ByVal e As System.EventArgs)Handles ComboBox2.SelectedIndexChanged
      Select Case Me.ComboBox2.SelectedIndex
        Case 0
          Me.DateTimePicker1.ShowUpDown = False
        Case 1
          Me.DateTimePicker1.ShowUpDown = True
      End Select
      Me.TextBox1.Text = TimeOfDay
    End Sub

4.CheckBox1_CheckStateChanged事件中的代码如下所示。

    Private Sub CheckBox1_CheckStateChanged(ByVal sender As Object,ByVal e
      As System.EventArgs)Handles CheckBox1.CheckStateChanged
      If Me.CheckBox1.Checked Then
        Me.MonthCalendar1.ShowToday = True
      Else
        Me.MonthCalendar1.ShowToday = False
      End If
    End Sub

5.Button1_Click事件中的代码如下所示。

    Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
      System.EventArgs)Handles Button1.Click
      End
    End Sub