using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Head1Ton.StackTenButtons
{
class StackTenButtons : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new StackTenButtons());
}
public StackTenButtons()
{
Title = "Stack Ten Buttons";
StackPanel stack = new StackPanel();
Content = stack;
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Name = ((char)('A' + i)).ToString();
btn.FontSize += rand.Next(10);
btn.Content = "Button " + btn.Name + " says 'Click me'";
btn.Click += new RoutedEventHandler(ButtonOnClick);
stack.Children.Add(btn);
}
}
void ButtonOnClick(object sender, RoutedEventArgs e)
{
Button btn = e.Source as Button;
MessageBox.Show("Button " + btn.Name + " has been clicked", "Button Click");
}
}
}
'Program > WPF' 카테고리의 다른 글
MS Access 파일을 WPF에서 사용하기 (0) | 2009.11.06 |
---|---|
WPF 동영상 (0) | 2009.09.16 |
DependencyProperty 클래스 (0) | 2009.08.28 |
GridSplitter 로 열 크기 조정 (0) | 2009.08.21 |
GridSplitter 로 행 크기 조정 (0) | 2009.08.21 |