C# WPF Win7 标题栏添加按钮(模拟)
来源:互联网 发布:淘宝开放平台的api 编辑:程序博客网 时间:2024/06/02 04:12
研究了一天,终于成功在Win7标题栏上加了按钮。
(使用AreoGlass模拟的标题栏)
废话不多说,代码:
[StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; }; [DllImport("DwmApi.dll")] public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset);private void Window_Loaded(object sender, RoutedEventArgs e) { Background = Brushes.Transparent; try { IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; MARGINS margins = new MARGINS(); margins.cxLeftWidth = -1; margins.cxRightWidth = -1; margins.cyTopHeight = -1; margins.cyBottomHeight = -1; int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); if (hr < 0) { //未启用AreoGlass //在此可以参见[C#标题栏添加按钮],网上例子很多。 } } catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; //未启用AreoGlass,同上。 } }
XMAL:
<Window x:Class="UsersApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainForm" Height="400" Width="500" Loaded="Window_Loaded" Icon="/UsersApp;component/Images/Error.ico" WindowStartupLocation="CenterScreen" WindowStyle="None" MaxWidth="500" MaxHeight="400" MinHeight="400" MinWidth="500"> <Grid Height="378"> <Label Content="主窗体" Height="28" HorizontalAlignment="Left" Name="label1" VerticalAlignment="Top" Margin="-3,-6,0,0" /> <Button Content="" Height="19" HorizontalAlignment="Left" Margin="50,0,0,0" Name="button1" VerticalAlignment="Top" Width="39" /> </Grid></Window>
然后在MainForm上加个Frame之类的控件,模拟用户区。
最后,因为是无边框窗体,所以必须自己写窗体拖动。
这个网上也有很多,自己搜吧。
0 0
- C# WPF Win7 标题栏添加按钮(模拟)
- C#实现在窗体标题栏加入按钮(好像不支持WIN7)
- WPF模拟点击按钮
- Activity标题栏添加返回按钮
- C# wpf 下拉按钮
- C# WPF 按钮模板
- WPF 为按钮添加Tooltip
- 【WPF】Button按钮添加背景图片
- Activity标题栏添加图片或按钮
- Android标题栏最右边添加按钮
- Android在顶部标题栏添加按钮
- android标题栏中添加返回按钮
- android标题栏中添加返回按钮
- android标题栏中添加返回按钮
- C# 按钮添加事件
- WPF动态添加按钮并相应事件。
- WPF动态添加按钮并相应事件。
- C# WPF 动态添加窗体
- gdb调试多线程
- 基于邻接表的图建立(有向图+无向图)
- xcode的使用技巧索引
- 不配置环境变量运行tomcat
- MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
- C# WPF Win7 标题栏添加按钮(模拟)
- UITextField基础语法
- Mac os x下,使用pip安装scrapy
- hdu 5201 The Monkey King
- Spring IOC自动扫描
- Go语言文档
- 【Java GUI】Java GUI基础
- javaScript中私有属性和方法
- Android.mk文件语法规范及使用模板