using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace customDialog { /// /// Summary description for Form1. /// public class CustomDialog : System.Windows.Forms.Form { private System.Windows.Forms.Label birthdayLabel; private System.Windows.Forms.Label yearLabel; private System.Windows.Forms.Label yearValue; private System.Windows.Forms.Button birthdayButton; // manually added private Birthday birthdayDialog; private System.Windows.Forms.Label signLabel; private System.Windows.Forms.Label signValue; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public CustomDialog() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // birthdayDialog = new Birthday(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.birthdayLabel = new System.Windows.Forms.Label(); this.yearLabel = new System.Windows.Forms.Label(); this.yearValue = new System.Windows.Forms.Label(); this.birthdayButton = new System.Windows.Forms.Button(); this.signLabel = new System.Windows.Forms.Label(); this.signValue = new System.Windows.Forms.Label(); this.SuspendLayout(); // // birthdayLabel // this.birthdayLabel.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.birthdayLabel.Location = new System.Drawing.Point(16, 16); this.birthdayLabel.Name = "birthdayLabel"; this.birthdayLabel.Size = new System.Drawing.Size(184, 23); this.birthdayLabel.TabIndex = 0; this.birthdayLabel.Text = "Days to next Birthday"; // // yearLabel // this.yearLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.yearLabel.Location = new System.Drawing.Point(16, 48); this.yearLabel.Name = "yearLabel"; this.yearLabel.Size = new System.Drawing.Size(72, 23); this.yearLabel.TabIndex = 5; this.yearLabel.Text = "Days to wait"; // // yearValue // this.yearValue.Location = new System.Drawing.Point(104, 48); this.yearValue.Name = "yearValue"; this.yearValue.Size = new System.Drawing.Size(96, 23); this.yearValue.TabIndex = 6; this.yearValue.Text = "days till birthday"; // // birthdayButton // this.birthdayButton.Location = new System.Drawing.Point(64, 120); this.birthdayButton.Name = "birthdayButton"; this.birthdayButton.Size = new System.Drawing.Size(89, 23); this.birthdayButton.TabIndex = 7; this.birthdayButton.Text = "select birthday"; this.birthdayButton.Click += new System.EventHandler(this.birthdayButton_Click); // // signLabel // this.signLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.signLabel.Location = new System.Drawing.Point(16, 80); this.signLabel.Name = "signLabel"; this.signLabel.Size = new System.Drawing.Size(72, 23); this.signLabel.TabIndex = 8; this.signLabel.Text = "Zodiac Sign"; // // signValue // this.signValue.Location = new System.Drawing.Point(104, 80); this.signValue.Name = "signValue"; this.signValue.Size = new System.Drawing.Size(96, 23); this.signValue.TabIndex = 9; this.signValue.Text = "sign value"; // // CustomDialog // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(216, 157); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.signValue, this.signLabel, this.birthdayButton, this.yearValue, this.yearLabel, this.birthdayLabel}); this.Name = "CustomDialog"; this.Text = "Custom Dialog"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new CustomDialog()); } private void birthdayButton_Click(object sender, System.EventArgs e){ DateTime today, birthday; int days, todayDay, birthdayDay; if (birthdayDialog.ShowDialog() == DialogResult.OK) { signValue.Text = birthdayDialog.Sign; today = birthdayDialog.Today; birthday = birthdayDialog.DateAndTime; todayDay = today.DayOfYear; birthdayDay = birthday.DayOfYear; if (todayDay == birthdayDay) { yearValue.Text = "Happy Birthday"; return; } else if (todayDay < birthdayDay) days = birthdayDay - todayDay; else days = 365 - (todayDay - birthdayDay); yearValue.Text = days.ToString(); } } } }