using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class GetYear : Form
{
public
GetYear()
{
InitializeComponent();
}
private
void btnGet_Click(object
sender, EventArgs e)
{
//
how to validate textbox
in windows application..........
foreach
(Control cc in
this.Controls)
{
if
(cc.GetType() == typeof(TextBox))
{
if
(cc.Text == "")
{
MessageBox.Show("Please enter
dob in this format mm/dd/yyyy");
return;
}
}
}
//
code for
get years,months,days with dob(Date of Birth)
int
days, currentyear, dobyear;
int
c = 0;
int
i;
days = (int)DateTime.Now.Subtract(Convert.ToDateTime(txtdob.Text)).TotalDays;
currentyear = (int)DateTime.Now.Year;
dobyear = (Convert.ToDateTime(txtdob.Text).Year);
ldays.Text = "No of Days = " + days.ToString();
for
(i = dobyear; i <= currentyear; i++)
{
if
((i % 400 == 0) || (i % 4 == 0 && i % 100 != 0))
++c;
}
lnoofleapyear.Text = "No of Leap Year = " + c.ToString();
if
(days > 365)
{
days = days - c;
}
lyear.Text = "Year = " + (days / 365).ToString();
days = days % 365;
lyear.Text += " Months = " + (days / 30).ToString();
lyear.Text += " Days = " + (days % 30).ToString();
}
//First we add Timer Control in Windows Form and set this property
·
Enabled=true
·
Interval=1000
//this code for change Form’s color each second.....
private
void timer1_Tick(object
sender, EventArgs e)
{
Random
rr = new Random();
string
color = rr.Next(100000, 999999).ToString();
this.BackColor
= System.Drawing.ColorTranslator.FromHtml("#" + color);
}
}
}
0 comments:
Post a Comment