Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

To display a date by using a MonthCalendar control




Компиляция кода

Пример

Отображение времени в надписи

Compiling the Code

Example

Компиляция кода

Пример

Compiling the Code

This example requires:

· A Windows Form with a DateTimePicker control named dateTimePicker1 and a Button control labeled Select a Meeting Date.

· Set the event handler of the button to button1_Click.


Извлечение даты в элементе управления "DateTimePicker"

В этом примере происходит выбор даты встречи в элементе управления DateTimePicker Windows Forms. Выбранная дата встречи и текущая дата будут отображены в окнах сообщений.

ß-----

 

 

Для этого примера необходимы следующие компоненты.

· Форма Windows Form с элементом управления DateTimePicker, которому задано имя dateTimePicker1, и элемент управления Button с надписью Выбор даты встречи.

· Задайте обработчику событий кнопки значение button1_Click.


How to: Display the Time in a Label

This example displays the current time in a Label.

private void displayTime() { Label1.Text = DateTime.Now.ToShortTimeString(); }

The form must contain a Labelnamed Label1.


В этом примере текущее время отображается в Label.

private void displayTime() { Label1.Text = DateTime.Now.ToShortTimeString(); }

Форма должна содержать Labelс именем "Label1".[9]


How to: Display the Date and Time in Your Application

You can display the date on a Windows Form by using calendar controls, such as the MonthCalendar control or a DateTimePicker control. The DateTimePicker control also enables you to display the time.

You can also use these controls to collect input from the user to use the date or time selected elsewhere in your application. The MonthCalendar control enables you to select a range of dates.

1. On the File menu, click New Project.

The New Project dialog box appears.

2. Click Windows Forms Application and then click OK.

3. Add a Label control to the form, with the default name label1.

4. Add a MonthCalendar control to the form, with the default name MonthCalendar1.

5. Double-click the form to add the default Load event handler in the Code Editor and add the following code. This code assigns the selected date (today's date) to the Text property of the label in short date format.

this.label1.Text = this.monthCalendar1.SelectionRange.Start.ToShortDateString();

6. Create a DateChanged event handler for the MonthCalendar1 control. You can do this by double-clicking the control in the designer.

7. Add the following code to the MonthCalendar_DateChanged event handler. This code sets the label to the selected date, but this time in long date format.

this.label1.Text = this.monthCalendar1.SelectionRange.Start.ToShortDateString();

8. Press F5 to run the program.

9. When the form opens, change the date by clicking a date in the MonthCalendar control.

10. Verify that the date is updated in the label.





Поделиться с друзьями:


Дата добавления: 2014-12-27; Просмотров: 358; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.01 сек.