Articles in this section
Category / Section

How to Change Width of WinForm DateTimePicker when in Standard Format?

1 min read

Date time Format

It is possible to adjust the width of the WinForms DateTimePicker when it is in standard format. The width of the DateTimePickerAdv is calculated by adding the following constraints.

  • Width of the DateTimePickerUpDownButton
  • Width of the DateTimePickerDropButton
  • Font size of the DateTimePickerAdv
  • The length of the DataTimePickerAdv's Value in the specified standard format.

C#

//New font size is set here.
this.dateTimePickerAdv1.Font = new Font("Tahoma", 13);
this.dateTimePickerAdv1.ShowCheckBox = false;
this.dateTimePickerAdv1.ShowUpDown = true;
this.dateTimePickerAdv1.AutoSize = false;
this.dateTimePickerAdv1.AutoSizeMode = AutoSizeMode.GrowOnly;
this.dateTimePickerAdv1.Format = DateTimePickerFormat.Long;
int updownWidth = 0, dropWidth = 0;
 
//Calculating the UpDown and DropDown button width
foreach (Control ctrl in this.dateTimePickerAdv1.Controls)
{
    if (ctrl.GetType().ToString() == "Syncfusion.Windows.Forms.Tools.DateTimePickerUpDownButton")
        updownWidth = ctrl.Size.Width;
    else if (ctrl.GetType().ToString() == "Syncfusion.Windows.Forms.Tools.DateTimePickerDropButton")
        dropWidth = ctrl.Size.Width;
}
 
//Sum up the width of drop down button, updown button and font.
int nWidth = dropWidth + updownWidth + Convert.ToInt32(this.dateTimePickerAdv1.Font.Size * this.dateTimePickerAdv1.Value.ToLongDateString().Length);
this.dateTimePickerAdv1.Width = nWidth;

 

VB

''Font is set
Me.DateTimePickerAdv2.Font = New Font("Tahoma", 13)
Me.DateTimePickerAdv2.ShowCheckBox = False
Me.DateTimePickerAdv2.ShowUpDown = True
Me.DateTimePickerAdv2.AutoSize = False
Me.DateTimePickerAdv2.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly
Me.DateTimePickerAdv2.Format = DateTimePickerFormat.Long
Dim updownWidth As Integer = 0, dropWidth As Integer = 0
 
''Calculating the UpDown and DropDown button width
For Each ctrl As Control In Me.DateTimePickerAdv2.Controls
   If ctrl.GetType().ToString() = "Syncfusion.Windows.Forms.Tools.DateTimePickerUpDownButton" Then
      updownWidth = ctrl.Size.Width
   ElseIf ctrl.GetType().ToString() = "Syncfusion.Windows.Forms.Tools.DateTimePickerDropButton" Then
      dropWidth = ctrl.Size.Width
   End If
Next ctrl
 
''Sum up the width of drop down button, updown button and font.
Dim nWidth As Integer = dropWidth + updownWidth + Convert.ToInt32(Me.DateTimePickerAdv2.Font.Size * Me.DateTimePickerAdv2.Value.ToLongDateString().Length)
Me.DateTimePickerAdv2.Width = nWidth

Conclusion

I hope you enjoyed learning about how to change width of WinForm DateTimePicker when in standard format.

You can refer to our WinForms DateTimePicker featuretour page to know about its other groundbreaking feature representations and documentation, to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied