This is a migrated thread and some comments may be shown as answers.

DateTimePicker AutoSize doesn't resize

5 Answers 718 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
strombringer
Top achievements
Rank 2
strombringer asked on 28 Mar 2009, 08:18 PM
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".

5 Answers, 1 is accepted

Sort by
0
Accepted
Boyko Markov
Telerik team
answered on 30 Mar 2009, 12:33 PM
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.
0
strombringer
Top achievements
Rank 2
answered on 01 Apr 2009, 11:14 AM
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 :-).


0
Boyko Markov
Telerik team
answered on 03 Apr 2009, 02:55 PM
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.
0
Naveed Sorush
Top achievements
Rank 1
answered on 16 Jul 2010, 07:29 PM
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

 

 

0
Nikolay
Telerik team
answered on 19 Jul 2010, 07:30 PM
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
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
strombringer
Top achievements
Rank 2
Answers by
Boyko Markov
Telerik team
strombringer
Top achievements
Rank 2
Naveed Sorush
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or