只是想问一下如何获得本月,上个月,今年和去年的日期时间选择器在vb.net 2012中是否有可能?例如,我在组合框中选择“本月”,然后将日期时间选择器值更改为今天的月份。这是我的代码结构..
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
'if "Today" was chosen
If ComboBox1.SelectedIndex = 1 Then
DateTimePicker1.Value = Today
DateTimePicker2.Value = Today
'if "This Month" was chosen
ElseIf ComboBox1.SelectedIndex = 2 Then
End If
End Sub
答案 0 :(得分:0)
上个月
DateTimePicker1.Value=Now.AddMonths(-1).ToString("dd/MM/yyyy")
去年获得
DateTimePicker1.Value= Now.AddYears(-1).ToString("dd/MM/yyyy")