728x90
Border Control은 닷넷 프레임워크 3.0이 추가되면서 새로 등장한 Control입니다. 어떠한 영역이나 경계를 지정할때 사용하는 Control입니다. 이번강좌에서는 Border를 지정하고 Button을 클릭하면 Border의 배경색(BackGroundColor)이 변경되서 보여지는 간단한 예제입니다.
그림 1. Border 프로그램
<Window x:Class="wpf19.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="450" Width="600">
<Grid>
<Border Name="root" BorderThickness="2" BorderBrush="Black"
Background="LightGray" Width="350" Height="350">
<Canvas>
<Button Name="btn" Canvas.Top="40" Canvas.Left="40"
Background="LightSkyBlue" Height="35"
Click="ChangeBackground_Click"
Content="Click Me to change the Background Color" />
<TextBlock Canvas.Top="130" Canvas.Left="40" Name="Text1"
Text="Waiting for Click!"/>
</Canvas>
</Border>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="450" Width="600">
<Grid>
<Border Name="root" BorderThickness="2" BorderBrush="Black"
Background="LightGray" Width="350" Height="350">
<Canvas>
<Button Name="btn" Canvas.Top="40" Canvas.Left="40"
Background="LightSkyBlue" Height="35"
Click="ChangeBackground_Click"
Content="Click Me to change the Background Color" />
<TextBlock Canvas.Top="130" Canvas.Left="40" Name="Text1"
Text="Waiting for Click!"/>
</Canvas>
</Border>
</Grid>
</Window>
BorderThickness : Border 두께
BorderBrush : Border 색깔
Borderground : Border 배경색
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace wpf19
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
void ChangeBackground_Click(object sender, RoutedEventArgs e)
{
root.Background = Brushes.LightSteelBlue;
btn.Content = "Clicked";
Text1.Text = "The Blackground is now LightSteelBlue";
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace wpf19
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
void ChangeBackground_Click(object sender, RoutedEventArgs e)
{
root.Background = Brushes.LightSteelBlue;
btn.Content = "Clicked";
Text1.Text = "The Blackground is now LightSteelBlue";
}
}
}
ChangeBackground_Click 이벤트가 발생되면 Border의 색깔을 LightSteelBlue로 변경하고 Button의 이름은 “Clicked!“, 로 TextBox의 내용은 "The background is now LightSteelBlue“으로 각각 변경이 됩니다.
※ 테스트 환경
-----------------------------------------------------------------------------------------
운영체체 : Windows Vista Ultimate 32bit
개발툴 : Microsoft Visual C# Codename "Orcas"
-----------------------------------------------------------------------------------------
'.NET WPF' 카테고리의 다른 글
[Controls] 22. Element:Shape (Polyline/Polygon) (0) | 2007.01.31 |
---|---|
[Controls] 21. Element:Shape (Line:선) (0) | 2007.01.30 |
[Controls] 20. Element:Shape (Ellipse:원) (0) | 2007.01.28 |
[Controls] 16. Expender (0) | 2007.01.12 |
[Controls] 15. Treeview (0) | 2007.01.11 |
[Controls] 14. Slider Style DataBinding (0) | 2007.01.10 |
[Controls] 13. Menu (0) | 2006.12.22 |
댓글