这个程序用到了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 制作播放视频的屏保程序、而且能分屏显示的更多相关文章

  1. 用Qt写的简单屏保程序

    近日老大提别人家产品都有屏保程序,貌似我们也该有,简单在qtcn.org请教了一下,写了个小程序! 晕倒,半天没找到上传功能!我已经上传到qtcn上了,地址如下: http://www.qtcn.or ...

  2. WinForm 屏保程序

    this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWind ...

  3. 3D屏保程序:汉诺塔

    学过程序的人一定记得汉诺塔.我们学的第一个程序是HelloWorld,而碰到的第一个坑就是汉诺塔,短短十几行代码,不知花费了多少时间精力去理解.我记得当年的开发环境还是蓝屏的,汉诺塔程序的输出还是一行 ...

  4. python写的屏保程序

    __author__ = 'ChenYan' from random import randint from tkinter import * class Randball(): def __init ...

  5. [archlinux][plasma][screensaver] plasma5配置屏保程序,没成功(-_-#)

    plamsa用了好久,一直没有屏保.我想要玄酷的屏保! 用xscreensaver, 之前用FVWM2的时候,就用过了,很玄酷. 一,安装 pacman -S xscreensaver 二,配置 xs ...

  6. 用processing生成屏保程序

    想法 利用随机数控制圆圈的大小.位置以及颜色,可以产生随机的美感. 让小球动起来,并且在屏幕边界处产生反弹效果. 代码 1: float circle_x = (float) 0.0; 2: floa ...

  7. WPF 制作 Windows 屏保

    分享如何使用WPF 制作 Windows 屏保 WPF 制作 Windows 屏保 作者:驚鏵 原文链接:https://github.com/yanjinhuagood/ScreenSaver 框架 ...

  8. 一个仿windows泡泡屏保的实现

    一个仿windows泡泡屏保的实现 有天看到有人在百度知道上问windows 泡泡屏保该怎么用C#做,一时有趣,就做了一个出来,对于其中几个要点总结如下: 一,屏保程序的制作要求 屏保程序的扩展名是. ...

  9. 3D屏保: 线圈

    LineFlower3DSP 一个3D屏保程序,算法的原理类似于圆内轮旋线的生成. 下载地址: http://files.cnblogs.com/WhyEngine/LineFlower3D_sp.z ...

随机推荐

  1. The Story of self Parameter in Python, Demystified

      转自:http://www.programiz.com/article/python-self-why If you have been programming in Python (in obj ...

  2. TensorFlow学习之运行label_image实例

    前段时间,搞了搞编译label_image中cc的实例,最后终于搞定...但想在IDE中编译还没成功,继续摸索中. 现分享一下,探究过程,欢迎叨扰,交流. 个人地址:http://home.cnblo ...

  3. 关于环信的WebIm的SDK一些使用注意

    先打自己几下脸,不好好看接口文档,啪啪啪. 主要先说下回调,直接先copy文档的 conn.listen({ onOpened: function ( message ) { //连接成功回调 //以 ...

  4. Node.js连接Mysql

    1.安装 npm install mysql 注意要复制node_modules到当前工程的文件夹中 2.基本连接 /** * Created by Administrator on 13-12-25 ...

  5. 给jdk写注释系列之jdk1.6容器(6)-HashSet源码解析&Map迭代器

    今天的主角是HashSet,Set是什么东东,当然也是一种java容器了.      现在再看到Hash心底里有没有会心一笑呢,这里不再赘述hash的概念原理等一大堆东西了(不懂得需要先回去看下Has ...

  6. VC+ADO连接DBF字符串

    1.m_strConnect.Format(TEXT("Driver={Microsoft dBASE Driver (*.dbf)}; DriverID=277;Dbq=%s;" ...

  7. Nginx - HTTP Configuration, Module Variables

    The HTTP Core module introduces a large set of variables that you can use within the value of direct ...

  8. C#算法基础之递归排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. ORACLE字符串分组聚合函数(字符串连接聚合函数)

    ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...

  10. C# 私人笔记

    .ADO.NET 连接数据库的模版 string constr = "data source=127.0.0.1\\mysql2008;database=dbtest;integrated ...