WPF可拖动浮动窗口(类似于手机浮动窗口工具)

上传者: Hat_man_ | 上传时间: 2026-01-16 21:34:36 | 文件大小: 87KB | 文件类型: ZIP
wpf
在本文中,我们将深入探讨如何在Windows Presentation Foundation (WPF) 中实现一个可拖动的浮动窗口,这个功能类似于在手机上使用的圆形浮动窗口工具。WPF是.NET框架中的一个强大的用户界面框架,用于构建丰富的桌面应用程序。 我们要创建一个WPF应用程序项目。在Visual Studio中,选择"新建项目",然后在模板列表中找到"WPF应用程序",并命名为"WpfApp1"。创建项目后,Visual Studio会自动为你生成一个默认的MainWindow.xaml及其对应的MainWindow.xaml.cs文件。 接下来,我们需要设计我们的浮动窗口。在MainWindow.xaml中,我们可以自定义窗口的外观,让它看起来像手机上的圆形浮动窗口。这可以通过设置窗口的`Width`、`Height`和`Background`属性来完成,同时可以使用`CornerRadius`属性使窗口呈圆形。例如: ```xml ``` 为了让窗口可拖动,我们需要在代码-behind中添加事件处理程序。在MainWindow.xaml.cs中,我们首先将窗口的`MouseLeftButtonDown`事件与`MouseMove`和`MouseLeftButtonUp`事件关联起来: ```csharp private void MainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void MainWindow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { // 可能需要添加释放时的逻辑 } ``` `DragMove()`方法是WPF提供的内置函数,它允许用户通过鼠标移动窗口。 为了实现类似手机浮动窗口的交互,我们可以添加键盘控制。这可以通过创建一个新的UserControl,如`KeyBoardControl.xaml`,并在其中定义按键行为。例如,可以添加按钮来模拟方向键移动窗口: ```xml

文件下载

资源详情

[{"title":"( 69 个子文件 87KB ) WPF可拖动浮动窗口(类似于手机浮动窗口工具)","children":[{"title":"WpfApp1","children":[{"title":"App.config <span style='color:#111;'> 189B </span>","children":null,"spread":false},{"title":"MainWindow.xaml <span style='color:#111;'> 1.30KB </span>","children":null,"spread":false},{"title":"App.xaml <span style='color:#111;'> 368B </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"WpfApp1.exe <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false},{"title":"WpfApp1_MarkupCompile.cache <span style='color:#111;'> 215B </span>","children":null,"spread":false},{"title":"WpfApp1.pdb <span style='color:#111;'> 37.50KB </span>","children":null,"spread":false},{"title":"WpfApp1.g.resources <span style='color:#111;'> 1.84KB </span>","children":null,"spread":false},{"title":"WpfApp1.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.15KB </span>","children":null,"spread":false},{"title":"WpfApp1_MarkupCompile.i.lref <span style='color:#111;'> 56B </span>","children":null,"spread":false},{"title":"WpfApp1.csproj.AssemblyReference.cache <span style='color:#111;'> 7.98KB </span>","children":null,"spread":false},{"title":"WpfApp1.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"WpfApp1_MarkupCompile.i.cache <span style='color:#111;'> 214B </span>","children":null,"spread":false},{"title":"WpfApp1.csproj.CoreCompileInputs.cache <span style='color:#111;'> 42B </span>","children":null,"spread":false},{"title":"MainWindow.g.cs <span style='color:#111;'> 5.19KB </span>","children":null,"spread":false},{"title":"WpfApp1_MarkupCompile.lref <span style='color:#111;'> 56B </span>","children":null,"spread":false},{"title":"WpfApp1.csproj.CopyComplete <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 7.11KB </span>","children":null,"spread":false},{"title":"MainWindow.baml <span style='color:#111;'> 1.61KB </span>","children":null,"spread":false},{"title":"TempPE","children":[{"title":"Properties.Resources.Designer.cs.dll <span style='color:#111;'> 4.00KB </span>","children":null,"spread":false}],"spread":false},{"title":"WpfApp1.csproj.GenerateResource.cache <span style='color:#111;'> 84B </span>","children":null,"spread":false},{"title":"WpfApp1.csproj.SuggestedBindingRedirects.cache <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"MainWindow.g.i.cs <span style='color:#111;'> 5.19KB </span>","children":null,"spread":false},{"title":"_IsIncrementalBuild <span style='color:#111;'> 32B </span>","children":null,"spread":false},{"title":".NETFramework,Version=v4.7.2.AssemblyAttributes.cs <span style='color:#111;'> 214B </span>","children":null,"spread":false},{"title":"App.g.i.cs <span style='color:#111;'> 2.29KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferences.cache <span style='color:#111;'> 205B </span>","children":null,"spread":false},{"title":"App.g.cs <span style='color:#111;'> 2.29KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"MainWindow.xaml.cs <span style='color:#111;'> 1.34KB </span>","children":null,"spread":false},{"title":"bin","children":[{"title":"Debug","children":[{"title":"WpfApp1.exe.config <span style='color:#111;'> 189B </span>","children":null,"spread":false},{"title":"WpfApp1.exe <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false},{"title":"WpfApp1.pdb <span style='color:#111;'> 37.50KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.pdb <span style='color:#111;'> 31.50KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.dll <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Properties","children":[{"title":"Resources.Designer.cs <span style='color:#111;'> 2.78KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.07KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 201B </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 2.25KB </span>","children":null,"spread":false},{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false}],"spread":true},{"title":"App.xaml.cs <span style='color:#111;'> 334B </span>","children":null,"spread":false},{"title":"WpfApp1.csproj <span style='color:#111;'> 4.34KB </span>","children":null,"spread":false}],"spread":true},{"title":"KeyBoardControl","children":[{"title":"UserControl1.xaml.cs <span style='color:#111;'> 1.91KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.csproj <span style='color:#111;'> 3.67KB </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"UserControl1.g.i.cs <span style='color:#111;'> 4.60KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.csproj.FileListAbsolute.txt <span style='color:#111;'> 1000B </span>","children":null,"spread":false},{"title":"KeyBoardControl.g.resources <span style='color:#111;'> 2.07KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.csproj.AssemblyReference.cache <span style='color:#111;'> 7.18KB </span>","children":null,"spread":false},{"title":"KeyBoardControl_MarkupCompile.lref <span style='color:#111;'> 66B </span>","children":null,"spread":false},{"title":"KeyBoardControl.csproj.GenerateResource.cache <span style='color:#111;'> 84B </span>","children":null,"spread":false},{"title":"KeyBoardControl.csproj.CoreCompileInputs.cache <span style='color:#111;'> 42B </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 7.02KB </span>","children":null,"spread":false},{"title":"UserControl1.baml <span style='color:#111;'> 1.85KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.pdb <span style='color:#111;'> 31.50KB </span>","children":null,"spread":false},{"title":"TempPE","children":null,"spread":false},{"title":"KeyBoardControl.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"UserControl1.g.cs <span style='color:#111;'> 4.60KB </span>","children":null,"spread":false},{"title":"_IsIncrementalBuild <span style='color:#111;'> 32B </span>","children":null,"spread":false},{"title":"KeyBoardControl_MarkupCompile.cache <span style='color:#111;'> 208B </span>","children":null,"spread":false},{"title":"KeyBoardControl_MarkupCompile.i.lref <span style='color:#111;'> 66B </span>","children":null,"spread":false},{"title":".NETFramework,Version=v4.7.2.AssemblyAttributes.cs <span style='color:#111;'> 214B </span>","children":null,"spread":false},{"title":"KeyBoardControl_MarkupCompile.i.cache <span style='color:#111;'> 205B </span>","children":null,"spread":false},{"title":"KeyBoardControl.dll <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"bin","children":[{"title":"Debug","children":[{"title":"KeyBoardControl.pdb <span style='color:#111;'> 31.50KB </span>","children":null,"spread":false},{"title":"KeyBoardControl.dll <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Properties","children":[{"title":"Resources.Designer.cs <span style='color:#111;'> 2.76KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.10KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 201B </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 2.23KB </span>","children":null,"spread":false},{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false}],"spread":true},{"title":"UserControl1.xaml <span style='color:#111;'> 1.72KB </span>","children":null,"spread":false}],"spread":true},{"title":"WpfApp1.sln <span style='color:#111;'> 1.59KB </span>","children":null,"spread":false}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明