using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
class MainClass : Window
{
TextBox txtboxBegin = new TextBox();
TextBox txtboxEnd = new TextBox();
Label lblLifeYears = new Label();
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new MainClass());
}
public MainClass()
{
SizeToContent = SizeToContent.WidthAndHeight;
ResizeMode = ResizeMode.CanMinimize;
Grid grid = new Grid();
Content = grid;
for (int i = 0; i < 2; i++)
{
RowDefinition rowdef = new RowDefinition();
rowdef.Height = GridLength.Auto;
grid.RowDefinitions.Add(rowdef);
}
for (int i = 0; i < 2; i++)
{
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = GridLength.Auto;
grid.ColumnDefinitions.Add(coldef);
}
Label lbl = new Label();
lbl.Content = "Begin Date: ";
grid.Children.Add(lbl);
Grid.SetRow(lbl, 0);
Grid.SetColumn(lbl, 0);
txtboxBegin.Text = new DateTime(1980, 1, 1).ToShortDateString();
txtboxBegin.TextChanged += TextBoxOnTextChanged;
grid.Children.Add(txtboxBegin);
Grid.SetRow(txtboxBegin, 0);
Grid.SetColumn(txtboxBegin, 1);
lbl = new Label();
lbl.Content = "End Date: ";
grid.Children.Add(lbl);
Grid.SetRow(lbl, 1);
Grid.SetColumn(lbl, 0);
txtboxEnd.TextChanged += TextBoxOnTextChanged;
grid.Children.Add(txtboxEnd);
Grid.SetRow(txtboxEnd, 1);
Grid.SetColumn(txtboxEnd, 1);
Thickness thick = new Thickness(5); // ~1/20 inch.
grid.Margin = thick;
foreach (Control ctrl in grid.Children)
ctrl.Margin = thick;
txtboxBegin.Focus();
txtboxEnd.Text = DateTime.Now.ToShortDateString();
}
void TextBoxOnTextChanged(object sender, TextChangedEventArgs args)
{
Console.WriteLine(txtboxBegin.Text);
lblLifeYears.Content = "string";
}
}
|