2017年元旦已经到了,想做一个祝福语的窗口,就把上一篇画心的程序改了改,变成了如下界面。

说下改动的地方,首先窗口没有标题栏了。

MainWindow.xaml

  AllowsTransparency="True"
MouseDoubleClick="Window_MouseDoubleClick"
WindowStyle="None" Background="#00FFFFFF" Loaded="Window_Loaded" MouseMove="Window_MouseMove"
Title="MainWindow" Height="" Width=""

中间圆形按钮的样式

<Style TargetType="Button" x:Key="ButtonStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Ellipse Width="" Height="">
<Ellipse.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="" Color="blue"/>
<GradientStop Offset="" Color="LightBlue"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse Width="" Height="">
<Ellipse.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="" Color="White"/>
<GradientStop Offset="" Color="Transparent"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
<ContentControl VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"
FontSize="" FontWeight="Bold" Foreground="Red"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

虽然没有了标题栏,为了能够让窗口自由移动

      private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}

双击鼠标,关闭窗口

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
this.Close();
}

不再使用线程睡眠的方式来动态显示心的生成,这次采用计时器。

      private DispatcherTimer timer = new DispatcherTimer();//创建定时器对象  

        public MainWindow()
{
InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; this.bendediction.Content = "2017年\r\n元旦快乐";
timer.Tick += new EventHandler(timer_Tick); //添加事件,定时到事件
timer.Interval = TimeSpan.FromMilliseconds(100);//设置定时长
timer.Start();
} void timer_Tick(object sender, EventArgs e)
{
if (iTick < maxStep)
{
CreateHeartLine(iTick);
}
else
{
timer.Stop();
}
iTick++;
}

  本次心的生成算法,基本不变,只是把心的半径和位置调整了下。

        private void CreateHeartLine(int iTick)
{
centerPt = canvas_Shape.Width/ ;
radius = canvas_Shape.Width / ;
for (int i = ; i < iTick; i++)
{
System.Windows.Controls.Image img = new System.Windows.Controls.Image(); img.Source = new BitmapImage(new Uri(@"image/" + + ".png", UriKind.Relative));//给出照片路径
img.Height = ;
img.Width = ;
img.Stretch = Stretch.Fill; double angle = * Math.PI / maxStep * i; //桃形心
double x = centerPt - * (Math.Sin(angle) * Math.Sin(angle) * Math.Sin(angle)) * ;//
double y = centerPt - ( * Math.Cos(angle) - * Math.Cos( * angle) - * Math.Cos( * angle) - Math.Cos( * angle)) * ;//
Canvas.SetLeft(img, x);
Canvas.SetTop(img, y);
canvas_Shape.Children.Add(img);
}
}

为了添加背景音乐,使用了MediaElement。

       private void Window_Loaded(object sender, RoutedEventArgs e)
{ me.LoadedBehavior = MediaState.Manual; //设置为手动控制
me.UnloadedBehavior = MediaState.Manual;
string strPath = string.Format(@"{0}\data\music\bk.mp3", System.Windows.Forms.Application.StartupPath);
Uri uri = new Uri(strPath, UriKind.Relative);
me.Source = uri; me.IsHitTestVisible = true;
me.MediaEnded += new RoutedEventHandler(me_MediaEnded);
gd.Children.Add(me);
me.Play();
}

 为了能够循环播放

      private void me_MediaEnded(object sender, RoutedEventArgs e)
{
me.Stop();
me.Play();
}

WPF 画心2.0版之元旦快乐的更多相关文章

  1. 基于DDDLite的权限管理OpenAuth.net 1.0版正式发布

    距离上一篇OpenAuth.net的文章已经有5个多月了,在这段时间里项目得到了很多朋友的认可,开源中国上面的Star数接近300,于是坚定了我做下去的信心.最近稍微清闲点,正式推出1.0版,并在阿里 ...

  2. [转载]我的Java后端书架 (2016年暖冬4.0版)

      [转载]我的Java后端书架 (2016年暖冬4.0版) ps:最近正在初学Java,有一些其他语言的底子,但是还是要好好看书,好好练习,网上找了好久,都没有这份书单来的实用,特意转载过来,方便以 ...

  3. 不同编程语言打印“元旦快乐!"

    javascript: document.write("元旦快乐!"+"<br/>"); PHP: <?php echo "元旦快乐 ...

  4. UrlPager免费分页控件2.0版发布!

    UrlPager是一个ASP.NET WebForm应用程序中通过url进行分页的分页控件,支持使用url路由来生成自定义的分页url.与AspNetPager不同,UrlPager需.NET Fra ...

  5. MvcPager 免费开源分页控件3.0版发布!

    MvcPager 3.0版在原2.0版的基础上进行了较大的升级,对MvcPager脚本插件重写并进行了大量优化.修复了部分bug并新增了客户端Javascript API等功能,使用更方便,功能更强大 ...

  6. ASP.NET MVC分页组件MvcPager 2.0版发布暨网站全新改版

    MvcPager分页控件是在ASP.NET MVC Web应用程序中实现分页功能的一系列扩展方法,该分页控件的最初的实现方法借鉴了网上流行的部分源代码, 尤其是ScottGu的PagedList< ...

  7. bootstrap 2.3版与3.0版的使用区别

    bootstrap 2.3版与3.0版的使用区别 bootstrap已经推出了3.0的新版,看起来2.3.x版本也不会再更新了.那么bootstrap 2.3版与3.0版的区别在哪里呢?下面我们就来介 ...

  8. SWFUpload 2.5.0版 官方说明文档 中文翻译版

    原文地址:http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html#setFileUploadLimit SWFUpload v2 ...

  9. 我的Java后端书架 (2016年暮春3.0版)

      04月 24, 2016 | Filed under 技术 http://calvin1978.blogcn.com/articles/javabookshelf.html 书架主要针对Java后 ...

随机推荐

  1. Python Logging模块的简单使用

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

  2. dos命令

    一 .常用命令 1 dir无参数:查看当前所在目录的文件和文件夹./s:查看当前目录已经其所有子目录的文件和文件夹./a:查看包括隐含文件的所有文件./ah:只显示出隐含文件./w:以紧凑方式(一行显 ...

  3. 解决SmartGit序列号问题

    SmartGit过了30天试用期之后,就需要用户输入序列号才能继续使用,有一个办法可以跳过输入序列号. 一.windows+R  输入:%APPDATA%\syntevo\SmartGit 二.打开7 ...

  4. WKWebView与JavaScript交互基础

    login.html 代码 <!DOCTYPE html> <html> <head> <title>使用JavaScript</title> ...

  5. NSString属性什么时候用copy,什么时候用strong?

           我们在声明一个NSString属性时,对于其内存相关特性,通常有两种选择(基于ARC环境):strong与copy.那这两者有什么区别呢?什么时候该用strong,什么时候该用copy呢 ...

  6. leetcode 111 minimum depth of binary tree

    problem description: Given a binary tree, find its minimum depth. The minimum depth is the number of ...

  7. yum---Linux软件安装与管理

    查询: yum list #查询所有可用的软件包列表 yum search keywords #搜索服务器上所有和关键字相关的软件包 安装: yum -y install 包名 options: in ...

  8. 年月日与time的相互转换

    年月日的转换 // 这里就是把时间格式化成你要的 SimpleDateFormat sdf = new SimpleDateFormat("yyyy");//将时间转换为年 Sim ...

  9. python3.5.2本地环境搭建

    OS:win7 Download URL:https://www.python.org/downloads/release/python-352/ install 下载二进制安装文件之后,点击安装,一 ...

  10. webservice客户端开发

    一.根据约定条件生成客户端 1.需要axis.jar包 2.调用 import org.apache.axis.client.Call; import org.apache.axis.client.S ...