概要
AeroSnap をどうしても消したかったの!😣
ちょっといじくったら Windows Forms でも使えそう?
こんな感じ (適当に変えてね)
MainWindow.xaml
<Window x:Class="WpfApp2.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:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
WindowStyle="None">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="0"/>
</WindowChrome.WindowChrome>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="45"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button x:Name="CloseButton" Background="Transparent" Content=""
FontFamily="Segoe MDL2 Assets" FontSize="8.5"
BorderThickness="0" RenderOptions.EdgeMode="Aliased"
Grid.Column = "1"/>
<Grid Grid.Row="1" Grid.ColumnSpan="2"/>
<Canvas x:Name="DragHandle" Background="Transparent"/>
</Grid>
</Window>
MainWindow.xaml.cs
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Runtime.InteropServices;
namespace WpfApp2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
int GWL_STYLE = -16;
int WS_OVERLAPPEDWINDOW = 0;
int WS_THICKFRAME = 0x00040000;
[DllImport("user32")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwLong);
public MainWindow()
{
InitializeComponent();
this.CloseButton.Click
+= CloseButton_Click; //ウィンドウ閉じるボタン
this.DragHandle.PreviewMouseLeftButtonDown
+= DragHandle_PreviewMouseLeftButtonDown; //ドラッグ移動
this.Loaded += MainWindow_Loaded; //ウィンドウがロードされたら
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
=> SetWindowLong(
new WindowInteropHelper(this).Handle,
GWL_STYLE,
WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME);
private void CloseButton_Click(object sender, RoutedEventArgs e)
=> this.Close();
private void DragHandle_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
=> this.DragMove();
}
}
試せ
MainWindow.xaml.cs
this.Loaded += MainWindow_Loaded; //ウィンドウがロードされたら
(多分)32行目の、上のやつコメントアウトしたりしなかったりして違いを確かめよう!
ウィンドウをドラッグで移動させてマウスカーソルが画面端でごっつんこしなかったら成功!
(コピペしてもうまく動かなかったらごめんなさい僕は動いたんです😥)