DateTimePicker AutoSize doesn't resize

6 posts, 1 answers
  1. strombringer
    strombringer avatar
    5 posts
    Member since:
    Mar 2008

    Posted 28 Mar 2009 Link to this post

    Hi!

    With the following code, shouldn't the DateTimePicker be resized automatically to display the complete date?
    // dtp1 is of type RadDateTimePicker 
    dtp1.Format = DateTimePickerFormat.Long; 
    dtp1.AutoSize = true
    dtp1.Value = new DateTime(1982, 9, 20); 
    Because it doesn't on my computer.
    I'm using Vista Business x64, .NET 3.5, Culture "de-DE".
  2. Answer
    Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 30 Mar 2009 Link to this post

    Hi strombringer,

    We do not support AutoSizing by the text shown in the RadDateTimePicker. The only way at the moment for sizing the control is to size it manually. A possible solution could be also to subscribe to ValueChanged event and modify the size of the control. ValueChanged event is fired on every change of datetimepicker Value property.

    Sincerely yours,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. strombringer
    strombringer avatar
    5 posts
    Member since:
    Mar 2008

    Posted 01 Apr 2009 Link to this post

    Thank you for the answer.

    This is the solution I came up with, in case someone else has the same problem:
    using Telerik.WinControls.UI; 
    using System.Windows.Forms; 
    using System.Globalization; 
     
    public class MyDateTimePicker : RadDateTimePicker 
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) 
        { 
            if (this.AutoSize) 
            { 
                DateTimeFormatInfo dateTimeFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat; 
                string format = this.CustomFormat; 
                switch (Format) 
                { 
                    case DateTimePickerFormat.Long: 
                        format = dateTimeFormatInfo.LongDatePattern; 
                        break; 
                    case DateTimePickerFormat.Short: 
                        format = dateTimeFormatInfo.ShortDatePattern; 
                        break; 
                    case DateTimePickerFormat.Time: 
                        format = dateTimeFormatInfo.LongTimePattern; 
                        break; 
                    default: 
                        break; 
                } 
     
                string datevalue = this.Value.ToString(format, dateTimeFormatInfo); 
                float dtpBirthdayWidth = e.Graphics.MeasureString(datevalue, Font, 300).Width; 
                int width = (int)dtpBirthdayWidth + 20; // +20 for the Dropdown-Button 
                if (this.Width != width) 
                    this.Width = width
            } 
            base.OnPaint(e); 
        } 
     
        protected override void OnValueChanged(EventArgs e) 
        { 
            this.Invalidate(); // without this the control won't resize directly 
            base.OnValueChanged(e); 
        } 

    It's not perfect, but enough for me at the moment. One problem when manually entering a date is, that the date sometimes scrolls to the left, you can't see the beginning of the string and have a white empty space between the end of the string and the Dropdown-Button.
    I also didn't test it extensively, so handle with care :-).


  5. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 03 Apr 2009 Link to this post

    Hello strombringer,

    I hope this solution will help someone. Please write me back if you have any other questions or suggestions regarding RadDateTimePicker.

    Regards,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  6. Naveed Sorush
    Naveed Sorush avatar
    3 posts
    Member since:
    Mar 2010

    Posted 16 Jul 2010 Link to this post

    namespace MyNameSpace
    {

     

    public class MyDatePicker : DatePicker
    {

     

     

     

    public MyDatePicker()

     

    {

     

     

     ..............

     

    }

    }

     


    I am trying to create my own DatePicker based on the Telerik DatePicker control for Silverlight and WPF... Where can I find some help on this?

    Thanks,
    Naveed

     

     

  7. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 19 Jul 2010 Link to this post

    Hi Naveed,

    I would kindly ask you to address your question in the appropriate WPF/Silverlight forum sections. This will not confuse those of our clients who enter the current thread and will allow the others interested in your question to find the Telerik response more easily.

    Sincerely yours,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready