Top 29 Datetimepicker C# The 43 Detailed Answer

You are looking for information, articles, knowledge about the topic nail salons open on sunday near me datetimepicker c# on Google, you do not find the information you need! Here are the best content compiled and compiled by the https://chewathai27.com/to team, along with other related topics such as: datetimepicker c# Datetimepicker, Truyền dữ liệu vào DateTimePicker, DateTimePicker C#, DateTimePicker format, DateTimePicker C# Windows Form, bootstrap-datetimepicker, Datetimepicker jQuery, datetimepicker format dd/mm/yyyy c#


[Lập trình C# Winform] – Bài 24: DateTimePicker | HowKteam
[Lập trình C# Winform] – Bài 24: DateTimePicker | HowKteam


[C#] Hướng dẫn sử dụng DateTimePicker

  • Article author: csharpcanban.com
  • Reviews from users: 21026 ⭐ Ratings
  • Top rated: 3.8 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about [C#] Hướng dẫn sử dụng DateTimePicker [C#] Trong bài viết này csharpcanban.com sẽ hướng dẫn các bạn sử dụng DateTimePicker Control để lập trình phần mềm trên Winform, có ví dụ và code Demo, … …
  • Most searched keywords: Whether you are looking for [C#] Hướng dẫn sử dụng DateTimePicker [C#] Trong bài viết này csharpcanban.com sẽ hướng dẫn các bạn sử dụng DateTimePicker Control để lập trình phần mềm trên Winform, có ví dụ và code Demo, … [C#] Trong bài viết này csharpcanban.com sẽ hướng dẫn các bạn sử dụng DateTimePicker Control để lập trình phần mềm trên Winform, có ví dụ và code Demo, các bạn có thể tải về để sử dụng.
  • Table of Contents:
[C#] Hướng dẫn sử dụng DateTimePicker
[C#] Hướng dẫn sử dụng DateTimePicker

Read More

DateTimePicker Class (System.Windows.Forms) | Microsoft Docs

  • Article author: docs.microsoft.com
  • Reviews from users: 24995 ⭐ Ratings
  • Top rated: 3.4 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about DateTimePicker Class (System.Windows.Forms) | Microsoft Docs The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker … …
  • Most searched keywords: Whether you are looking for DateTimePicker Class (System.Windows.Forms) | Microsoft Docs The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker … Represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.
  • Table of Contents:

Definition

Examples

Remarks

Constructors

Fields

Properties

Methods

Events

Explicit Interface Implementations

Applies to

See also

DateTimePicker Class (System.Windows.Forms) | Microsoft Docs
DateTimePicker Class (System.Windows.Forms) | Microsoft Docs

Read More

Cách dùng DateTimePicker – MonthCalendar trong C# (winforms)

  • Article author: freetuts.net
  • Reviews from users: 20489 ⭐ Ratings
  • Top rated: 4.7 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about Cách dùng DateTimePicker – MonthCalendar trong C# (winforms) Trong ví dụ đầu tiên này mình sẽ thực hiện một chương trình đơn giản trong đó có sử dụng DateTimePicker, cụ thể sẽ thực hiện theo Form dưới đây với một số chức … …
  • Most searched keywords: Whether you are looking for Cách dùng DateTimePicker – MonthCalendar trong C# (winforms) Trong ví dụ đầu tiên này mình sẽ thực hiện một chương trình đơn giản trong đó có sử dụng DateTimePicker, cụ thể sẽ thực hiện theo Form dưới đây với một số chức … Cách dùng DateTimePicker và MonthCalendar trong C#, đây là hai điều khiển được sử dụng để hiển thị ngày tháng trong lập trình Winforms.
  • Table of Contents:

1 DateTimePicker trong C#

2 MonthCalendar trong C#

3 Ví dụ sử dụng DateTimePicker và MonthCalendar trong C#

4 Kết luận

Cùng chuyên mục

Cách dùng DateTimePicker - MonthCalendar trong C# (winforms)
Cách dùng DateTimePicker – MonthCalendar trong C# (winforms)

Read More

DateTimePicker trong lập trình C# Winform | How Kteam

  • Article author: howkteam.vn
  • Reviews from users: 6161 ⭐ Ratings
  • Top rated: 4.0 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about DateTimePicker trong lập trình C# Winform | How Kteam Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam. … Sao anh có thể để datetimepicker bằng tiếng việt vậy ạ? … kq = 9 ngày. anh ơi, làm thế nào để tính … …
  • Most searched keywords: Whether you are looking for DateTimePicker trong lập trình C# Winform | How Kteam Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam. … Sao anh có thể để datetimepicker bằng tiếng việt vậy ạ? … kq = 9 ngày. anh ơi, làm thế nào để tính … DateTimePicker trong lập trình C# WinformDateTimePicker trong lập trình C# Winform
  • Table of Contents:

Lập trình Winform cơ bản

DateTimePicker trong lập trình C# Winform

DateTimePicker trong lập trình C# Winform

Dẫn nhập

Nội dung

Kết luận

Thảo luận

DateTimePicker trong lập trình C# Winform | How Kteam
DateTimePicker trong lập trình C# Winform | How Kteam

Read More

Bài tập C# – Bài 9 – Cách dùng DateTimePicker – MonthCalendar trong C# winforms

  • Article author: www.plpsoft.vn
  • Reviews from users: 33194 ⭐ Ratings
  • Top rated: 3.6 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about Bài tập C# – Bài 9 – Cách dùng DateTimePicker – MonthCalendar trong C# winforms Cách dùng DateTimePicker – MonthCalendar trong C# winforms … Nhưng khác biệt là MonthCalendar cho phép người dùng có thể chọn một tập các ngày hay nói … …
  • Most searched keywords: Whether you are looking for Bài tập C# – Bài 9 – Cách dùng DateTimePicker – MonthCalendar trong C# winforms Cách dùng DateTimePicker – MonthCalendar trong C# winforms … Nhưng khác biệt là MonthCalendar cho phép người dùng có thể chọn một tập các ngày hay nói … Công ty phần mềm, thiết kế website, bảo mật mạng máy tính, lắp đặt camera, mua bán laptop, dịch vụ tư vấn, thiết kế, thi công liên quan đến thiết bị tin học và thiết bị an ninh.Phần mềm, phần mềm quản lý, phần mềm bán hàng, phần mềm tính tiền, sản xuất các sản phẩm phần mềm, thiết kế website, thiết kế, thi công lắp đặt camera, điện mặt trời, phần mềm quản lý Karaoke, SPA, quán ăn, cafe, nhà hàng, khách sạn, hotel, vật tư xây dựng, điện gia dụng, vật tư nông nghiệp, phòng khám đông y, phòng khám bệnh, quầy thuốc tây, plpsoft, plpsoft.vn, bảo mật mạng máy tính, bảo mật, network security, computer network security servives, CNSS
  • Table of Contents:

BÀI TẬP THỰC HÀNH C#

Bài 9 Cách dùng DateTimePicker – MonthCalendar trong C# winforms

Bài tập C# - Bài 9 - Cách dùng DateTimePicker - MonthCalendar trong C# winforms
Bài tập C# – Bài 9 – Cách dùng DateTimePicker – MonthCalendar trong C# winforms

Read More

C# DateTimePicker Control

  • Article author: csharp.net-informations.com
  • Reviews from users: 37363 ⭐ Ratings
  • Top rated: 4.8 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about C# DateTimePicker Control The DateTimePicker control allows you to display and collect date and time from the user with a specified format. … The DateTimePicker control has two parts, a … …
  • Most searched keywords: Whether you are looking for C# DateTimePicker Control The DateTimePicker control allows you to display and collect date and time from the user with a specified format. … The DateTimePicker control has two parts, a … The DateTimePicker control has two parts, a label that displays the selected date and a popup calendar that allows users to select a new date
  • Table of Contents:
C# DateTimePicker Control
C# DateTimePicker Control

Read More

C# | DateTimePicker Class – GeeksforGeeks

  • Article author: www.geeksforgeeks.org
  • Reviews from users: 32238 ⭐ Ratings
  • Top rated: 3.3 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about C# | DateTimePicker Class – GeeksforGeeks Properties ; MaximumDateTime, This property is used to get the maximum date value allowed for the DateTimePicker control. ; MinDate, This property … …
  • Most searched keywords: Whether you are looking for C# | DateTimePicker Class – GeeksforGeeks Properties ; MaximumDateTime, This property is used to get the maximum date value allowed for the DateTimePicker control. ; MinDate, This property … Data Structures,Algorithms,Python,C,C++,Java,JavaScript,How to,Android Development,SQL,C#,PHP,Golang,Data Science,Machine Learning,PHP,Web Development,System Design,Tutorial,Technical Blogs,School Learning,Interview Experience,Interview Preparation,Programming,Competitive Programming,SDE Sheet,Jobathon,Coding Contests,GATE CSE,Placement,Learn To Code,Aptitude,Quiz,Tips,CSS,HTML,jQuery,Bootstrap,MySQL,NodeJS,React,Angular,Tutorials,Courses,Learn to code,Source codeA Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
  • Table of Contents:

Related Articles

Start Your Coding Journey Now!

C# | DateTimePicker Class - GeeksforGeeks
C# | DateTimePicker Class – GeeksforGeeks

Read More

C# DateTimePicker Control

  • Article author: www.c-sharpcorner.com
  • Reviews from users: 33196 ⭐ Ratings
  • Top rated: 5.0 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about C# DateTimePicker Control A DateTimePicker control allows users to select a date and time in Windows Forms applications. In this tutorial, we will see how to create a … …
  • Most searched keywords: Whether you are looking for C# DateTimePicker Control A DateTimePicker control allows users to select a date and time in Windows Forms applications. In this tutorial, we will see how to create a … CSharp DateTimePicker,DateTimePicker C#A DateTimePicker control allows users to select a date and time in Windows Forms applications. In this tutorial, we will see how to create a DateTimePicker control at design-time as well as at run-time, set its properties and call its methods.
  • Table of Contents:
C# DateTimePicker Control
C# DateTimePicker Control

Read More

Chuyển đổi datetimepicker trong c# – programming – Dạy Nhau Học

  • Article author: daynhauhoc.com
  • Reviews from users: 48591 ⭐ Ratings
  • Top rated: 4.9 ⭐
  • Lowest rated: 1 ⭐
  • Summary of article content: Articles about Chuyển đổi datetimepicker trong c# – programming – Dạy Nhau Học c-sharp · nguyen_huan (Nguyễn Huấn) November 29, 2018, 4:34pm #1. em chuyển đổi datetimepicker vào csdl thì báo lỗi ko thể chuyển đổi là sao ạ …
  • Most searched keywords: Whether you are looking for Chuyển đổi datetimepicker trong c# – programming – Dạy Nhau Học c-sharp · nguyen_huan (Nguyễn Huấn) November 29, 2018, 4:34pm #1. em chuyển đổi datetimepicker vào csdl thì báo lỗi ko thể chuyển đổi là sao ạ em chuyển đổi datetimepicker vào csdl thì báo lỗi ko thể chuyển đổi là sao ạ
    private void button22_Click(object sender, EventArgs e)
    {
    if (mahang.TextLength == 0 || cc.TextLength == 0 || tc.TextLength == 0)
    {
  • Table of Contents:
Chuyển đổi datetimepicker trong c# - programming - Dạy Nhau Học
Chuyển đổi datetimepicker trong c# – programming – Dạy Nhau Học

Read More


See more articles in the same category here: https://chewathai27.com/to/blog.

[C#] Hướng dẫn sử dụng DateTimePicker

Chia sẻ

Giới thiệu

Đôi khi lập trình viên xây dựng các ứng dụng có chức năng lựa chọn ngày tháng, thì đó là lúc họ cần phải sử dụng tới điều khiển DateTimePicker. Điều khiển DateTimePicker cho phép hiển thị và lựa chọn ngày và thời gian theo định dạng. Để hiểu rõ hơn về DateTimePicker, các bạn hãy đọc kỹ bài này cũng như thực hành viết ứng dụng theo đoạn code bên dưới nhé.

Điều khiển DateTimePicker có 2 phần (hình trên), phần thứ nhất là 1 Label để hiển thị ngày tháng đã lựa chọn, và phần thứ 2 là 01 bảng lịch dưới dạng Popup cho phép người dùng lựa chọn ngày tháng. Thuộc tính quan trọng nhất của điều khiển DateTimePicker đó là thuộc tính Value, nó cho phép lưu trữ thông tin về ngày tháng đã được người sử dụng lựa chọn. Chúng ta có thể gán giá trị cho thuộc tính Value trong khi chạy ứng dụng như sau:

dateTimePicker1.Value = DateTime.Today;

Để lưu lại giá trị của thuộc tính Value của điều khiển DateTimePicker , chúng ta sử dụng biến đối tượng DateTime, như dưới đây.

DateTime iDate; iDate = dateTimePicker1.Value;

Điều khiển DateTimePicker có một vài lựa chọn kiểu hiển thị ngày tháng, cụ thể gồm có 4 định dạng hiển thị gồm các kiểu: Long, Short, Time, hoặc dạng Custom, chúng ta có thể thay đổi kiểu hiển thị như sau:

dateTimePicker1.Format = DateTimePickerFormat.Short;

Chương trình

using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { dateTimePicker1.Format = DateTimePickerFormat.Short; dateTimePicker1.Value = DateTime.Today; } private void button1_Click(object sender, EventArgs e) { DateTime iDate; iDate = dateTimePicker1.Value; MessageBox.Show(“Bạn đã lựa chọn: ” + iDate); } } }

Kết luận

Như vậy, trên đây csharpcanban.com đã Hướng dẫn các bạn xây dựng ứng dụng sử dụng điều khiển DateTimePicker bằng C#. Thực sự là quá đơn giản đúng không các bạn. Hãy đặt câu hỏi trong phần bình luận ở dưới đây. Csharpcanban.com sẽ trả lời các bạn chi tiết nhất.

Trong các bài tiếp theo mình sẽ tiếp tục hướng dẫn các bạn sử dụng Microsoft Visual Studio C#, sử dụng các Control trong C#, đó là sử dụng Combobox, Listbox, Radio Button, và nhiều Control khác, hãy thường xuyên theo dõi website csharpcanban.com để cập nhật các bài học mới nhé các bạn.

Bản quyền

Nội dung trên csharpcanban.com được biên soạn, biên dịch từ nhiều nguồn khác nhau, đồng thời đã được viết thành chương trình chạy. Csharpcanban.Com bảo lưu mọi quyền đối với những bài viết này. Mọi hình thức sao chép đều cần phải được Csharpcanban.Com cấp phép.

Chia sẻ

DateTimePicker Class (System.Windows.Forms)

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.

The following code example creates an new instance of a DateTimePicker control and initializes it. The control’s CustomFormat property is set. Also, the ShowCheckBox property is set so that the control displays a CheckBox, and the ShowUpDown property is set so that the control is displayed as a spin button control. To run this example, paste the following code into a form and call the CreateMyDateTimePicker method in the example form’s constructor or Load event handling method.

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.

The DateTimePicker control only supports Gregorian calendars.

When used to represent a date, the DateTimePicker control appears in two parts: a drop-down list with a date represented in text, and a calendar that appears when you click the down-arrow next to the list. The calendar looks like the MonthCalendar control, which can be used for selecting multiple dates. For more information about the MonthCalendar control, see MonthCalendar Control Overview.

You can change the look of the calendar portion of the control by setting the CalendarForeColor, CalendarFont, CalendarTitleBackColor, CalendarTitleForeColor, CalendarTrailingForeColor, and CalendarMonthBackground properties.

To use a spin button control (also known as an up-down control) to adjust the date/time value, set the ShowUpDown property to true . The calendar will not drop down when the control is selected. The date and time can be adjusted by selecting each element individually and using the up and down buttons to change the value.

The Value property contains the current date and time the control is set to. You can use the Text property or the appropriate member of Value to get the date and time value. For more information, see How to: Set and Return Dates with the Windows Forms DateTimePicker Control. You can limit the dates and times that can be selected by setting the MinDate and MaxDate properties.

The values can be displayed in four formats, which are set by the Format property: Long, Short, Time, or Custom. The default date Format is DateTimePickerFormat.Long.

If you want the DateTimePicker to appear as a control for picking or editing times instead of dates, set the ShowUpDown property to true and the Format property to Time. For more information, see How to: Display Time with the DateTimePicker Control.

If the Format property is set to DateTimePickerFormat.Custom, you can create your own format style by setting the CustomFormat property and building a custom format string. The custom format string can be a combination of custom field characters and other literal characters. For example, you can display the date as “June 01, 2012 – Friday” by setting the CustomFormat property to “MMMM dd, yyyy – dddd”. For more information, see How to: Display a Date in a Custom Format with the Windows Forms DateTimePicker Control and Custom Date and Time Format Strings.

When a DateTimePicker is data-bound and the backing value is changed to null , the value of the DateTimePicker will not be updated and the previous value will be retained. In situations where this behavior is not desirable (for example, when using a set of data-bound controls to page through a recordset) use the Format event of the Binding class to set the DateTimePicker to a value recognizable as a null .

Initializes a new instance of the DateTimePicker class.

Gets the minimum date value of the DateTimePicker control.

Specifies the maximum date value of the DateTimePicker control. This field is read-only.

Specifies the default trailing foreground color of the DateTimePicker control. This field is read-only.

Specifies the default title foreground color of the DateTimePicker control. This field is read-only.

Specifies the default title back color of the DateTimePicker control. This field is read-only.

Specifies the default month background color of the DateTimePicker control. This field is read-only.

This property is not relevant for this class.

Gets or sets the width of the control.

Gets or sets a value indicating whether the control and all its child controls are displayed.

Gets or sets the date/time value assigned to the control.

Gets or sets a value indicating whether to use the wait cursor for the current control and all child controls.

Gets the parent control that is not parented by another Windows Forms control. Typically, this is the outermost Form that the control is contained in.

Gets or sets the distance, in pixels, between the top edge of the control and the top edge of its container’s client area.

Gets or sets the text associated with this control.

Gets or sets the object that contains data about the control.

Gets or sets a value indicating whether the user can give the focus to this control using the TAB key.

Gets or sets the tab order of the control within its container.

Gets or sets the height and width of the control.

Gets or sets the site of the control.

Gets or sets a value indicating whether a spin button control (also known as an up-down control) is used to adjust the date/time value.

Gets a value indicating whether the user interface is in the appropriate state to show or hide keyboard accelerators.

Gets a value indicating whether the control should display focus rectangles.

Gets or sets a value indicating whether a check box is displayed to the left of the selected date.

Gets a value that determines the scaling of child controls.

Gets or sets whether the contents of the DateTimePicker are laid out from right to left.

Gets or sets a value indicating whether control’s elements are aligned to support locales using right-to-left fonts.

Gets the distance, in pixels, between the right edge of the control and the left edge of its container’s client area.

Gets or sets a value indicating whether the control redraws itself when resized.

This property is now obsolete.

Gets or sets the window region associated with the control.

Gets a value indicating whether the control is currently re-creating its handle.

Gets the version of the assembly containing the control.

Gets the product name of the assembly containing the control.

Gets the size of a rectangular area into which the control can fit.

Gets the preferred height of the DateTimePicker control.

Gets or sets the parent container of the control.

Gets or sets padding within the control.

Gets or sets the spacing between the contents of the DateTimePicker control and its edges.

Gets or sets the name of the control.

Gets or sets the size that is the lower limit that GetPreferredSize(Size) can specify.

Gets the minimum date value allowed for the DateTimePicker control.

Gets or sets the minimum date and time that can be selected in the control.

Gets or sets the size that is the upper limit that GetPreferredSize(Size) can specify.

Gets the maximum date value allowed for the DateTimePicker control.

Gets or sets the maximum date and time that can be selected in the control.

Gets or sets the space between controls.

Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.

Gets or sets the distance, in pixels, between the left edge of the control and the left edge of its container’s client area.

Gets a cached instance of the control’s layout engine.

Gets a value indicating whether the control is mirrored.

Gets a value indicating whether the control has a handle associated with it.

Gets a value indicating whether the control has been disposed of.

Indicates if one of the Ancestors of this control is sited and that site in DesignMode. This property is read-only.

Gets or sets a value indicating whether the control is visible to accessibility applications.

Gets a value indicating whether the caller must call an invoke method when making method calls to the control because the caller is on a different thread than the one the control was created on.

Gets or sets the IME mode of a control.

Gets or sets the Input Method Editor (IME) mode of the control.

Gets or sets the height of the control.

Gets a value indicating whether the control contains one or more child controls.

Gets the window handle that the control is bound to.

Gets or sets the format of the date and time displayed in the control.

Gets or sets the foreground color of the DateTimePicker control.

Gets or sets the height of the font of the control.

Gets or sets the font of the text displayed by the control.

Gets a value indicating whether the control has input focus.

Gets the list of event handlers that are attached to this Component .

Gets or sets a value indicating whether the control can respond to user interaction.

Gets or sets the alignment of the drop-down calendar on the DateTimePicker control.

Gets or sets a value indicating whether this control should redraw its surface using a secondary buffer to reduce or prevent flicker.

Gets or sets a value indicating whether the control should redraw its surface using a secondary buffer. Setting this property has no effect on the DateTimePicker control.

Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.

Gets a value indicating whether the base Control class is in the process of disposing.

Gets the rectangle that represents the display area of the control.

Gets the DPI value for the display device where the control is currently being displayed.

Gets a value that indicates whether the Component is currently in design mode.

Gets the default size of the control.

Gets the internal spacing, in pixels, of the contents of a control.

Gets the length and height, in pixels, that is specified as the default minimum size of a control.

Gets the length and height, in pixels, that is specified as the default maximum size of a control.

Gets the space, in pixels, that is specified by default between controls.

Gets the default Input Method Editor (IME) mode supported by the control.

Gets or sets the default cursor for the control.

Gets the data bindings for the control.

Gets or sets the custom date/time format string.

Gets or sets the cursor that is displayed when the mouse pointer is over the control.

Gets the required creation parameters when the control handle is created.

Gets a value indicating whether the control has been created.

Gets the collection of controls contained within the control.

Gets or sets the ContextMenuStrip associated with this control.

Gets or sets the shortcut menu associated with the control.

Gets a value indicating whether the control, or one of its child controls, currently has the input focus.

Gets the IContainer that contains the Component .

Gets the name of the company or creator of the application containing the control.

Gets or sets the height and width of the client area of the control.

Gets the rectangle that represents the client area of the control.

Gets or sets a value indicating whether the Value property has been set with a valid date/time value and the displayed value is able to be updated.

Gets or sets a value indicating whether the control causes validation to be performed on any controls that require validation when it receives focus.

Gets or sets a value indicating whether the control has captured the mouse.

Gets a value indicating whether the control can be selected.

Determines if events can be raised on the control.

Gets a value indicating whether the control can receive focus.

Gets a value indicating whether the ImeMode property can be set to an active value, to enable IME support.

Gets or sets the foreground color of the calendar trailing dates.

Gets or sets the foreground color of the calendar title.

Gets or sets the background color of the calendar title.

Gets or sets the background color of the calendar month.

Gets or sets the foreground color of the calendar.

Gets or sets the font style applied to the calendar.

Gets or sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control.

Gets the distance, in pixels, between the top edge of the control and the top edge of its container’s client area.

Gets or sets the BindingContext for the control.

Gets or sets the background image layout as defined in the ImageLayout enumeration.

Gets or sets the layout of the background image of the DateTimePicker control.

Gets or sets the background image for the control.

Gets or sets a value indicating the background color of the DateTimePicker control.

This property is not relevant for this class.

Gets or sets where this control is scrolled to in ScrollControlIntoView(Control) .

Gets or sets the edges of the container to which a control is bound and determines how a control is resized with its parent.

Gets or sets a value indicating whether the control can accept data that the user drags onto it.

Gets or sets the accessible role of the control.

Gets or sets the name of the control used by accessibility client applications.

Gets or sets the description of the control used by accessibility client applications.

Gets or sets the default action description of the control for use by accessibility client applications.

Gets the AccessibleObject assigned to the control.

AccessibilityNotifyClients(AccessibleEvents, Int32) Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control. (Inherited from Control)

AccessibilityNotifyClients(AccessibleEvents, Int32, Int32) Notifies the accessibility client applications of the specified AccessibleEvents for the specified child control . (Inherited from Control)

BeginInvoke(Action) Executes the specified delegate asynchronously on the thread that the control’s underlying handle was created on. (Inherited from Control)

BeginInvoke(Delegate) Executes the specified delegate asynchronously on the thread that the control’s underlying handle was created on. (Inherited from Control)

BeginInvoke(Delegate, Object[]) Executes the specified delegate asynchronously with the specified arguments, on the thread that the control’s underlying handle was created on. (Inherited from Control)

BringToFront() Brings the control to the front of the z-order. (Inherited from Control)

Contains(Control) Retrieves a value indicating whether the specified control is a child of the control. (Inherited from Control)

CreateAccessibilityInstance() Creates a new accessibility object for the DateTimePicker control.

CreateControl() Forces the creation of the visible control, including the creation of the handle and any visible child controls. (Inherited from Control)

CreateControlsInstance() Creates a new instance of the control collection for the control. (Inherited from Control)

CreateGraphics() Creates the Graphics for the control. (Inherited from Control)

CreateHandle() Creates the physical window handle.

CreateObjRef(Type) Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject)

DefWndProc(Message) Sends the specified message to the default window procedure. (Inherited from Control)

DestroyHandle() Destroys the physical window handle.

Dispose() Releases all resources used by the Component. (Inherited from Component)

Dispose(Boolean) Releases the unmanaged resources used by this control and its child controls and optionally releases the managed resources.

Dispose(Boolean) Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources. (Inherited from Control)

DrawToBitmap(Bitmap, Rectangle) Supports rendering to the specified bitmap. (Inherited from Control)

EndInvoke(IAsyncResult) Retrieves the return value of the asynchronous operation represented by the IAsyncResult passed. (Inherited from Control)

Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object)

FindForm() Retrieves the form that the control is on. (Inherited from Control)

Focus() Sets input focus to the control. (Inherited from Control)

GetAccessibilityObjectById(Int32) Retrieves the specified AccessibleObject. (Inherited from Control)

GetAutoSizeMode() Retrieves a value indicating how a control will behave when its AutoSize property is enabled. (Inherited from Control)

GetChildAtPoint(Point) Retrieves the child control that is located at the specified coordinates. (Inherited from Control)

GetChildAtPoint(Point, GetChildAtPointSkip) Retrieves the child control that is located at the specified coordinates, specifying whether to ignore child controls of a certain type. (Inherited from Control)

GetContainerControl() Returns the next ContainerControl up the control’s chain of parent controls. (Inherited from Control)

GetHashCode() Serves as the default hash function. (Inherited from Object)

GetLifetimeService() Obsolete. Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject)

GetNextControl(Control, Boolean) Retrieves the next control forward or back in the tab order of child controls. (Inherited from Control)

GetPreferredSize(Size) Retrieves the size of a rectangular area into which a control can be fitted. (Inherited from Control)

GetScaledBounds(Rectangle, SizeF, BoundsSpecified) Retrieves the bounds within which the control is scaled. (Inherited from Control)

GetService(Type) Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component)

GetStyle(ControlStyles) Retrieves the value of the specified control style bit for the control. (Inherited from Control)

GetTopLevel() Determines if the control is a top-level control. (Inherited from Control)

GetType() Gets the Type of the current instance. (Inherited from Object)

Hide() Conceals the control from the user. (Inherited from Control)

InitializeLifetimeService() Obsolete. Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject)

InitLayout() Called after the control has been added to another container. (Inherited from Control)

Invalidate() Invalidates the entire surface of the control and causes the control to be redrawn. (Inherited from Control)

Invalidate(Boolean) Invalidates a specific region of the control and causes a paint message to be sent to the control. Optionally, invalidates the child controls assigned to the control. (Inherited from Control)

Invalidate(Rectangle) Invalidates the specified region of the control (adds it to the control’s update region, which is the area that will be repainted at the next paint operation), and causes a paint message to be sent to the control. (Inherited from Control)

Invalidate(Rectangle, Boolean) Invalidates the specified region of the control (adds it to the control’s update region, which is the area that will be repainted at the next paint operation), and causes a paint message to be sent to the control. Optionally, invalidates the child controls assigned to the control. (Inherited from Control)

Invalidate(Region) Invalidates the specified region of the control (adds it to the control’s update region, which is the area that will be repainted at the next paint operation), and causes a paint message to be sent to the control. (Inherited from Control)

Invalidate(Region, Boolean) Invalidates the specified region of the control (adds it to the control’s update region, which is the area that will be repainted at the next paint operation), and causes a paint message to be sent to the control. Optionally, invalidates the child controls assigned to the control. (Inherited from Control)

Invoke(Action) Executes the specified delegate on the thread that owns the control’s underlying window handle. (Inherited from Control)

Invoke(Delegate) Executes the specified delegate on the thread that owns the control’s underlying window handle. (Inherited from Control)

Invoke(Delegate, Object[]) Executes the specified delegate, on the thread that owns the control’s underlying window handle, with the specified list of arguments. (Inherited from Control)

Invoke(Func) Executes the specified delegate on the thread that owns the control’s underlying window handle. (Inherited from Control)

InvokeGotFocus(Control, EventArgs) Raises the GotFocus event for the specified control. (Inherited from Control)

InvokeLostFocus(Control, EventArgs) Raises the LostFocus event for the specified control. (Inherited from Control)

InvokeOnClick(Control, EventArgs) Raises the Click event for the specified control. (Inherited from Control)

InvokePaint(Control, PaintEventArgs) Raises the Paint event for the specified control. (Inherited from Control)

InvokePaintBackground(Control, PaintEventArgs) Raises the PaintBackground event for the specified control. (Inherited from Control)

IsInputChar(Char) Determines if a character is an input character that the control recognizes. (Inherited from Control)

IsInputKey(Keys) Determines whether the specified key is a regular input key or a special key that requires preprocessing.

LogicalToDeviceUnits(Int32) Converts a Logical DPI value to its equivalent DeviceUnit DPI value. (Inherited from Control)

LogicalToDeviceUnits(Size) Transforms a size from logical to device units by scaling it for the current DPI and rounding down to the nearest integer value for width and height. (Inherited from Control)

MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object)

MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject)

NotifyInvalidate(Rectangle) Raises the Invalidated event with a specified region of the control to invalidate. (Inherited from Control)

OnAutoSizeChanged(EventArgs) Raises the AutoSizeChanged event. (Inherited from Control)

OnBackColorChanged(EventArgs) Raises the BackColorChanged event. (Inherited from Control)

OnBackgroundImageChanged(EventArgs) Raises the BackgroundImageChanged event. (Inherited from Control)

OnBackgroundImageLayoutChanged(EventArgs) Raises the BackgroundImageLayoutChanged event. (Inherited from Control)

OnBindingContextChanged(EventArgs) Raises the BindingContextChanged event. (Inherited from Control)

OnCausesValidationChanged(EventArgs) Raises the CausesValidationChanged event. (Inherited from Control)

OnChangeUICues(UICuesEventArgs) Raises the ChangeUICues event. (Inherited from Control)

OnClick(EventArgs) Raises the Click event. (Inherited from Control)

OnClientSizeChanged(EventArgs) Raises the ClientSizeChanged event. (Inherited from Control)

OnCloseUp(EventArgs) Raises the CloseUp event.

OnContextMenuChanged(EventArgs) Raises the ContextMenuChanged event. (Inherited from Control)

OnContextMenuStripChanged(EventArgs) Raises the ContextMenuStripChanged event. (Inherited from Control)

OnControlAdded(ControlEventArgs) Raises the ControlAdded event. (Inherited from Control)

OnControlRemoved(ControlEventArgs) Raises the ControlRemoved event. (Inherited from Control)

OnCreateControl() Raises the CreateControl() method. (Inherited from Control)

OnCursorChanged(EventArgs) Raises the CursorChanged event. (Inherited from Control)

OnDockChanged(EventArgs) Raises the DockChanged event. (Inherited from Control)

OnDoubleClick(EventArgs) Raises the DoubleClick event. (Inherited from Control)

OnDpiChangedAfterParent(EventArgs) Raises the DpiChangedAfterParent event. (Inherited from Control)

OnDpiChangedBeforeParent(EventArgs) Raises the DpiChangedBeforeParent event. (Inherited from Control)

OnDragDrop(DragEventArgs) Raises the DragDrop event. (Inherited from Control)

OnDragEnter(DragEventArgs) Raises the DragEnter event. (Inherited from Control)

OnDragLeave(EventArgs) Raises the DragLeave event. (Inherited from Control)

OnDragOver(DragEventArgs) Raises the DragOver event. (Inherited from Control)

OnDropDown(EventArgs) Raises the DropDown event.

OnEnabledChanged(EventArgs) Raises the EnabledChanged event. (Inherited from Control)

OnEnter(EventArgs) Raises the Enter event. (Inherited from Control)

OnFontChanged(EventArgs) Raises the FontChanged event.

OnForeColorChanged(EventArgs) Raises the ForeColorChanged event. (Inherited from Control)

OnFormatChanged(EventArgs) Raises the FormatChanged event.

OnGiveFeedback(GiveFeedbackEventArgs) Raises the GiveFeedback event. (Inherited from Control)

OnGotFocus(EventArgs) Raises the GotFocus event. (Inherited from Control)

OnHandleCreated(EventArgs) Raises the HandleCreated event.

OnHandleCreated(EventArgs) Raises the HandleCreated event. (Inherited from Control)

OnHandleDestroyed(EventArgs) Raises the HandleDestroyed event.

OnHandleDestroyed(EventArgs) Raises the HandleDestroyed event. (Inherited from Control)

OnHelpRequested(HelpEventArgs) Raises the HelpRequested event. (Inherited from Control)

OnImeModeChanged(EventArgs) Raises the ImeModeChanged event. (Inherited from Control)

OnInvalidated(InvalidateEventArgs) Raises the Invalidated event. (Inherited from Control)

OnKeyDown(KeyEventArgs) Raises the KeyDown event. (Inherited from Control)

OnKeyPress(KeyPressEventArgs) Raises the KeyPress event. (Inherited from Control)

OnKeyUp(KeyEventArgs) Raises the KeyUp event. (Inherited from Control)

OnLayout(LayoutEventArgs) Raises the Layout event. (Inherited from Control)

OnLeave(EventArgs) Raises the Leave event. (Inherited from Control)

OnLocationChanged(EventArgs) Raises the LocationChanged event. (Inherited from Control)

OnLostFocus(EventArgs) Raises the LostFocus event. (Inherited from Control)

OnMarginChanged(EventArgs) Raises the MarginChanged event. (Inherited from Control)

OnMouseCaptureChanged(EventArgs) Raises the MouseCaptureChanged event. (Inherited from Control)

OnMouseClick(MouseEventArgs) Raises the MouseClick event. (Inherited from Control)

OnMouseDoubleClick(MouseEventArgs) Raises the MouseDoubleClick event. (Inherited from Control)

OnMouseDown(MouseEventArgs) Raises the MouseDown event. (Inherited from Control)

OnMouseEnter(EventArgs) Raises the MouseEnter event. (Inherited from Control)

OnMouseHover(EventArgs) Raises the MouseHover event. (Inherited from Control)

OnMouseLeave(EventArgs) Raises the MouseLeave event. (Inherited from Control)

OnMouseMove(MouseEventArgs) Raises the MouseMove event. (Inherited from Control)

OnMouseUp(MouseEventArgs) Raises the MouseUp event. (Inherited from Control)

OnMouseWheel(MouseEventArgs) Raises the MouseWheel event. (Inherited from Control)

OnMove(EventArgs) Raises the Move event. (Inherited from Control)

OnNotifyMessage(Message) Notifies the control of Windows messages. (Inherited from Control)

OnPaddingChanged(EventArgs) Raises the PaddingChanged event. (Inherited from Control)

OnPaint(PaintEventArgs) Raises the Paint event. (Inherited from Control)

OnPaintBackground(PaintEventArgs) Paints the background of the control. (Inherited from Control)

OnParentBackColorChanged(EventArgs) Raises the BackColorChanged event when the BackColor property value of the control’s container changes. (Inherited from Control)

OnParentBackgroundImageChanged(EventArgs) Raises the BackgroundImageChanged event when the BackgroundImage property value of the control’s container changes. (Inherited from Control)

OnParentBindingContextChanged(EventArgs) Raises the BindingContextChanged event when the BindingContext property value of the control’s container changes. (Inherited from Control)

OnParentChanged(EventArgs) Raises the ParentChanged event. (Inherited from Control)

OnParentCursorChanged(EventArgs) Raises the CursorChanged event. (Inherited from Control)

OnParentEnabledChanged(EventArgs) Raises the EnabledChanged event when the Enabled property value of the control’s container changes. (Inherited from Control)

OnParentFontChanged(EventArgs) Raises the FontChanged event when the Font property value of the control’s container changes. (Inherited from Control)

OnParentForeColorChanged(EventArgs) Raises the ForeColorChanged event when the ForeColor property value of the control’s container changes. (Inherited from Control)

OnParentRightToLeftChanged(EventArgs) Raises the RightToLeftChanged event when the RightToLeft property value of the control’s container changes. (Inherited from Control)

OnParentVisibleChanged(EventArgs) Raises the VisibleChanged event when the Visible property value of the control’s container changes. (Inherited from Control)

OnPreviewKeyDown(PreviewKeyDownEventArgs) Raises the PreviewKeyDown event. (Inherited from Control)

OnPrint(PaintEventArgs) Raises the Paint event. (Inherited from Control)

OnQueryContinueDrag(QueryContinueDragEventArgs) Raises the QueryContinueDrag event. (Inherited from Control)

OnRegionChanged(EventArgs) Raises the RegionChanged event. (Inherited from Control)

OnResize(EventArgs) Raises the Resize event. (Inherited from Control)

OnRightToLeftChanged(EventArgs) Raises the RightToLeftChanged event. (Inherited from Control)

OnRightToLeftLayoutChanged(EventArgs) Raises the RightToLeftLayout event.

OnSizeChanged(EventArgs) Raises the SizeChanged event. (Inherited from Control)

OnStyleChanged(EventArgs) Raises the StyleChanged event. (Inherited from Control)

OnTabIndexChanged(EventArgs) Raises the TabIndexChanged event. (Inherited from Control)

OnTabStopChanged(EventArgs) Raises the TabStopChanged event. (Inherited from Control)

OnTextChanged(EventArgs) Raises the TextChanged event. (Inherited from Control)

OnValidated(EventArgs) Raises the Validated event. (Inherited from Control)

OnValidating(CancelEventArgs) Raises the Validating event. (Inherited from Control)

OnValueChanged(EventArgs) Raises the ValueChanged event.

OnVisibleChanged(EventArgs) Raises the VisibleChanged event. (Inherited from Control)

PerformLayout() Forces the control to apply layout logic to all its child controls. (Inherited from Control)

PerformLayout(Control, String) Forces the control to apply layout logic to all its child controls. (Inherited from Control)

PointToClient(Point) Computes the location of the specified screen point into client coordinates. (Inherited from Control)

PointToScreen(Point) Computes the location of the specified client point into screen coordinates. (Inherited from Control)

PreProcessControlMessage(Message) Preprocesses keyboard or input messages within the message loop before they are dispatched. (Inherited from Control)

PreProcessMessage(Message) Preprocesses keyboard or input messages within the message loop before they are dispatched. (Inherited from Control)

ProcessCmdKey(Message, Keys) Processes a command key. (Inherited from Control)

ProcessDialogChar(Char) Processes a dialog character. (Inherited from Control)

ProcessDialogKey(Keys) Processes a dialog key. (Inherited from Control)

ProcessKeyEventArgs(Message) Processes a key message and generates the appropriate control events. (Inherited from Control)

ProcessKeyMessage(Message) Processes a keyboard message. (Inherited from Control)

ProcessKeyPreview(Message) Previews a keyboard message. (Inherited from Control)

ProcessMnemonic(Char) Processes a mnemonic character. (Inherited from Control)

RaiseDragEvent(Object, DragEventArgs) Raises the appropriate drag event. (Inherited from Control)

RaiseKeyEvent(Object, KeyEventArgs) Raises the appropriate key event. (Inherited from Control)

RaiseMouseEvent(Object, MouseEventArgs) Raises the appropriate mouse event. (Inherited from Control)

RaisePaintEvent(Object, PaintEventArgs) Raises the appropriate paint event. (Inherited from Control)

RecreateHandle() Forces the re-creation of the handle for the control. (Inherited from Control)

RectangleToClient(Rectangle) Computes the size and location of the specified screen rectangle in client coordinates. (Inherited from Control)

RectangleToScreen(Rectangle) Computes the size and location of the specified client rectangle in screen coordinates. (Inherited from Control)

Refresh() Forces the control to invalidate its client area and immediately redraw itself and any child controls. (Inherited from Control)

RescaleConstantsForDpi(Int32, Int32) Provides constants for rescaling the control when a DPI change occurs. (Inherited from Control)

ResetBackColor() Resets the BackColor property to its default value. (Inherited from Control)

ResetBindings() Causes a control bound to the BindingSource to reread all the items in the list and refresh their displayed values. (Inherited from Control)

ResetCursor() Resets the Cursor property to its default value. (Inherited from Control)

ResetFont() Resets the Font property to its default value. (Inherited from Control)

ResetForeColor() Resets the ForeColor property to its default value. (Inherited from Control)

ResetImeMode() Resets the ImeMode property to its default value. (Inherited from Control)

ResetMouseEventArgs() Resets the control to handle the MouseLeave event. (Inherited from Control)

ResetRightToLeft() Resets the RightToLeft property to its default value. (Inherited from Control)

ResetText() Resets the Text property to its default value (Empty). (Inherited from Control)

ResumeLayout() Resumes usual layout logic. (Inherited from Control)

ResumeLayout(Boolean) Resumes usual layout logic, optionally forcing an immediate layout of pending layout requests. (Inherited from Control)

RtlTranslateAlignment(ContentAlignment) Converts the specified ContentAlignment to the appropriate ContentAlignment to support right-to-left text. (Inherited from Control)

RtlTranslateAlignment(HorizontalAlignment) Converts the specified HorizontalAlignment to the appropriate HorizontalAlignment to support right-to-left text. (Inherited from Control)

RtlTranslateAlignment(LeftRightAlignment) Converts the specified LeftRightAlignment to the appropriate LeftRightAlignment to support right-to-left text. (Inherited from Control)

RtlTranslateContent(ContentAlignment) Converts the specified ContentAlignment to the appropriate ContentAlignment to support right-to-left text. (Inherited from Control)

RtlTranslateHorizontal(HorizontalAlignment) Converts the specified HorizontalAlignment to the appropriate HorizontalAlignment to support right-to-left text. (Inherited from Control)

RtlTranslateLeftRight(LeftRightAlignment) Converts the specified LeftRightAlignment to the appropriate LeftRightAlignment to support right-to-left text. (Inherited from Control)

Scale(Single) Obsolete. Obsolete. Scales the control and any child controls. (Inherited from Control)

Scale(Single, Single) Obsolete. Obsolete. Scales the entire control and any child controls. (Inherited from Control)

Scale(SizeF) Scales the control and all child controls by the specified scaling factor. (Inherited from Control)

ScaleBitmapLogicalToDevice(Bitmap) Scales a logical bitmap value to it’s equivalent device unit value when a DPI change occurs. (Inherited from Control)

ScaleControl(SizeF, BoundsSpecified) Scales a control’s location, size, padding and margin. (Inherited from Control)

ScaleCore(Single, Single) This method is not relevant for this class. (Inherited from Control)

Select() Activates the control. (Inherited from Control)

Select(Boolean, Boolean) Activates a child control. Optionally specifies the direction in the tab order to select the control from. (Inherited from Control)

SendToBack() Sends the control to the back of the z-order. (Inherited from Control)

SetAutoSizeMode(AutoSizeMode) Sets a value indicating how a control will behave when its AutoSize property is enabled. (Inherited from Control)

SetBounds(Int32, Int32, Int32, Int32) Sets the bounds of the control to the specified location and size. (Inherited from Control)

SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified) Sets the specified bounds of the control to the specified location and size. (Inherited from Control)

SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) Performs the work of setting the specified bounds of this control.

SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) Performs the work of setting the specified bounds of this control. (Inherited from Control)

SetClientSizeCore(Int32, Int32) Sets the size of the client area of the control. (Inherited from Control)

SetStyle(ControlStyles, Boolean) Sets a specified ControlStyles flag to either true or false . (Inherited from Control)

SetTopLevel(Boolean) Sets the control as the top-level control. (Inherited from Control)

SetVisibleCore(Boolean) Sets the control to the specified visible state. (Inherited from Control)

Show() Displays the control to the user. (Inherited from Control)

SizeFromClientSize(Size) Determines the size of the entire control from the height and width of its client area. (Inherited from Control)

SuspendLayout() Temporarily suspends the layout logic for the control. (Inherited from Control)

ToString() Returns a string that represents the current DateTimePicker control.

Update() Causes the control to redraw the invalidated regions within its client area. (Inherited from Control)

UpdateBounds() Updates the bounds of the control with the current size and location. (Inherited from Control)

UpdateBounds(Int32, Int32, Int32, Int32) Updates the bounds of the control with the specified size and location. (Inherited from Control)

UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32) Updates the bounds of the control with the specified size, location, and client size. (Inherited from Control)

UpdateStyles() Forces the assigned styles to be reapplied to the control. (Inherited from Control)

UpdateZOrder() Updates the control in its parent’s z-order. (Inherited from Control)

Cách dùng DateTimePicker – MonthCalendar trong C# (winforms)

Trong bài này chúng ta sẽ tìm hiểu hai đối tượng DateTimePicker và MonthCalendar trong C#, đây là hai điều khiển được sử dụng để hiển thị ngày tháng dưới hai hình thức khác nhau trong lập trình Winforms.

Bài viết này được đăng tại freetuts.net , không được copy dưới mọi hình thức.

Chúng ta sẽ cùng nhau tim hiểu về công dụng cũng như các thuộc tính và phương thức, sự kiện của DateTimePicker và MonthCalendar nhé. Sau đó mình sẽ thực hiện một chương trình áp dụng hai điều khiển trên.

1. DateTimePicker trong C#

Điều khiển DateTimePicker cho phép người dùng chọn ngày tháng như một lịch biểu nhưng biểu diễn ở dạng ComboBox.

Các đối tượng ngày tháng biểu diễn trong DateTimePicker thực chất là các đối tượng thuộc lớp DateTime. Điều khiển DateTimePicker được đặt trong nhóm Common Controls của cửa sổ ToolBox.

Bài viết này được đăng tại [free tuts .net]

Một số thuộc tính thường dùng trong DateTimePicker:

Thuộc tính Mô tả Format Đinh dạng kiểu hiển thị của ngày tháng *Lưu ý: Thường sử dụng giá trị kiểu Short Value Trả về giá trị hiện thời của điều khiển DateTimePicker Value.Date Trả về ngày tháng năm Value.Day Trả về ngày của tháng Value.Month Trả về tháng Value.Year Trả về năm Value.DateOfWeek Trả về ngày của tuần (0 là chủ nhật, 1 là thứ hai, …, 6 là thứ bảy) CustomFormat Cho phép lập trình tạo ra một đinh dạng khác nhau về ngày tháng. *Lưu ý: Đinh dạng ngày tháng năm như kiểu Việt Nam thì kiểu định dạng phải là dd/MM/yyyy. Khi đó thuộc tính Format phải thiết lập là Cusom MaxDate Thiết lập ngày lớn nhất cho phép người dùng chọn trên điều khiển DateTimePicker MinDate Thiết lập ngày nhỏ nhất cho phép người dùng chọn trên điều khiển DateTimePicker

Một số sự kiện thường dùng:

Sự kiện Mô tả ValueChanged Phát sinh khi người đung chọn giá trị khác với giá trị trước đó trên điều khiển DateTimePicker CloseUp Phát sinh người dùng kết thúc việc chọn ngày trên điều khiển DateTimePicker

2. MonthCalendar trong C#

MonthCalendar là điều khiển hiển thị lịch dưới dạng một lịch biểu cho phép người dùng chọn ngày tháng. Nhưng khác biệt là MonthCalendar cho phép người dùng có thể chọn một tập các ngày hay nói cách khác là một tập các đối tượng thuộc lớp DateTime.

Điều khiển MonthCalendar được đặt trong nhóm Common Controls.

Một số thuộc tính thường dùng:

Thuộc tính Mô tả MaxDate Thiết lập ngày lớn nhất cho phép người dùng chọn trên điều khiển MonthCalendar MinDate Thiết lập ngày nhỏ nhất cho phép người dùng chọn trên điều khiển MonthCalendar SelectionRange Trả về một dãy các ngày liên tục được chọn bởi người dùng SelectionStart Trả về ngày đầu tiên trong dãy tại thuộc tính SelectionRange SelectionEnd Trả về ngày cuối cùng trong dãy tại thuộc tính SelectionRange AnnuallyBoldedDates Chứa một mảng các ngày. Trong mỗi năm, các ngày trong mảng sẽ được bôi đen MonthCalendar BoldedDates Chứa mảng các ngày. Các ngày này sẽ được bôi den trên điều khiển MonthCalendar tại những năm chỉ định MaxSelectCount Thiết lập số lượng ngày tối đa mà người dùng có thể chọn MonthlyBoldedDates Chứa mảng các ngày trong mỗi tháng, các ngày trong mảng sẽ được bôi đen trên MonthCalendar

Trong MonthCalendar có một sự kiện được sử dụng rất thông dụng đó chính là DateChanged. Đây là một sự kiện được phát sinh khi một ngày mới hoặc một dãy các ngày mới được chọn.

3. Ví dụ sử dụng DateTimePicker và MonthCalendar trong C#

Trong ví dụ này mình sẽ thực hiện viết chương trình có sử dụng DateTimePicker và MonthCalendar để các bạn hiểu rõ hơn về công dụng cũng như cách nó hoạt động.

Ví dụ sử dụng điều khiển DateTimePicker

Trong ví dụ đầu tiên này mình sẽ thực hiện một chương trình đơn giản trong đó có sử dụng DateTimePicker, cụ thể sẽ thực hiện theo Form dưới đây với một số chức năng tương ứng.

Chương trình có các chức năng như sau:

TextBox ” Họ Tên “: Chỉ cho phép nhập ký tự hoa hoặc thường, cho phép nhập khoảng trắng và cho phép xóa lùi.

“: Chỉ cho phép nhập ký tự hoa hoặc thường, cho phép nhập khoảng trắng và cho phép xóa lùi. TextBox ” Số Điện Thoại “: Chỉ cho phép nhập số và được xóa lùi.

“: Chỉ cho phép nhập số và được xóa lùi. DateTimePicker ” Thời Gian “: Chỉ cho phép chọn thời gian đăng ký học lớn hơn thời gian hiện tại.

“: Chỉ cho phép chọn thời gian đăng ký học lớn hơn thời gian hiện tại. Button ” Đăng ký “: Hiển thị hộp thoại bao gồm các nội dung trong ô TextBox và thời gian được chọn trong DateTimePicker.

“: Hiển thị hộp thoại bao gồm các nội dung trong ô TextBox và thời gian được chọn trong DateTimePicker. Button “Thoát”: Đóng chương trình.

Đầu tiên chúng ta sẽ tạo Form tương tự như trên:

Một số Label với nội dung tương ứng.

3 TextBox để nhập tên, sđt, email.

2 Button để đăng ký và thoát.

1 DateTimePicker để chọn thời gian học.

Sau khi tạo được Form, ta sẽ bắt đầu xử lý sự kiện cho từng TextBox và Button.

Bước 1: Xử lý sự kiện cho TextBox “Họ Tên”, với chức năng chỉ cho phép nhập lý tự hoa hoặc thường. cho phép nhập khoảng trắng và xóa lùi.

Ta sẽ viết trên sự kiện KeyPress trong TextBox, sử dụng KeyChar để làm điều kiện.

private void txtHoTen_KeyPress(object sender, KeyPressEventArgs e) { if (!((e.KeyChar >= ‘a’ && e.KeyChar <= 'z') ||(e.KeyChar == ' ')|| (e.KeyChar >= ‘A’ && e.KeyChar <= 'Z') || e.KeyChar == (char)8)) e.Handled = true; } Bước 2: Xử lý sự kiện cho TextBox "Số Điện Thoại", với chức năng chỉ cho phép nhập số và được xóa lùi. Tương tự như TextBox "Họ Tên" ta cũng sẽ sử dụng KeyPress và KeyChar để viết điều kiện. private void txtSDT_KeyPress(object sender, KeyPressEventArgs e) { if (!(e.KeyChar >= ‘0’ && e.KeyChar <= '9' || e.KeyChar == (char)8)) e.Handled = true; } Bước 3: Xử lý sự kiện cho DateTimePicker "Thời Gian", với chức năng chỉ cho phép chọn thời gian đăng ký học lớn hơn thời gian hiện tại. Ta sẽ viết sự kiện ở FormLoad. private void Form1_Load(object sender, EventArgs e) { dateTimePicker1.MinDate = DateTime.Now; int dayofmonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); dateTimePicker1.MaxDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, dayofmonth); } Bước 4: Xử lý sự kiện cho Button "Đăng Ký", với chức năng sẽ hiển thị nội dung trong các ô TextBox và thời gian được chọn trong DateTimePicker trên hộp thoại MessageBox. private void btnDangKy_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtHoTen.Text) || string.IsNullOrEmpty(txtSDT.Text) || string.IsNullOrEmpty(txtEmail.Text)) { MessageBox.Show("Bạn chưa nhập đầy đủ thông tin"); } else if (!string.IsNullOrEmpty(txtHoTen.Text) || !string.IsNullOrEmpty(txtSDT.Text) || !string.IsNullOrEmpty(txtEmail.Text) == true) { MessageBox.Show("Chúc mừng bạn: " + txtHoTen.Text + " Số Điện Thoại: " + txtSDT.Text + " Email: " + txtEmail.Text + " Thời gian lựa chọn: " + dateTimePicker1.Value.ToShortDateString()); } } Bước 5: Xử lý sự kiện cho Button "Thoát", với chức năng sẽ đóng chương trình khi người dùng nhấn vào nút này. private void bntThoat_Click(object sender, EventArgs e) { Application.Exit(); } Kết quả: Full Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Cau5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnDangKy_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtHoTen.Text) || string.IsNullOrEmpty(txtSDT.Text) || string.IsNullOrEmpty(txtEmail.Text)) { MessageBox.Show("Bạn chưa nhập đầy đủ thông tin"); } else if (!string.IsNullOrEmpty(txtHoTen.Text) || !string.IsNullOrEmpty(txtSDT.Text) || !string.IsNullOrEmpty(txtEmail.Text) == true) { MessageBox.Show("Chúc mừng bạn: " + txtHoTen.Text + " Số Điện Thoại: " + txtSDT.Text + " Email: " + txtEmail.Text + " Thời gian lựa chọn: " + dateTimePicker1.Value.ToShortDateString()); } } private void txtHoTen_KeyPress(object sender, KeyPressEventArgs e) { if (!((e.KeyChar >= ‘a’ && e.KeyChar <= 'z') ||(e.KeyChar == ' ')|| (e.KeyChar >= ‘A’ && e.KeyChar <= 'Z') || e.KeyChar == (char)8)) e.Handled = true; } private void txtSDT_KeyPress(object sender, KeyPressEventArgs e) { if (!(e.KeyChar >= ‘0’ && e.KeyChar <= '9' || e.KeyChar == (char)8)) e.Handled = true; } private void Form1_Load(object sender, EventArgs e) { dateTimePicker1.MinDate = DateTime.Now; int dayofmonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); dateTimePicker1.MaxDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, dayofmonth); } private void bntThoat_Click(object sender, EventArgs e) { Application.Exit(); } } } Ví dụ sử dụng điều khiển MonthCalendar Trong ví dụ này mình sẽ thực hiện viết một chương trình trong đó có sử dụng MonthCalendar, cụ thể ta sẽ tạo giao diện như Form dưới đây với các chức năng tương ứng. Các chức năng trong chương trình: Button " Hiển thị ": Hiển thị ngày bắt đầu chọn (SelectionStart), ngày cuối cùng chọn (SelectionEnd), MinDate, MaxDate, Today. ": Hiển thị ngày bắt đầu chọn (SelectionStart), ngày cuối cùng chọn (SelectionEnd), MinDate, MaxDate, Today. Button " Count Day ": Đếm tổng ngày từ lúc SelectionStart đến SelectionEnd. ": Đếm tổng ngày từ lúc SelectionStart đến SelectionEnd. Button "Count Hour": Đếm tổng giờ từ lúc SelectionStart đến SelectionEnd. Việc đầu tiên ta cần tạo giao diện cho Form tương tự như Form ở trên, bao gồm: Các Label với nội dung tương ứng. 7 TextBox để hiển thị các nội dung. 3 Button để viết sự kiện. 1 MonthCalendar làm lịch biểu. Tiếp đến ta sẽ lần lượt viết các chức năng cho chương trình. Bước 1: Xử lý sự kiện cho Button "Hiển thị", với chức năng hiển thị ngày bắt đầu và ngày cuối cùng được chọn, MinDate, MaxDate, Today. private void btnHienthi_Click(object sender, EventArgs e) { txtStart.Text = monthCalendar1.SelectionStart.ToShortDateString(); txtEnd.Text = monthCalendar1.SelectionEnd.ToShortDateString(); txtmin.Text = monthCalendar1.MinDate.ToShortDateString(); txtMax.Text = monthCalendar1.MaxDate.ToShortDateString(); txtDayDate.Text = monthCalendar1.TodayDate.ToShortDateString(); } Bước 2: Xử lý sự kiện cho Button "Count Day", với chức năng đếm số ngày được chọn. private void btnCountday_Click(object sender, EventArgs e) { int numdays; numdays = Convert.ToInt32((monthCalendar1.SelectionEnd - monthCalendar1.SelectionStart).TotalDays); txtday.Text = numdays.ToString(); } Bước 3: Xử lý sự kiện cho Button "Count Hour", với chức năng đếm số giờ được chọn. private void btnCountHour_Click(object sender, EventArgs e) { int numhour; numhour = Convert.ToInt32((monthCalendar1.SelectionEnd - monthCalendar1.SelectionStart).TotalHours); txthour.Text = numhour.ToString(); } Kết quả: Full Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Cau2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnHienthi_Click(object sender, EventArgs e) { txtStart.Text = monthCalendar1.SelectionStart.ToShortDateString(); txtEnd.Text = monthCalendar1.SelectionEnd.ToShortDateString(); txtmin.Text = monthCalendar1.MinDate.ToShortDateString(); txtMax.Text = monthCalendar1.MaxDate.ToShortDateString(); txtDayDate.Text = monthCalendar1.TodayDate.ToShortDateString(); } private void btnCountday_Click(object sender, EventArgs e) { int numdays; numdays = Convert.ToInt32((monthCalendar1.SelectionEnd - monthCalendar1.SelectionStart).TotalDays); txtday.Text = numdays.ToString(); } private void btnCountHour_Click(object sender, EventArgs e) { int numhour; numhour = Convert.ToInt32((monthCalendar1.SelectionEnd - monthCalendar1.SelectionStart).TotalHours); txthour.Text = numhour.ToString(); } private void Form1_Load(object sender, EventArgs e) { } } } 4. Kết luận Như vậy là chúng ta đã tìm hiểu xong về DateTimePick và MonthCalendar trong lập trình C# winforms. Đây là hai điều khiển khá quan trọng và được sử dụng nhiều, vì vậy các bạn hãy luyện tập nhiều để có thể thành thạo nó nhé. Ở bài tiếp theo mình sẽ tiếp tục giới thiệu các bạn các điều khiển quan trọng khác trong C# winforms. Các bạn nhớ chú ý theo dõi nhé !!! là

So you have finished reading the datetimepicker c# topic article, if you find this article useful, please share it. Thank you very much. See more: Datetimepicker, Truyền dữ liệu vào DateTimePicker, DateTimePicker C#, DateTimePicker format, DateTimePicker C# Windows Form, bootstrap-datetimepicker, Datetimepicker jQuery, datetimepicker format dd/mm/yyyy c#

Leave a Comment