我想在屏幕左下角的任何PC上打开我的c#应用程序(屏幕的左侧或右侧)。为此,我该怎么办?我这样做了;
<Window x:Class="BPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPF"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}" />
</StackPanel>
</Window>
我可以设置Height
和Width
参数,但PC屏幕不同。我希望在任何PC上,应用程序应以全宽(等于PC /笔记本电脑屏幕)打开,宽度为400。
我想在笔记本电脑/电脑屏幕的右侧启动应用程序(在每台笔记本电脑/ PC上),应用程序的右侧应与笔记本电脑屏幕的右侧相连。
答案 0 :(得分:0)
您需要添加此wpf应用代码的代码。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
var workingArea = System.Windows.SystemParameters.WorkArea;
this.Left = 0;
this.Top = workingArea.Bottom - this.Height;
}
添加xaml代码。您必须更改此属性“宽度=”400“”
<Window x:Class="BPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPF"
Title="MainWindow" Height="350" Width="400">
<StackPanel>
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}}" />
<TextBlock Text="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}" />
</StackPanel>
如果你想设置正确的
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
var workingArea = System.Windows.SystemParameters.WorkArea;
this.Left = workingArea.Right - this.Width;
this.Top = workingArea.Bottom - this.Height;
}
我修复了这段代码,并为set right添加了代码。
答案 1 :(得分:0)
如果我理解您的要求,您可以将Height
属性设置为SystemParameters.PrimaryScreenHeight
,将Left
属性设置为0
:
<Window x:Class="BPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPF"
Title="MainWindow" Left="0" Height="{x:Static SystemParameters.PrimaryScreenHeight}" Width="400">
<StackPanel>
</StackPanel>
</Window>