簡體   English   中英

C#Telerik Winforms DateTimePicker日歷大小

[英]C# telerik Winforms DateTimePicker Calendar Size

嗨,我目前在一個涉及使用DateTimePicker控件的項目中工作,作為系統UI的負責人,我希望控件能夠“響應(在Web開發中)”,以便在任何屏幕尺寸下,控件將進行調整,但是直到遇到dateTimePIcker的日歷下拉列表時,在初始化之后的運行時中,每次我為CalendarSize分配新的大小都不會繼承或我真的不知道發生了什么時,所以窗口大小我希望下拉日歷具有與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;
}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM