首页 > 其他分享 >WPF AllowsTransparency DragMove

WPF AllowsTransparency DragMove

时间:2024-07-03 21:20:09浏览次数:1  
标签:IntPtr Windows System MainWindow using WPF DragMove AllowsTransparency

 

//xaml
<Window x:Class="WpfApp191.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:WpfApp191"
        mc:Ignorable="d" AllowsTransparency="True"
        WindowStyle="None" 
        Title="MainWindow" Height="450" Width="800">
    <Window.Background>
        <ImageBrush ImageSource="324.jpg"/>
    </Window.Background>
    <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
        <Rectangle RadiusX="30" RadiusY="30">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0,1">
                    <GradientStop Color="DarkBlue" Offset="0"/>
                    <GradientStop Color="#80000080" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <TextBlock TextAlignment="Center" VerticalAlignment="Top"
                       Margin="4" Text="My Window Title"
                       FontSize="16" Foreground="White" FontWeight="Bold"/>
        <Button Content="X" HorizontalAlignment="Right" Click="CloseClick"
                    FontWeight="Bold" VerticalAlignment="Top"
                    Margin="20,4" FontSize="16"/>
        <TextBlock Text="Welcome o the new Window"
                       Foreground="Yellow" FontSize="25"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"/>
    </Grid>
</Window>



//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

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

        private void CloseClick(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }
    }
}

 

 

 

 

 

 

 

 

 

 

 

 //
 // Summary:
 //     Allows a window to be dragged by a mouse with its left button down over an exposed
 //     area of the window's client area.
 //
 // Exceptions:
 //   T:System.InvalidOperationException:
 //     The left mouse button is not down.
 [SecurityCritical]
 public void DragMove()
 {
     VerifyApiSupported();
     SecurityHelper.DemandUIWindowPermission();
     VerifyContextAndObjectState();
     VerifyHwndCreateShowState();
     if (!IsSourceWindowNull && !IsCompositionTargetInvalid)
     {
         if (Mouse.LeftButton != MouseButtonState.Pressed)
         {
             throw new InvalidOperationException(SR.Get("DragMoveFail"));
         }

         if (WindowState == WindowState.Normal)
         {
             UnsafeNativeMethods.SendMessage(CriticalHandle, WindowMessage.WM_SYSCOMMAND, (IntPtr)61458, IntPtr.Zero);
             UnsafeNativeMethods.SendMessage(CriticalHandle, WindowMessage.WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
         }
     }
 }

 

标签:IntPtr,Windows,System,MainWindow,using,WPF,DragMove,AllowsTransparency
From: https://www.cnblogs.com/Fred1987/p/18282572

相关文章

  • WPF open image and print as pdf file
    //xaml<Windowx:Class="WpfApp189.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • WPF OpenFielDialog Filter InitialiaDirectory Title
    //xaml<Windowx:Class="WpfApp189.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • WPF Prism PubSubEvent(订阅)
    Prism提供了事件聚合器(EventAggregator)来实现事件的订阅和发布,允许模块之间进行松耦合的通信。主要作用:解耦合:通过事件订阅和发布,模块之间可以实现解耦合,避免直接依赖于彼此的实现细节。示例用法:定义事件类:publicclassMessageEvent:PubSubEvent<string>{}订......
  • WPF进度条中间写百分比数字
    我发现很多同学把思维固话了,通常我们需要实现的进度条是我在网上看到好多例子,但是都没有我的简单,他们不是重写ProcessBar就是使用模板,可以将TextBlock提取出来啊,灵活一点单独绑定然后一句代码Panel.ZIndex="1"就搞定了<StackPanel><ButtonContent="执行耗时......
  • DevExpress WPF中文教程:Grid - 如何显示摘要(设计时)?
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。无论是Office办公软件的衍伸产品,还是以数据为中心......
  • WPF Image scalertransform translatetransform mvvm,custom delegate command Comman
    //xaml<Windowx:Class="WpfApp187.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • wpf关于Resource,Style的定义与引用,滑动按钮
    当我们使用wpf框架去搭建自己的程序时,一般都会重写wpf原生的一些样式,以达到软件风格的统一于美化,以下介绍一下常见的几种添加Style的方式我们以一个滑动按钮为例1.对当前控件的样式进行更改<ToggleButton><ToggleButton.Style><StyleTarg......
  • WPF 分隔栏分割窗体简单测试
    XAML:<Windowx:Class="WpfApp3.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.micro......
  • WPF 中 StackPanel 控件的可视化 Visibility.Collapsed 控件元素会自动前移
    XAML:<Grid><Grid.RowDefinitions><RowDefinition/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><StackPanelGrid.Row="0"><TextBoxx:Name="txb_001&quo......
  • 开发界的良心评测文章,告诉你WPF 与 WinForms 对比:性能、开发难度、特点及操作系统支持
    引言WindowsPresentationFoundation(WPF)和WindowsForms(WinForms)是微软提供的两种用于构建Windows桌面应用程序的框架。尽管它们都有助于开发高效的桌面应用程序,但在性能、开发难度、特点和操作系统支持方面存在显著差异。本文将详细比较WPF和WinForms,以帮助开发者选择......