본문 바로가기
.NET C#

모니터 해상도(Tip)

by 태디 2008. 9. 15.
728x90

WPF에서 모니터의 실제 해상도를 가져오는 간단한 프로그램입니다.

사용자 삽입 이미지

xaml code

<Window x:Class="WPFScreen.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="165" Width="300">
    <Grid>
        <Label HorizontalAlignment="Left" Margin="23,30,0,0" VerticalAlignment="Top"
               Width="55" Height="23" Content="Width :"/>
        <Label HorizontalAlignment="Left" Margin="23,0,0,38" VerticalAlignment="Bottom"
               Width="55" Height="23" Content="Height : "/>
        <TextBlock Margin="78,35,137,0" TextWrapping="Wrap" x:Name="txWidth"
                   VerticalAlignment="Top" Height="23" />
        <TextBlock Margin="82,0,133,33" TextWrapping="Wrap" VerticalAlignment="Bottom"
                   Height="23" x:Name="txHeigh" />
    </Grid>
</Window>
 

cs code

using System.Windows;
 
namespace WPFScreen
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
 
            this.Loaded += new RoutedEventHandler(Window1_Loaded);
        }
 
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            txWidth.Text = SystemParameters.PrimaryScreenWidth.ToString();
            txHeigh.Text = SystemParameters.PrimaryScreenHeight.ToString();
        }
    }
}

댓글