0

すべての側面からサイズを変更できるようにしたい、ボーダーレスの透明な wpf ウィンドウ (WindowStyle=None) があります。現在、ResizeMode=CanResizeWithGrip を設定した場合、サイズ変更は上記の設定でのみ機能します。これは視覚的な合図としては良いのですが、1 つの隅からしかサイズ変更できないため、あまり良くありません。

これを adorner で行いたいので、ウィンドウがサイズ変更モード (オンとオフを切り替えることができます) のときに視覚的な合図を与えることもできます。これは可能ですか?もしそうなら、どうすればいいですか?

4

1 に答える 1

1

この質問は、stackoverflow のどこかですでに回答されています。今はよくわかりませんが、私がやった方法は次のとおりです。

メインウィンドウ:

<Window x:Class="Solution.Views.Main.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" MinWidth="1000" MinHeight="500" WindowStyle="None" AllowsTransparency="False" BorderThickness="0" ResizeMode="NoResize">

   <Window.TaskbarItemInfo>
     <TaskbarItemInfo />
   </Window.TaskbarItemInfo>

  <Grid>

    <Border MouseLeftButtonDown="WindowResizeEast" MouseEnter="BorderVertical_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" VerticalAlignment="Stretch" HorizontalAlignment="Right" Width="1" Background="Black"/>
    <Border MouseLeftButtonDown="WindowResizeWest" MouseEnter="BorderVertical_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave"  VerticalAlignment="Stretch" HorizontalAlignment="Left" Width="1" Background="Black"/>
    <Border MouseLeftButtonDown="WindowResizeNorth" MouseEnter="BorderHorizontal_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave"  VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="1" Background="Black"/>
    <Border MouseLeftButtonDown="WindowResizeSouth" MouseEnter="BorderHorizontal_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave"  VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="1" Background="Black"/>
    <Border VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="20" Height="20" MouseEnter="BorderSouthEast_OnMouseEnter" MouseLeave="BorderAll_OnMouseLeave" MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown">
        <Grid>
            <Path Stroke="Gray" StrokeThickness="1" Data=" M 5 20 L 20 5 M 10 20 L 20 10 M 15 20 L 20 15"/>
        </Grid>
    </Border>
  </Grid>
</Window>

メインウィンドウ コード:

using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using PrmWpf.Services;

 public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);

    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    private void WindowResizeNorth(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Top, IntPtr.Zero);
    }

    private void WindowResizeSouth(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Bottom, IntPtr.Zero);
    }

    private void WindowResizeWest(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Left, IntPtr.Zero);
    }

    private void WindowResizeEast(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
    {
        var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.Right, IntPtr.Zero);
    }

    private enum ResizeDirection { Left = 61441, Right = 61442, Top = 61443, Bottom = 61446, BottomRight = 61448, }

    private void BorderVertical_OnMouseEnter(object sender, MouseEventArgs e)
    {
        Mouse.OverrideCursor = Cursors.SizeWE;
    }

    private void BorderHorizontal_OnMouseEnter(object sender, MouseEventArgs e)
    {
        Mouse.OverrideCursor = Cursors.SizeNS;
    }

    private void BorderAll_OnMouseLeave(object sender, MouseEventArgs e)
    {
        Mouse.OverrideCursor = Cursors.Arrow;
    }

    private void BorderSouthEast_OnMouseEnter(object sender, MouseEventArgs e)
    {
        Mouse.OverrideCursor = Cursors.SizeNWSE;
    }

    private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        SendMessage(hwndSource.Handle, 0x112, (IntPtr)ResizeDirection.BottomRight, IntPtr.Zero);
    }
}
于 2016-11-29T09:13:38.290 に答える