wpf 制作播放视频的屏保程序、而且能分屏显示
这个程序用到了WPF里 “visual_Brush”(主要是为了实现分屏显示) , “UserControl” ,这两个知识点;
在屏保状态下播放指定文件夹下的视频,而且能分屏显示;
把编译好的屏保程序(原本是.exe)改名为.SCR 放到C:\Windos\System32下
现在就可以设置为屏保了:譬如win7系统的 在桌面属性→→个性化设置里→→ 选择屏保程序→→ 这时候就能看到你写的屏保程序的名字了(切记改名.scr);
MainWindow.xaml:
<Window x:Class="visual_Brush.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
Title="MainWindow" Height="1080" Width="3840" WindowStyle="None" ResizeMode="NoResize"
xmlns:local="clr-namespace:visual_Brush" WindowStartupLocation="Manual" Background="Black" Left="0" Top="0"
MouseDown="Window_MouseDown" TouchDown="Window_TouchDown" Topmost="True">
<Grid Height="1080" Width="3840" Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<local:UserControl_Video x:Name="Video" Height="1080" Width="1920" Grid.Column="0"></local:UserControl_Video>
<Grid x:Name="ExtendedScreenGrid" Height="1080" Width="1920" Grid.Column="1" Background="Black" VerticalAlignment="Top" HorizontalAlignment="Right" >
<Rectangle StrokeThickness="0">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=Video}">
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
</Window>
MainWindow.cs(后台代码)→)→)→)→)→)→)→)→)→)→)→)→
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
this.Close();
}
}
UserControl_Video.xaml
<UserControl x:Class="visual_Brush.UserControl_Video"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Loaded="UserControl_Loaded_1">
<Grid x:Name="grid">
<MediaElement Name="myMedia" LoadedBehavior="Play" MediaOpened="myMedia_MediaOpened">
</MediaElement>
</Grid>
</UserControl>
UserControl_Video.cs(后台代码)
public partial class UserControl_Video : UserControl
{
int i = 0;
string[] carImageUris = Directory.GetFiles(@"D:\video");//指定文件夹目录
private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
{
myMedia.MediaEnded+=new RoutedEventHandler(myMedia_MediaEnded);
myMedia.Source = new Uri(carImageUris[0], UriKind.Absolute);
}
void myMedia_MediaOpened(object sender, RoutedEventArgs e)
{
myMedia.LoadedBehavior = MediaState.Manual;
myMedia.Play();
}
/// <summary>
/// 当媒体结束时发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void myMedia_MediaEnded(object sender, RoutedEventArgs e)
{
if (i!= carImageUris.Length-1)
{
i++;
myMedia.Source = new Uri(carImageUris[i], UriKind.Absolute);
}
else
{
myMedia.Source = new Uri(carImageUris[0], UriKind.Absolute);
i = 0;
}
}
public UserControl_Video()
{
InitializeComponent();
myMedia.Volume = 100;
//myMedia.Play();
}
void mediaPlay(Object sender, EventArgs e)
{
myMedia.Play();
}
}
wpf 制作播放视频的屏保程序、而且能分屏显示的更多相关文章
- 用Qt写的简单屏保程序
近日老大提别人家产品都有屏保程序,貌似我们也该有,简单在qtcn.org请教了一下,写了个小程序! 晕倒,半天没找到上传功能!我已经上传到qtcn上了,地址如下: http://www.qtcn.or ...
- WinForm 屏保程序
this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWind ...
- 3D屏保程序:汉诺塔
学过程序的人一定记得汉诺塔.我们学的第一个程序是HelloWorld,而碰到的第一个坑就是汉诺塔,短短十几行代码,不知花费了多少时间精力去理解.我记得当年的开发环境还是蓝屏的,汉诺塔程序的输出还是一行 ...
- python写的屏保程序
__author__ = 'ChenYan' from random import randint from tkinter import * class Randball(): def __init ...
- [archlinux][plasma][screensaver] plasma5配置屏保程序,没成功(-_-#)
plamsa用了好久,一直没有屏保.我想要玄酷的屏保! 用xscreensaver, 之前用FVWM2的时候,就用过了,很玄酷. 一,安装 pacman -S xscreensaver 二,配置 xs ...
- 用processing生成屏保程序
想法 利用随机数控制圆圈的大小.位置以及颜色,可以产生随机的美感. 让小球动起来,并且在屏幕边界处产生反弹效果. 代码 1: float circle_x = (float) 0.0; 2: floa ...
- WPF 制作 Windows 屏保
分享如何使用WPF 制作 Windows 屏保 WPF 制作 Windows 屏保 作者:驚鏵 原文链接:https://github.com/yanjinhuagood/ScreenSaver 框架 ...
- 一个仿windows泡泡屏保的实现
一个仿windows泡泡屏保的实现 有天看到有人在百度知道上问windows 泡泡屏保该怎么用C#做,一时有趣,就做了一个出来,对于其中几个要点总结如下: 一,屏保程序的制作要求 屏保程序的扩展名是. ...
- 3D屏保: 线圈
LineFlower3DSP 一个3D屏保程序,算法的原理类似于圆内轮旋线的生成. 下载地址: http://files.cnblogs.com/WhyEngine/LineFlower3D_sp.z ...
随机推荐
- oracle顺序控制语句goto、null和分页过程中输入输出存储、java程序的调用过程
顺序控制语句1 goto建议不要使用 declare i number:=; begin loop dbms_output.put_line(i); then goto end_loop; end i ...
- Linux vsftpd 无法登录 cannot change directory:xxx priv_sock_get_cmd 问题
配置vsftpd时本地用户无法切换不能登录问题.问题如下: C:\Users\kai>ftp ftp> open 172.24.144.10 连接到 172.24.144.10. (vsF ...
- spl_autoload_register()和__autoload()区别
这篇文章主要介绍了spl_autoload_register()和__autoload()区别,需要的朋友可以参考下 关于spl_autoload_register()和__autoload(), ...
- poj 1741 树的分治
思路:这题我是看 漆子超<分治算法在树的路径问题中的应用>写的. 附代码: #include<iostream> #include<cstring> #includ ...
- hdu 1394 树状数组
思路:从后面往前面统计,每次先sum+=Sum(num[i]+1),然后在update(num[i]+1,1).这样每次Sum每次加的个数就是num[i]的逆序对个数. 每次从队首调一个元素到队尾,逆 ...
- poj 1716 差分约束
水水的. 给几个不等式:dis[b]-dis[a]>=2; 0<=dis[i+1]-dis[i]<=1; #include<iostream> #include< ...
- 转:一个C语言实现的类似协程库(StateThreads)
http://blog.csdn.net/win_lin/article/details/8242653 译文在后面. State Threads for Internet Applications ...
- java性能
一.关于性能的基本知识 1.性能的定义 在我们讨论怎样提高Java的性能之前,我们需要明白“性能“的真正含义.我们一般定义如下五个方面作为评判性能的标准. 1) 运算的性能----哪一个算法的执 ...
- (转)MSMQ续
原文作者:虔诚者 点此传送至原文 在上一篇我简单介绍了MSMQ的相关概念,本篇将以代码说明 Message Message是MSMQ的数据存储单元,我们的用户数据一般也被填充在Message的b ...
- Bootstrap简单Demo(2015年05月-18日)
Bootstrap的简单使用 1.Bootstrap是什么? 这是Bootstrap官网上对它的描述:Bootstrap是最受欢迎的HTML.CSS和JS框架,用于开发响应式布局.移动设备优先的WEB ...