1. Reference


https://stackoverflow.com/questions/4019831/how-do-you-center-your-main-window-in-wpf

https://stackoverflow.com/questions/1545258/changing-the-start-up-location-of-a-wpf-window



2. SourceCode


A. Move to Center


private void CenterWindowOnScreen()

{

    double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;

    double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;

    double windowWidth = this.Width;

    double windowHeight = this.Height;

    this.Left = (screenWidth / 2) - (windowWidth / 2);

    this.Top = (screenHeight / 2) - (windowHeight / 2);

}


B. Set position


<Window x:Class="WpfApplication1.Window1" 

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

    Title="Window1" 

    Height="500" Width="500"

    WindowStartupLocation="Manual" 

    Left="0" Top="0">

</Window>

반응형

'Programming > C#' 카테고리의 다른 글

[LINQ] LINQ 중복 제거  (0) 2018.07.03
[WPF] Grid 칸 합치기  (0) 2018.06.12
[WPF] 아이콘 변경  (0) 2018.06.07
[WPF] 그리드 헤더 짤림 현상  (0) 2018.06.07
[C#] 문자열 검증. (null값, 공백확인)  (0) 2017.09.22

+ Recent posts