首页 热点资讯 义务教育 高等教育 出国留学 考研考公

WPF C# 实现鼠标穿透窗体

发布网友 发布时间:2022-04-22 06:04

我来回答

4个回答

热心网友 时间:2023-09-27 02:43

如果要作成透明的话,窗体本身很难获得Mouse事件,直接点到后面的东西去了,我做了个例子
Window.xmal代码:
<Window x:Class="Test.Class1"
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}"
>
<Grid MouseRightButtonDown="WindowClicked">
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Title}"
FontSize="18" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20"
MouseLeftButtonDown="DragWindow" FontFamily="Impact" Foreground="Red"/>

<Viewbox Stretch="Uniform" MouseLeftButtonDown="DragWindow">
<Path Fill="#80D0E0FF" Stroke="Red" StrokeThickness="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Data="M79,3L65,82 17,91 50,138 96,157 104,192 175,154 190,167 218,78 156,76 157,9 111,39z"/>
</Viewbox>
</Grid>
</Window>

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();
}
}
}

热心网友 时间:2023-09-27 02:43

form的试过,wpf的还没玩过

热心网友 时间:2023-09-27 02:44

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

热心网友 时间:2023-09-27 02:44

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

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com