C# telerik Winforms DateTimePicker 日历大小
C# telerik Winforms DateTimePicker Calendar Size
您好,我目前在做一个项目,涉及到DateTimePicker控件的使用,作为系统UI的负责人,我将我的控件设置为"responsive (in web dev)"所以在任何屏幕尺寸下,我的控件都会对其进行调整,但直到我遇到 dateTimePIcker 的日历下拉列表,在每次初始化后的运行时中,我为 CalendarSize 分配一个新尺寸时都没有被继承,或者我真的不知道是什么发生了,所以在更改 window 大小时,我希望我的下拉日历具有与 dateTimePicker 相同的宽度,并通过公式构造高度。
顺便说一句:我的 DateTimePicker 锚定在顶部、左侧、右侧,因此宽度会发生变化。
在我的代码中:
private void ResizeDateTimePicker()
{
int dtpCurrWidth = this.dateTimePicker.Size.Width;
int dtpCurrHeight = dtpCurrWidth - (dtpCurrWidth / 2);
((Telerik.WinControls.UI.RadDateTimePickerElement)(this.dateTimePicker.GetChildAt(0))).CalendarSize = new System.Drawing.Size(dtpCurrWidth, 200);
//I change the Calendar Size of the DateTimePicker with this code because this is how telerik change the CalendarSize in Design View
}
在我的设计中:
this.dateTimePicker.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dateTimePicker.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.dateTimePicker.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Bold);
this.dateTimePicker.Location = new System.Drawing.Point(79, 28);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(377, 37);
this.dateTimePicker.TabIndex = 0;
this.dateTimePicker.TabStop = false;
this.dateTimePicker.Text = "Friday, September 7, 2012";
this.dateTimePicker.ThemeName = "Material";
this.dateTimePicker.SizeChanged += new System.EventHandler(this.dateTimePicker_sizeChanged);
this.dateTimePicker.Value = new System.DateTime(2012, 9, 7, 0, 0, 0, 0);
((Telerik.WinControls.Primitives.FillPrimitive)(this.dateTimePicker.GetChildAt(0).GetChildAt(0))).SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
((Telerik.WinControls.UI.RadMaskedEditBoxElement)(this.dateTimePicker.GetChildAt(0).GetChildAt(2).GetChildAt(1))).Text = "Friday, September 7, 2012";
((Telerik.WinControls.UI.RadTextBoxItem)(this.dateTimePicker.GetChildAt(0).GetChildAt(2).GetChildAt(1).GetChildAt(0))).Alignment = System.Drawing.ContentAlignment.MiddleLeft;
找到了一个解决方案,其中我可以像这样修改它的最小和最大大小而不是修改日历的大小。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radDateTimePicker1.SizeChanged += RadDateTimePicker1_SizeChanged;
}
private void RadDateTimePicker1_SizeChanged(object sender, EventArgs e)
{
int width = this.radDateTimePicker1.Width;
int height = 300;//calculate it according to your formula
Size desiredSize = new Size(width, height);
RadDateTimePickerCalendar cal = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
// Control popup size
cal.DropDownMinSize = desiredSize;
cal.DropDownMaxSize = desiredSize;
}
}
您好,我目前在做一个项目,涉及到DateTimePicker控件的使用,作为系统UI的负责人,我将我的控件设置为"responsive (in web dev)"所以在任何屏幕尺寸下,我的控件都会对其进行调整,但直到我遇到 dateTimePIcker 的日历下拉列表,在每次初始化后的运行时中,我为 CalendarSize 分配一个新尺寸时都没有被继承,或者我真的不知道是什么发生了,所以在更改 window 大小时,我希望我的下拉日历具有与 dateTimePicker 相同的宽度,并通过公式构造高度。 顺便说一句:我的 DateTimePicker 锚定在顶部、左侧、右侧,因此宽度会发生变化。 在我的代码中:
private void ResizeDateTimePicker()
{
int dtpCurrWidth = this.dateTimePicker.Size.Width;
int dtpCurrHeight = dtpCurrWidth - (dtpCurrWidth / 2);
((Telerik.WinControls.UI.RadDateTimePickerElement)(this.dateTimePicker.GetChildAt(0))).CalendarSize = new System.Drawing.Size(dtpCurrWidth, 200);
//I change the Calendar Size of the DateTimePicker with this code because this is how telerik change the CalendarSize in Design View
}
在我的设计中:
this.dateTimePicker.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dateTimePicker.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.dateTimePicker.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Bold);
this.dateTimePicker.Location = new System.Drawing.Point(79, 28);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(377, 37);
this.dateTimePicker.TabIndex = 0;
this.dateTimePicker.TabStop = false;
this.dateTimePicker.Text = "Friday, September 7, 2012";
this.dateTimePicker.ThemeName = "Material";
this.dateTimePicker.SizeChanged += new System.EventHandler(this.dateTimePicker_sizeChanged);
this.dateTimePicker.Value = new System.DateTime(2012, 9, 7, 0, 0, 0, 0);
((Telerik.WinControls.Primitives.FillPrimitive)(this.dateTimePicker.GetChildAt(0).GetChildAt(0))).SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
((Telerik.WinControls.UI.RadMaskedEditBoxElement)(this.dateTimePicker.GetChildAt(0).GetChildAt(2).GetChildAt(1))).Text = "Friday, September 7, 2012";
((Telerik.WinControls.UI.RadTextBoxItem)(this.dateTimePicker.GetChildAt(0).GetChildAt(2).GetChildAt(1).GetChildAt(0))).Alignment = System.Drawing.ContentAlignment.MiddleLeft;
找到了一个解决方案,其中我可以像这样修改它的最小和最大大小而不是修改日历的大小。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.radDateTimePicker1.SizeChanged += RadDateTimePicker1_SizeChanged;
}
private void RadDateTimePicker1_SizeChanged(object sender, EventArgs e)
{
int width = this.radDateTimePicker1.Width;
int height = 300;//calculate it according to your formula
Size desiredSize = new Size(width, height);
RadDateTimePickerCalendar cal = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
// Control popup size
cal.DropDownMinSize = desiredSize;
cal.DropDownMaxSize = desiredSize;
}
}