We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How can I change the width of the DateTimePickerAdv when it is set to custom format?

 

It is possible to adjust the width of the DateTimePickerAdv according to the custom format given. The width of the DateTimePickerAdv is calculated by adding the following:

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

C#

this.dateTimePickerAdv3.ShowCheckBox = false;

this.dateTimePickerAdv3.ShowUpDown = true;

this.dateTimePickerAdv3.AutoSize = false;

this.dateTimePickerAdv3.AutoSizeMode = AutoSizeMode.GrowOnly;

this.dateTimePickerAdv3.Format = DateTimePickerFormat.Custom;

this.dateTimePickerAdv3.CustomFormat = "dd/MMM";

int updownWidth = 0, dropWidth = 0;

foreach (Control ctrl in this.dateTimePickerAdv3.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.dateTimePickerAdv3.Font.Size *

this.dateTimePickerAdv3.Value.ToString(this.dateTimePickerAdv3.CustomFormat).Length);

this.dateTimePickerAdv3.Width = nWidth;

VB

Me.dateTimePickerAdv3.ShowCheckBox = False

Me.dateTimePickerAdv3.ShowUpDown = True

Me.dateTimePickerAdv3.AutoSize = False

Me.dateTimePickerAdv3.AutoSizeMode = AutoSizeMode.GrowOnly

Me.dateTimePickerAdv3.Format = DateTimePickerFormat.Custom

Me.dateTimePickerAdv3.CustomFormat = "dd/MMM"

Dim updownWidth As Integer = 0, dropWidth As Integer = 0

For Each ctrl As Control In Me.dateTimePickerAdv3.Controls

If ctrl.GetType().ToString() = "Syncfusion.Windows.Forms.Tools.DateTimePickerUpDownButton" Then

updownWidth = ctrl.Size.Width

Else If 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.dateTimePickerAdv3.Font.Size * Me.dateTimePickerAdv3.Value.ToString(Me.dateTimePickerAdv3.CustomFormat).Length)

Me.dateTimePickerAdv3.Width = nWidth

Sample:

http://websamples.syncfusion.com/samples/KB/Tools.Windows/KB_CustomDatetimePickerAdv/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
1770 04/30/2011 07/10/2014 Windows Forms DateTimePickerAdv
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.