Datatimepicker display time only

Asked

Viewed 1,697 times

4

I am developing an application for the reception of my work in C#. As I am still crawling in the language, I need your help. The schedule will contain the following fields:

  • Requester Name; Scheduling Date ( I’m using Datatimepicker );
  • Start time ( I’m using the Datatimepicker );
  • End Time ( I’m using the Datatimepicker );

At Start Time and End Time I changed the Format for Time, but when I click, the full date continues to appear. How I would set up these fields to appear only the time for the user to select?

It follows below as it appears to me. I need it to appear 00:00:00 until 23:59:59: inserir a descrição da imagem aqui

  • What have you ever done? What’s the problem?

  • I only did what I passed in the post, because I just started the development. The problem is that even changing the format of the Datatimepicker, when clicking on the field, still appears the date and not only the times.

  • Show what you’ve done, help people help you.

  • Show how? If I just dragged the components to the stage and changed the format in the properties.

  • Taking the generated codes, you only know how to drag the controls but you know nothing about code?

  • then bigown. As I reported, I’m still crawling on C#. I’ve used code passed by ramaral before, but not exactly what I want.

  • @Jose.Marcos http://pttimeselect.sourceforge.net/example/index.html I think this might be interesting for you.

Show 2 more comments

2 answers

0

According to the documentation in addition to changing the format to Team it is necessary also to "set" with true the property Showupdown

timePicker = new DateTimePicker();
timePicker.Format = DateTimePickerFormat.Time;
timePicker.ShowUpDown = true;
  • So ramaral. I’ve tried this code before, but what happens in this code is that when we select a date, it converts to time. That’s not exactly what I want, because I’ve already formatted two fields for Time. What I need is that when clicking the field, do not appear the calendar and yes all times, from 00:00:00 until 23:59:59, because I will use 02 fields for the user to set the schedules of the schedule.

  • 1

    Is there any other component that does this besides dateTimePicker?

  • I confess that I did not test, but it is said in the documentation that this code "shows how to create a Datetimepicker that allows users to choose only one team" - "how to create a Datetimepicker that Enables users to Choose a time only."

  • Yes it allows, but it does not show a list to choose the time. the User has to pass the time and minutes by the button.

  • I changed my post and put an image of how it appears to me

  • Follow picture to see how it looks, with this code - IMG

  • Meuchapeu. There’s no way to do this in C#?

  • 1

    I believe that changing the DateTimePicker, just to show time how you want to not... what could and have a ComboBox with the set hours.

  • That’s what I thought. Create a Combox. I’ll try here and return, combined?

Show 4 more comments

0


I did it. According to Meuchapeu’s hint about creating a Combox, I put it as follows:

public Form1()
        {
            InitializeComponent();
            DateTime time = DateTime.Today;
            for (DateTime _time = time.AddHours(08); _time < time.AddHours(18); _time = _time.AddMinutes(30)) //from 16h to 18h hours
            {
                comboBox1.Items.Add(_time.ToShortTimeString());
            }
        }

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strTime_Start = comboBox1.SelectedItem.ToString();
            string strTime_End = "18:00";
            DateTime dateTime_Start = Convert.ToDateTime(strTime_Start);
            DateTime dateTime_End = Convert.ToDateTime(strTime_End);
        }

The result is below:

inserir a descrição da imagem aqui

  • Fox. 11 give your answer accepted so the question does not stay open

Browser other questions tagged

You are not signed in. Login or sign up in order to post.