2011-12-30 80 views
1

我在Microsoft Expression Blend WPF中創建了一個窗體。表單字段在格式化的矩形上。我所做的就是隱藏原來的窗口。現在,除了運行應用程序時,我無法使用鼠標移動窗體,所有東西看起來都很完美。有什麼可以解決這個問題?製作可通過鼠標移動的形狀窗口

下面是截圖。

enter image description here

回答

1

爲了達到這種效果,請嘗試以下。

在窗口元素:

  1. 將WindowStyle屬性設置爲無。
  2. 將背景設置爲空。
  3. 將AllowsTransparency設置爲True。

將您的內容分組到一個Border元素中。對於這類工作,邊界比矩形要好得多。在邊框上設置這些屬性:

  1. 具有5-10%Alpha通道的所需顏色背景。
  2. BorderBrush爲所需的顏色。 (你可能也可能不希望設置這個Alpha通道)
  3. BorderThickness到所需的厚度。

運行該應用程序,你將大致處於你的OP狀態。現在,添加窗口拖動,捕獲窗口上的MouseDown事件,並且只需調用DragMove()。

下面是一個簡單WPF應用程序,你應該能夠運行:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
    x:Class="ShapedWindow.MainWindow" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" 
    Height="480" 
    WindowStyle="None" 
    Background="{x:Null}" 
    AllowsTransparency="True" 
    MouseDown="Window_MouseDown"> 
<Border x:Name="LayoutRoot" 
     BorderBrush="Black" 
     CornerRadius="50" 
     BorderThickness="2,2,3,3" 
     Background="#18EF3B3B"> 
    <Grid> 
     <Button x:Name="CloseButton" 
       Content="Close" 
       HorizontalAlignment="Right" 
       VerticalAlignment="Top" 
       Width="75" 
       Margin="0,19,26,0" 
       Click="CloseButton_Click" /> 
    </Grid> 
</Border> 

而後面的代碼:

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Shapes; 

namespace ShapedWindow 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      this.InitializeComponent(); 

      // Insert code required on object creation below this point. 
     } 

     private void CloseButton_Click(object sender, RoutedEventArgs e) 
     { 
      this.Close(); 
     } 

     private void Window_MouseDown(object sender, MouseButtonEventArgs e) 
     { 
      DragMove(); 
     } 
    } 
} 
相關問題