屏幕长满美女照片,还带播放音乐哟。(屏幕长满玫瑰花)C# WPF
2013-12-18 15:42
405 查看
最近刚学WPF,又恰逢朋友过生日,没什么好送的,就编写了个这个东西,现在贴在这作为纪念。
代码还有些需要改进的地方,不过现在比较忙,就不去优化了额,能实现效果就好。
屏幕长满美女照片(可以随便放什么照片),还带播放音乐哟。
XAML:
C#:
代码还有些需要改进的地方,不过现在比较忙,就不去优化了额,能实现效果就好。
屏幕长满美女照片(可以随便放什么照片),还带播放音乐哟。
XAML:
<Window x:Class="BirthdayGift.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" MouseDoubleClick="Window_MouseDoubleClick" Height="300" Width="300" AllowsTransparency="True" WindowStyle="None" Background="#00FFFFFF" Loaded="Window_Loaded"> <Grid Name="gd"> </Grid> </Window>
C#:
using System; using System.Collections.Generic; using System.Linq; using System.Text; 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; using System.Windows.Threading; using System.Media; namespace BirthdayGift { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { MediaElement me = new MediaElement(); DispatcherTimer timer = new DispatcherTimer();//创建定时器对象 int screenWidth = (int)SystemParameters.PrimaryScreenWidth; //获取屏幕宽 int screenHeight = (int)SystemParameters.PrimaryScreenHeight;//获取屏幕高 int index = 1; public MainWindow() { InitializeComponent(); this.WindowState = System.Windows.WindowState.Maximized;//最大化窗口 this.Height = screenHeight; this.Width = screenWidth; timer.Tick += new EventHandler(timer_Tick); //添加事件,定时到事件 timer.Interval = TimeSpan.FromMilliseconds(200);//设置定时长 timer.Start(); } void timer_Tick(object sender, EventArgs e) { Random rdm = new Random(unchecked((int)DateTime.Now.Ticks)); //创建随机生成器对象 int height = rdm.Next(screenHeight);//产生小于screenHeight的数 int width = rdm.Next(screenWidth); Image im = new Image(); index = rdm.Next(1, 22); //照片数目21,随机显示一张照片 im.Source = new BitmapImage(new Uri(@"photoes/"+index+".jpg", UriKind.Relative));//给出照片路径 im.Height = 200; im.Width = 200; im.Stretch = Stretch.Fill; //给出距离屏幕边界的距离 im.Margin = new Thickness(width,height,screenWidth-im.Width-width,screenHeight-im.Height-height); gd.Children.Add(im);//添加图片到窗口 } /// <summa /// 双击左键退出窗口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Close(); } private void Window_Loaded(object sender, RoutedEventArgs e) { me.LoadedBehavior = MediaState.Manual; //设置为手动控制 me.UnloadedBehavior = MediaState.Manual; me.Source = new Uri(@"E:\Gift\HappyBirthday.mp3", UriKind.RelativeOrAbsolute); me.IsHitTestVisible = true; me.MediaEnded += new RoutedEventHandler(me_MediaEnded); gd.Children.Add(me); me.Play(); } /// <summary> /// 媒体播放完后自动重播 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void me_MediaEnded(object sender, RoutedEventArgs e) { me.Stop(); me.Play(); } } }
相关文章推荐
- C#调用WindowsMediaPlayer控件实现音乐播放(一)
- C#后台播放音乐文件
- C#用mciSendString实现音乐的循环播放
- C#中函数库方式重复播放MP3音乐
- C#播放音乐
- C#中如何控制播放音乐的声音大小
- C# 使用WPF 用MediaElement控件实现视频循环播放
- C# WPF 如何禁止窗口拖到屏幕边缘自动最大化
- 使用C#调用win32 mciSendCommand 播放音乐
- C#同时播放两首音乐
- C#调用winmm播放音乐(.wav文件)
- C#播放音乐,调用程序
- [C#]使用WindowsAPI中的mciSendString函式播放音乐
- C#使用MediaPlayer控件播放MP3等音乐文件
- C#语言播放音乐的四种方法
- c# 播放音乐
- WPF C# 多屏情况下,实现窗体显示到指定的屏幕内
- 用c#和wpf制作屏幕录像gif工具
- C# winform使用系统API播放音乐(非调用控件)
- 用C#和vs2015编写了一个简单音乐播放器,实现功能,多条音乐导入,播放、暂停、上下曲。采用vs2105自带的一个播放器控件