大学生做网站赚钱流程,wordpress主题调用编辑器,查企业的网站有哪些,淘宝网页版手机登录创建 WPF 不规则窗口 本文为khler原作#xff0c;转载必须确保本文完整并完整保留原作者信息及本文原始链接 E-mail: khler163.com QQ: 23381103 MSN: pragmachotmail.com 相对于用MFC创建不规则窗口#xff0c;WPF创建不规则窗体的过程就显得相当享受了 本文为khler原作转载必须确保本文完整并完整保留原作者信息及本文原始链接 E-mail: khler163.com QQ: 23381103 MSN: pragmachotmail.com 相对于用MFC创建不规则窗口WPF创建不规则窗体的过程就显得相当享受了原理清晰、实现简单。 下面图片就是演示程序运行效果 图1 镂空的灰太狼 我们的灰太狼先生漂浮在了我的blog编辑器上面右上角放了一个可以关闭程序的按钮通过鼠标可以拖动灰太狼窗口。 基本分两步就可以轻松实现上面的不规则窗体效果 1、背景窗口设置 a、将窗口的 WindowStyle 设置成 None 这样就把 Title bar 去掉了 b、将窗口的 AllowsTransparency 设置成 True 允许透明化处理 c、将窗口的 Background 设置成 Transparent 就是把背景设置成透明色。 2、显示元素的添加 这就很简单了把你要显示的元素添加进去就行了。最常见的就是加一个不规则的图片作为背景然后在上面甚至“外面”添加其他元素所谓“外面”现实的效果就是悬浮在外部了。 下面是代码 Xaml文件 Window x:ClassNonRectangularWindow.Window1 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml Title不规则窗口演示 SizeToContentWidthAndHeight MouseLeftButtonDownWindow_MouseLeftButtonDown WindowStyleNoneAllowsTransparencyTrueBackgroundTransparent Grid Width550Height450 !--非矩形区域元素-- Image Source/NonRectangularWindow;component/灰太狼1.png/Image Button Width60Height40ClickbtnClose_ClickMargin465,23,25,387关闭/Button /Grid/Window 复制代码 后台C#代码 usingSystem;usingSystem.Windows;usingSystem.Windows.Input;namespaceNonRectangularWindow{ publicpartialclassWindow1 : Window { publicWindow1() { InitializeComponent(); } voidbtnClose_Click(objectsender, RoutedEventArgs e) { this.Close(); } privatevoidWindow_MouseLeftButtonDown(objectsender, MouseButtonEventArgs e) { this.DragMove(); } }} 复制代码 源代码 点击这里下载本示例程序的源码。 注本示例程序需要VS2010、.net framework3.0及以上才能运行。 由于镂空后有很多边刺和杂色加入OuterGlowBitmapEffect效果是个不错的选择按照一楼的提示修改后的结果如下 图2以深色桌面为背景的改进版 Xaml如下 Window x:ClassNonRectangularWindow.Window1 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml Title不规则窗口演示 SizeToContentWidthAndHeight MouseLeftButtonDownWindow_MouseLeftButtonDown WindowStyleNoneAllowsTransparencyTrueBackgroundTransparent Grid Width550Height450 !--非矩形区域元素-- Image Source/NonRectangularWindow;component/灰太狼1.png Image.BitmapEffect OuterGlowBitmapEffect GlowColorWhiteGlowSize3/ /Image.BitmapEffect /Image Button Width60Height40ClickbtnClose_ClickMargin465,23,25,387关闭/Button TextBlock Height23HorizontalAlignmentLeftMargin395,151,0,0NametextBlock1TextHE YuanHuiVerticalAlignmentTop TextBlock.BitmapEffect OuterGlowBitmapEffect/ /TextBlock.BitmapEffect /TextBlock TextBlock Height23HorizontalAlignmentLeftMargin413,180,0,0NametextBlock2Text2010年4月29日VerticalAlignmentTopTextBlock.BitmapEffect OuterGlowBitmapEffect/ /TextBlock.BitmapEffect /TextBlock TextBlock Height23HorizontalAlignmentLeftMargin413,209,0,0NametextBlock3TextAll rights reserved.VerticalAlignmentTopTextBlock.BitmapEffectOuterGlowBitmapEffect //TextBlock.BitmapEffect/TextBlock /Grid/Window 复制代码 添加了VS2008的解决方案文件现在VS2008应该也能打开了不过注意我的VS2008是打了SP1的如果你还打不开建议把VS2008SP1装上不过装2008SP1还不如装个VS2010因为WPF在VS2010里面有相当大的提高编辑器已经非常好用了。 请在这里下载VS2008/VS2010版源代码。 posted on 2011-12-13 15:33 碧空雪狐 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/yanpo/archive/2011/12/13/2286187.html