티스토리 뷰
반응형
.NET Core WPF 프로젝트를 개발하다가, 현재 윈도우의 WorkingArea 정보를 확인 해야할 필요가 있어서 찾아보니 System.Windows.Forms.Screen을 이용해야 한다네요.
.Net Framework 프로젝트에서는 Add Reference를 이용해서 System.Windows.Forms를 추가하면 되었는데, .NET Core에서는 추가 할 수가 없어서.. 다시 검색을 하니 아래와 같은 방법을 이용하면 된다고 합니다.
프로젝트 파일에 UseWindowsForms를 true로 지정하면 끝~
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
그래서 간단한 예제를 만들어 보았습니다.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var rect = GetWindowRectangle();
Result.Text = $"X:{rect.X} Y:{rect.Y} Width:{rect.Width} Height:{rect.Height} Right:{rect.Right} Bottom:{rect.Bottom}";
}
System.Drawing.Rectangle GetWindowRectangle()
{
System.Drawing.Rectangle windowRectangle = System.Windows.Forms.Screen.GetWorkingArea(
new System.Drawing.Point((int)Left, (int)Top));
return windowRectangle;
}
}
결과는 이렇게 나옵니다.
소스(CoreWpf)
kaki104/WpfTest
Contribute to kaki104/WpfTest development by creating an account on GitHub.
github.com
반응형
'WPF .NET' 카테고리의 다른 글
Button Left Click시 ContextMenu 열기 (0) | 2021.03.10 |
---|---|
Visual Studio를 이용한 Memory Leak 확인 방법 (3) | 2021.03.08 |
.NET Core WPF 프로젝트에서 System.Windows.Forms 사용 (0) | 2021.03.07 |
Telerik - DockingRegionAdapter (0) | 2021.02.24 |
Infragistics - Differences Between xamGrid and xamDataGrid (0) | 2021.02.16 |
Infragistics - About XamDataGrid (0) | 2021.02.15 |
- TAG
- getworkingarea, winforms, WPF
댓글
반응형
공지사항
- Total
- 689,199
- Today
- 245
- Yesterday
- 434
링크
TAG
- Behavior
- visual studio 2019
- uno platform
- #Windows Template Studio
- WPF
- infragistics
- .net 5.0
- #XAML
- Windows 10
- XAML
- #uwp
- #MVVM
- ComboBox
- #prism
- PRISM
- dotNETconf
- Xamarin
- C#
- ef core
- MVVM
- Bot Framework
- IOT
- uno-platform
- UWP
- Build 2016
- LINQ
- .net
- windows 11
- Microsoft
- Cross-platform