|
1 | | -# How-to-create-a-DatePicker-in-Winforms-using-ButtonEdit-and-MonthCalendarAdv |
2 | | -Create a DatePicker using ButtonEdit and MonthCalendarAdv |
3 | | - |
4 | | -# C# |
5 | | - MonthCalendarAdv monthCalendarAdv = new MonthCalendarAdv(); |
6 | | - public Form1() |
7 | | - { |
8 | | - InitializeComponent(); |
9 | | - |
10 | | - childButton.Click += ChildButton_Click; |
11 | | - |
12 | | - calendarPopup.Controls.Add(monthCalendarAdv); |
13 | | - buttonEdit1.Buttons.Add(childButton); |
14 | | - tableLayoutPanel1.Controls.Add(calendarPopup, 0, 1); |
15 | | - monthCalendarAdv.DateSelected += MonthCalendarAdv_DateSelected; |
16 | | - } |
17 | | - |
18 | | - private void MonthCalendarAdv_DateSelected(object sender, EventArgs e) |
19 | | - { |
20 | | - buttonEdit1.TextBox.Text = monthCalendarAdv.Value.ToString(); |
21 | | - calendarPopup.Visible = false; |
22 | | - } |
23 | | - |
24 | | - private void ChildButton_Click(object sender, EventArgs e) |
25 | | - { |
26 | | - calendarPopup.Visible = true; |
27 | | - } |
| 1 | +# How to Create a DatePicker in WinForms Using ButtonEdit and MonthCalendarAdv |
| 2 | +This example demonstrates how to create a DatePicker in a WinForms application using Syncfusion’s ButtonEdit and MonthCalendarAdv controls. Combining these controls provides a user-friendly date selection interface that integrates seamlessly into Windows Forms applications. |
| 3 | + |
| 4 | +## Why This Is Useful |
| 5 | +- Customizable UI: Offers flexibility compared to standard DatePicker controls. |
| 6 | +- Rich Calendar Features: MonthCalendarAdv supports advanced customization. |
| 7 | +- Better UX: Provides an intuitive way for users to select dates. |
| 8 | + |
| 9 | +## How It Works |
| 10 | +- The ButtonEdit control acts as a container with a clickable button. |
| 11 | +- When the button is clicked, a popup containing the MonthCalendarAdv control is displayed. |
| 12 | +- The selected date from the calendar updates the ButtonEdit text box. |
| 13 | + |
| 14 | +## Key Implementation Steps |
| 15 | +- Initialize the MonthCalendarAdv control. |
| 16 | +- Add the calendar to a popup container. |
| 17 | +- Attach the popup to the ButtonEdit control. |
| 18 | +- Handle the DateSelected event to update the text box with the selected date. |
| 19 | +- Toggle the visibility of the calendar popup when the button is clicked. |
| 20 | + |
| 21 | +## Sample Code |
| 22 | +```C# |
| 23 | +MonthCalendarAdv monthCalendarAdv = new MonthCalendarAdv(); |
| 24 | + |
| 25 | +public Form1() |
| 26 | +{ |
| 27 | + InitializeComponent(); |
| 28 | + |
| 29 | + // Attach event handler for button click |
| 30 | + childButton.Click += ChildButton_Click; |
| 31 | + |
| 32 | + // Add calendar to popup and configure layout |
| 33 | + calendarPopup.Controls.Add(monthCalendarAdv); |
| 34 | + buttonEdit1.Buttons.Add(childButton); |
| 35 | + tableLayoutPanel1.Controls.Add(calendarPopup, 0, 1); |
| 36 | + |
| 37 | + // Handle date selection |
| 38 | + monthCalendarAdv.DateSelected += MonthCalendarAdv_DateSelected; |
| 39 | +} |
| 40 | + |
| 41 | +private void MonthCalendarAdv_DateSelected(object sender, EventArgs e) |
| 42 | +{ |
| 43 | + // Update ButtonEdit text with selected date |
| 44 | + buttonEdit1.TextBox.Text = monthCalendarAdv.Value.ToString(); |
| 45 | + calendarPopup.Visible = false; |
| 46 | +} |
| 47 | + |
| 48 | +private void ChildButton_Click(object sender, EventArgs e) |
| 49 | +{ |
| 50 | + // Show calendar popup |
| 51 | + calendarPopup.Visible = true; |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Output |
28 | 56 |
|
29 | 57 | . |
0 commit comments