2017-09-29 8 views
0

Salut Je travaille actuellement dans un projet qui implique l'utilisation du contrôle DateTimePicker, en tant que peroson en charge de l'interface utilisateur du système, je voudrais que mes contrôles à "responsive (en web dev) "de sorte que dans toutes les tailles d'écran mon contrôle s'y adaptera, mais jusqu'à ce que je rencontre le calendrier de la dateTimePIcker, dans l'exécution après l'initialisation chaque fois que j'attribue une nouvelle taille pour le CalendarSize n'est pas héritée ou je ne Je sais vraiment ce qui se passe, donc lors du changement de la taille de la fenêtre, je veux que mon calendrier déroulant ait la même largeur de la dateTimePicker et construise la hauteur par une formule. BTW: Mon DateTimePicker est Anchored Top, Left, Right de sorte que la largeur change. Dans mon code:C# telerik Winforms DateTimePicker Calendar Taille

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 
    } 

Dans ma conception:

  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; 

Répondre

0

une solution trouvé, dans laquelle au lieu de modifier la taille du calendrier que je peux modifier sa taille min et max comme ça.

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; 
} 

}