Материал из .Net Framework эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
DayOfWeek.Friday
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.DateTimePicker dateTimePickerDropOff;
private System.Windows.Forms.Label outputLabel;
private System.Windows.Forms.Label deliveryLabel;
private System.Windows.Forms.Label dropOffLabel;
public Form1() {
InitializeComponent();
dateTimePickerDropOff.MinDate = DateTime.Today;
dateTimePickerDropOff.MaxDate = DateTime.Today.AddYears( 1 );
}
private void dateTimePickerDropOff_ValueChanged( object sender, EventArgs e )
{
DateTime dropOffDate = dateTimePickerDropOff.Value;
if ( dropOffDate.DayOfWeek == DayOfWeek.Friday ||
dropOffDate.DayOfWeek == DayOfWeek.Saturday ||
dropOffDate.DayOfWeek == DayOfWeek.Sunday )
outputLabel.Text = dropOffDate.AddDays( 3 ).ToLongDateString();
else
outputLabel.Text = dropOffDate.AddDays( 2 ).ToLongDateString();
}
private void InitializeComponent()
{
this.dateTimePickerDropOff = new System.Windows.Forms.DateTimePicker();
this.outputLabel = new System.Windows.Forms.Label();
this.deliveryLabel = new System.Windows.Forms.Label();
this.dropOffLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// dateTimePickerDropOff
//
this.dateTimePickerDropOff.Location = new System.Drawing.Point(31, 39);
this.dateTimePickerDropOff.Name = "dateTimePickerDropOff";
this.dateTimePickerDropOff.Size = new System.Drawing.Size(200, 20);
this.dateTimePickerDropOff.TabIndex = 0;
this.dateTimePickerDropOff.ValueChanged += new System.EventHandler(this.dateTimePickerDropOff_ValueChanged);
//
// outputLabel
//
this.outputLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.outputLabel.Location = new System.Drawing.Point(31, 108);
this.outputLabel.Name = "outputLabel";
this.outputLabel.Size = new System.Drawing.Size(200, 23);
this.outputLabel.TabIndex = 1;
//
// deliveryLabel
//
this.deliveryLabel.AutoSize = true;
this.deliveryLabel.Location = new System.Drawing.Point(30, 95);
this.deliveryLabel.Name = "deliveryLabel";
this.deliveryLabel.Size = new System.Drawing.Size(119, 13);
this.deliveryLabel.TabIndex = 2;
//
// dropOffLabel
//
this.dropOffLabel.AutoSize = true;
this.dropOffLabel.Location = new System.Drawing.Point(30, 23);
this.dropOffLabel.Name = "dropOffLabel";
this.dropOffLabel.Size = new System.Drawing.Size(72, 13);
this.dropOffLabel.TabIndex = 3;
this.dropOffLabel.Text = "Drop Off Date:";
//
// DateTimePickerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(262, 235);
this.Controls.Add(this.dropOffLabel);
this.Controls.Add(this.deliveryLabel);
this.Controls.Add(this.outputLabel);
this.Controls.Add(this.dateTimePickerDropOff);
this.Name = "DateTimePickerForm";
this.Text = "DateTimePickerTest";
this.ResumeLayout(false);
this.PerformLayout();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}