2017-02-22 88 views
0

enter image description hereC#WPF移動窗口別處

enter image description here

我很想移動應用程序。 由於光學原因,我刪除了框架,現在我無法移動應用程序,就好像我有框架一樣。 在圖片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> 
+0

請參閱:http://stackoverflow.com/a/20623867/1136211 – Clemens

回答

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被複制與MyWindowMainWindow取代。非常感謝用戶Phaeze。

+0

請參閱幫助中心內的[如何引用他人撰寫的材料](http://stackoverflow.com/help/referencing)。 – Clemens

+0

@Clemens好的,讓我檢查一下 – Ragavan