WPF C# 实现鼠标穿透窗体

2026年09月08日 20:04
有4个网友回答
网友(1):

如果要作成透明的话,窗体本身很难获得Mouse事件,直接点到后面的东西去了,我做了个例子
Window.xmal代码:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Right Click To Close" Height="300" Width="300"
WindowStyle="None" AllowsTransparency="True" MouseRightButtonUp="WindowClicked"
Background="{x:Null}"
>

FontSize="18" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20"
MouseLeftButtonDown="DragWindow" FontFamily="Impact" Foreground="Red"/>


Data="M79,3L65,82 17,91 50,138 96,157 104,192 175,154 190,167 218,78 156,76 157,9 111,39z"/>




Window.xmal.cs 代码:
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 Test
{
public partial class Class1 : System.Windows.Window
{

public Class1()
{
InitializeComponent();
}

public void DragWindow(object sender, MouseButtonEventArgs args)
{
DragMove();
}

public void WindowClicked(object sender, MouseButtonEventArgs args)
{
Close();
}
}
}

网友(2):

form的试过,wpf的还没玩过

网友(3):

FORM的简单 WPF是这东东还没用过

网友(4):

穿透?还是不显示鼠标的光标?