How to use DateTimePicker, MonthCalendar and TrackBar in Visual Basic.Net


In this article I am going to show you how you can use DateTimePicker, MonthCalendar and TrackBar in Visual Basic.Net. I am going to copy the Date, Time, Year to the Textbox1 and Change the Font of the Textbox2 with TrackBar.

To use DateTimePicker, MonthCalendar and TrackBar in Visual Basic.Net. FIrst of all we have to create a New project and add a DateTimePicker, MonthCalendar and a TrackBar on the form from the Toolbox. Now add two Textboxes Textbox1 and Textbox2 on the form.

DateTimePicker:-
To copy time of day to the textbox using DateTimePicker

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
TextBox1.Text = DateTimePicker1.Value.TimeOfDay.ToString(
End Sub


To copy Date and time of day using DateTimePicker

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
TextBox1.Text = DateTimePicker1.Value
End Sub


To copy only year to the textbox using DateTimePicker

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
TextBox1.Text = DateTimePicker1.Value.Year
End Sub


To copy day and date to the textbox using DateTimePicker in (Wednesday, March 20, 2013 format)

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
TextBox1.Text = DateTimePicker1.Text
End Sub


MonthCalendar:-
To copy only date to the textbox using MonthCalendar1

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
TextBox1.Text = MonthCalendar1.SelectionRange.Start.Date
End Sub

To copy only day to the textbox using MonthCalendar1

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
TextBox1.Text = MonthCalendar1.SelectionRange.Start.Day
End Sub


Trackbar:-
Increase the font of textbox using trackbar

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TrackBar1.Maximum = 100
TrackBar1.Minimum = 10
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Me.TextBox2.Font = New Font("Arial", TrackBar1.Value)
End Sub



Regards
Keep coding


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: