Skip to content

Commit

Permalink
add showing current screen num and primary screen num
Browse files Browse the repository at this point in the history
  • Loading branch information
lsylusiyao committed Jun 23, 2020
1 parent 727597e commit 3d8519d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 18 deletions.
10 changes: 7 additions & 3 deletions ScreenRotateForWin10/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ScreenRotateForWin10"
mc:Ignorable="d"
Title="屏幕转向控制程序" Height="410" Width="360" ResizeMode="CanMinimize">
Title="屏幕转向控制程序" Height="410" Width="360" ResizeMode="CanMinimize" LocationChanged="Window_LocationChanged">
<!--Title="ScreenRotate"-->
<Grid Margin="0,0,-0.4,0">
<StackPanel Orientation="Vertical">
Expand All @@ -14,7 +14,7 @@
<!--Content="Screen to Rotate"-->
<ComboBox x:Name="choiceComboBox" Width="100" FontSize="16" ItemsSource="{Binding ScreenNums}"/>
</StackPanel>
<UniformGrid Rows="3" Columns="3" Margin="0,35,0,0" Height="220">
<UniformGrid Rows="3" Columns="3" Margin="0,30,0,0" Height="220">
<Label/>
<Button Content="旋转180度" Width="90" Height="60" FontSize="16" Click="Button_Click_2"/>
<!--Content="rotate for 180 deg"-->
Expand All @@ -30,7 +30,11 @@
<!--Content="horizon"-->
</UniformGrid>
</StackPanel>
<Button x:Name="defaultButton" Content="所有恢复默认" Width="120" VerticalAlignment="Bottom" Margin="0,0,0,30" Height="30" FontSize="14" Click="DefaultButton_Click"/>
<Button x:Name="defaultButton" Content="所有恢复默认" Width="120" VerticalAlignment="Bottom" Margin="0,0,0,42" Height="30" FontSize="14" Click="DefaultButton_Click"/>
<!--Content="All reset to default"-->
<Grid VerticalAlignment="Bottom">
<Label x:Name="currScreenLabel" Content="当前:?号屏幕" FontSize="16" HorizontalAlignment="Left"/> <!--Context="Curr: NO.? Screen"-->
<Label x:Name="primaryScreenLabel" Content="主屏幕:?号屏幕" FontSize="16" HorizontalAlignment="Right"/> <!--Context="Primary Screen: NO.? Screen"-->
</Grid>
</Grid>
</Window>
25 changes: 22 additions & 3 deletions ScreenRotateForWin10/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;

namespace ScreenRotateForWin10
{
Expand All @@ -19,19 +21,29 @@ public MainWindow()

private List<string> screenList = new List<string>();
private int screenCount = 0;
private int currScreenID = 0;
private int primaryScreenID = 0;
private readonly List<Screen> allScreens = Screen.AllScreens.ToList();

private void Init()
{
var result = new List<string>();
screenCount = Screen.AllScreens.Count();

screenCount = allScreens.Count;
result.AddRange(
Enumerable.Range(0, screenCount)
.Select(x => $"{x + 1}号屏幕") // $"NO.{x} Screen"
.Select(x => $"{x + 1}号屏幕") // $"NO.{x + 1} Screen"
);
result.Add("所有"); // All

primaryScreenID = allScreens.IndexOf(Screen.PrimaryScreen) + 1;
primaryScreenLabel.Content = $"主屏幕:{primaryScreenID}号屏幕"; // "Primary Screen: NO.? Screen"

screenList = result;
choiceComboBox.ItemsSource = screenList;
choiceComboBox.SelectedIndex = result.Count - 1; // Last

Window_LocationChanged(null, null); // currScreen label changed
}

private void RotateChoice(int choice, Display.Orientations degree)
Expand Down Expand Up @@ -73,5 +85,12 @@ private void Button_Click_4(object sender, RoutedEventArgs e)
{
RotateChoice(choiceComboBox.SelectedIndex, Display.Orientations.DEGREES_CW_0);
}

private void Window_LocationChanged(object sender, EventArgs e)
{
var currScreen = Screen.FromHandle(new WindowInteropHelper(this).Handle);
currScreenID = allScreens.IndexOf(currScreen) + 1;
currScreenLabel.Content = $"当前:{currScreenID}号屏幕"; // "Curr: NO.? Screen"
}
}
}
47 changes: 47 additions & 0 deletions ScreenRotateForWin10/ScreenRotateForWin10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>false</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<SupportUrl>https://github.com/lsylusiyao/ScreenRotateForWin10</SupportUrl>
<ProductName>ScreenRotateForWin10</ProductName>
<PublisherName>lsylusiyao</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.1.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -40,6 +59,21 @@
<PropertyGroup>
<ApplicationIcon>program_icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>CD11585E956AD426401BFC276EE44D4C1E733CD9</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>ScreenRotateForWin10_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -100,12 +134,25 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="ScreenRotateForWin10_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="program_icon.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 6 additions & 12 deletions ScreenRotateForWin10/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand All @@ -17,33 +17,29 @@
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

</application>
</compatibility>

<!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
Expand All @@ -54,7 +50,6 @@
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
</windowsSettings>
</application>

<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
Expand All @@ -70,5 +65,4 @@
</dependentAssembly>
</dependency>
-->

</assembly>
</assembly>

0 comments on commit 3d8519d

Please sign in to comment.