NEWS

[DEVEXPRESS] Thêm button Next and Previous trên Component DateEdit

[DEVEXPRESS] Thêm button Next and Previous trên Component DateEdit
Đăng bởi: Thảo Meo - Lượt xem: 3813 10:13:14, 16/03/2020DEVEXPRESS   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách thêm button Previous và Next trong DateEdit của Devexpress C#.

[DEVEXPRESS] Add Button Next And Previous in DateEdit C#

Trong công cụ, DateEdit của Devexpress cho phép các bạn chọn ngày tháng.

Tuy nhiên, nếu chúng ta muốn lùi về một ngày hoặc tới tiếp một ngày, thay vì chúng ta phải xổ combo Date ra để chọn thì sẽ mất thời gian nhiều hơn.

Nếu chúng ta thiết kế thêm 2 button Next và Previous cho DateEdit thì sẽ tiện lợi hơn.

Các bạn có thể nhìn demo ứng dụng bên dưới đây, mình di chuyển ngày rất dễ dàng và nhanh chóng.

next_pre_dateedit_thumb

Để sử dụng, đầu tiên các bạn kéo component Date Edit ra vào chọn thuộc tính Button và thêm vào hai button như hình bên dưới:

dateedit_devexpress

Và tiếp theo các bạn chọn thuộc tính Button Click để viết sự kiện cho 2 button  left và right mình mới thêm vào.

Full source code DateEdit Devexpress C#:

using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PreNextDateEdit
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
            dateEdit1.EditValue = DateTime.Now;
        }

        private void dateEdit1_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            DateEdit edit = dateEdit1;
            if (edit.EditValue == null) return;
            switch (e.Button.Kind)
            {
                case DevExpress.XtraEditors.Controls.ButtonPredefines.Left:
                    edit.EditValue = ((DateTime)edit.EditValue).AddDays(-1);
                    break;
                case DevExpress.XtraEditors.Controls.ButtonPredefines.Right:
                    edit.EditValue = ((DateTime)edit.EditValue).AddDays(1);
                    break;
                default:
                    break;
            }
        }
    }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[DEVEXPRESS] Thêm button Next and Previous trên Component DateEdit
Đăng bởi: Thảo Meo - Lượt xem: 3813 10:13:14, 16/03/2020DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.