【问题标题】:C# WPF move window elsewhereC# WPF 将窗口移动到别处
【发布时间】:2017-07-12 05:33:38
【问题描述】:

我很想移动应用程序。 由于光学原因,我移除了框架,现在我无法像有框架一样移动应用程序。 在图 2 中,您可以看到这个框架,只要走到这个框架并且手持的 Maustaste 就可以移动应用程序。 我也想对我的应用程序执行此操作,请参见图 1。 我怎样才能做到这一点? 如果我可以再次移动我的应用程序? 例如,如果我按下白色画布以便移动它。

<Window x:Name="windowsForm" x:Class="Vorschau.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:Vorschau"
        mc:Ignorable="d"
        Title="MainWindow" Height="514.583" Width="805.208" FontFamily="Century Gothic" WindowStartupLocation="CenterScreen" BorderThickness="0" ResizeMode="NoResize" WindowStyle="None" Icon="C:\Users\benutzer\Documents\Visual Studio 2015\Projects\Vorschau\Vorschau\img\coordinates.ico">
    <Canvas HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="185" Background="#FFE57E31">
        <Canvas Height="96" Canvas.Top="419" Width="185" Background="#FF2C373F">
            <Label x:Name="lbCopyright" Content="©  Name 2017" Canvas.Left="10" Canvas.Top="61" Width="121" Foreground="#FF1B1D1F"/>
        </Canvas>
        <Canvas Height="359" Canvas.Top="60" Width="185" Background="#FF37424A"/>
        <Canvas Height="60" Canvas.Left="185" Width="610">
            <Label x:Name="lbClose" Content="X" Canvas.Left="578" FontSize="20"/>
            <Label x:Name="lbMinimize" Content="-" Canvas.Left="556" FontSize="22" Canvas.Top="-2"/>
        </Canvas>
        <Canvas Height="455" Canvas.Left="185" Canvas.Top="60" Width="618" Background="#FFD1CFD0"/>
        <Image x:Name="image" Height="38" Canvas.Left="10" Canvas.Top="10" Width="38" Source="C:\Users\benutzer\Documents\Visual Studio 2015\Projects\Vorschau\Vorschau\img\coordinates64.png"/>
        <Label x:Name="lbLogoname" Content="Vorschaukomponente" Canvas.Left="37" Canvas.Top="10" Width="143" FontWeight="Bold" Foreground="White"/>
    </Canvas>
</Window>

【问题讨论】:

标签: c# wpf border frame


【解决方案1】:

添加以下代码以使您的窗口可移动。

public partial class MainWindow : Window
{
    public MainWindow ()
    {
        InitializeComponent();
        MouseDown += Window_MouseDown;
    }

    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ChangedButton == MouseButton.Left)
            DragMove();
    }
}

代码是从this answer 复制的,其中MyWindow 替换为MainWindow。非常感谢用户 Phaeze。

【讨论】:

猜你喜欢
  • 2013-05-12
  • 2018-04-28
  • 2010-09-24
  • 2016-02-27
  • 2011-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多