基本信息
源码名称:图片全屏播放器
源码大小:0.03M
文件格式:.rar
开发语言:C#
更新时间:2022-01-13
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 1 元 
   源码介绍

图片全屏播放器

图片全屏播放器,可以多选2个播放目录顺序播放或轮换播放,也可以定时播放

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
using AxWMPLib;
using System.Threading;

namespace 图片播放
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string picPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) "\\图片播放设置.ini";
        String dtNhms;
        DateTime dtB, dtE, dtN;
        int tm,dc,vz,index;
        bool play,dcvz;
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)))//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
            }
            readIni();//读取配置文件
            CK();
            if (autoPlayCK.Checked == true) 
            {
                this.WindowState = FormWindowState.Maximized;
                Button();
            }
        }
        public void CK()
        {
            if (timingCK.Checked == true)
            {
                dtB = dateTimeStart.Value;
                dtE = dateTimeEnd.Value;
                if (dtB > dtE)
                {
                    dcBox.Text = "定时开始时间必须小于结束时间";
                    timer1.Stop();
                }
            }
        }
        public void cmD(string c)
        {
            try
            {

                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                p.StandardInput.WriteLine(c);
                p.StandardInput.WriteLine("exit");
                p.WaitForExit();
                p.Close();
            }
            catch
            {

            }
        }
        public void readIni()
        {
            try
            {
                dcBox.Text = ReadString("轮播目录", "图片目录1", "", picPath);
                vzBox.Text = ReadString("轮播目录", "图片目录2", "", picPath);
                timingBox.Text = ReadString("定时轮播", "定时目录", "", picPath);
                qieHuanTimeText.Text = ReadString("播放模式", "切换时间", "", picPath);
                try
                {
                    if (Int32.Parse(timingBox.Text) < 1)
                    {
                        timer1.Stop();
                        formStop();
                        label7.Text = "配置的切换时间太短,请输入大与1的整数";
                    }
                }
                catch
                {
                    timer1.Stop();
                    formStop();
                    label7.Text = "输入的时长错误,请输入大与1的整数";
                }
                try
                {
                    timingCK.Checked = bool.Parse(ReadString("定时轮播", "开启轮播", "", picPath));
                    jgbf.Text = ReadString("定时轮播", "间隔张数", "", picPath);
                }
                catch
                {
                    timingCK.Checked = false;
                    if (jgbf.Text=="")
                    {
                        jgbf.Text = "1";
                    }
                }
                try
                {
                    charulunboCK.Checked = bool.Parse(ReadString("播放模式", "插入轮播", "", picPath));
                    xunxulunboCK.Checked= bool.Parse(ReadString("播放模式", "循序轮播", "", picPath));
                    onlyCK.Checked= bool.Parse(ReadString("定时轮播", "只放定时", "", picPath));
                    if (charulunboCK.Checked == true && xunxulunboCK.Checked == true)
                    {
                        timer1.Stop();
                        formStop();
                        label7.Text = "请选择插入模式或循序模式";
                        return;
                    }
                    if (charulunboCK.Checked == false && xunxulunboCK.Checked == false)
                    {
                        timer1.Stop();
                        formStop();
                        label7.Text = "请选择插入模式或循序模式";
                        return;
                    }
                 }
                catch
                {
                    timer1.Stop();
                    formStop();
                    label7.Text = "读取配置文件出错,请重新配置";
                }
                try
                {
                    pic1CK.Checked = bool.Parse(ReadString("播放模式", "播放图片1", "", picPath));
                    pic2CK.Checked = bool.Parse(ReadString("播放模式", "播放图片2", "", picPath));
                    if (pic1CK.Checked==false&&pic2CK.Checked==false)
                    {
                        timer1.Stop();
                        formStop();
                        label7.Text = "请配置播放目录,必须至少选定一个播放目录";
                    }
                }
                catch
                {
                    timer1.Stop();
                    formStop();
                    label7.Text = "读取配置文件出错,请重新配置";
                }
                if (timingCK.Checked == true)
                {
                dateTimeStart.Text = ReadString("定时轮播", "定时开始", "", picPath);
                dateTimeEnd.Text = ReadString("定时轮播", "定时结束", "", picPath);
                }
                else
                {
                    dateTimeStart.Text = DateTime.Now.ToString();
                    dateTimeEnd.Text = DateTime.Now.ToString();
                }
                try
                {
                    autoPlayCK.Checked = bool.Parse(ReadString("自动播放", "开启自动", "", picPath));
                }
                catch
                {
                    autoPlayCK.Checked = false;
                }
                tm = int.Parse(qieHuanTimeText.Text);
                try
                {
                    timingTFCheck.Checked = bool.Parse(ReadString("定时关机", "开启定时关机", "", picPath));
                }
                catch
                {
                    timingTFCheck.Checked = false;
                }
                try
                {
                    timingHH.Text = ReadString("定时时间", "时", "", picPath);
                    timingMM.Text = ReadString("定时时间", "分", "", picPath);
                }
                catch
                {
                    if (timingTFCheck.Checked==true)
                    {
                        if (timingHH.Text == "" || timingMM.Text == "" )
                        {
                            label7.Text = "定时关机配置错误,请重新配置定时关机时间";
                            timer1.Stop();
                        }
                    }
                    else
                    {
                        timingHH.Text = ""; timingMM.Text = "";
                    }

                }
                try
                {
                    jianGeCk.Checked = bool.Parse(ReadString("定时轮播", "轮播模式", "", picPath));
                }
                catch
                {
                    jianGeCk.Checked = false;
                }
            }
            catch
            {
                label7.Text = "保存的配置信息有误,请重新配置";
                tm = 0;
                timer1.Stop();
            }
        }
        [DllImport("user32.dll")]
        private static extern int SetCursorPos(int x, int y);
        public void MoveMouseToPoint(Point p)
        {
            SetCursorPos(p.X, p.Y);
        }
        public void SetMouseRectangle(Rectangle rectangle)
        {
            System.Windows.Forms.Cursor.Clip = rectangle;
        }
        public void SetMouseAtCenterScreen()
        {
            int winHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            int winWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
            Point centerP = new Point(1920, 800);
            MoveMouseToPoint(centerP);
        }
        [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
        public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

        public static void WriteIniKeys(string section, string key, string value, string filePath)
        {
            WritePrivateProfileString(section, key, value, filePath);
        }
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

        private void button3_Click(object sender, EventArgs e)
        {
            Button();
        }
        public void Button()
        {
            i = 0;
            x = 0;
            dcvz = true;
            CK();
            //ifTime();
            try
            {
                WriteIni();
                if (play == true)
                {
                    this.FormBorderStyle = FormBorderStyle.None;
                    this.WindowState = FormWindowState.Maximized;
                    pictureBox1.Dock = DockStyle.Fill;
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    timer1.Interval = tm * 1000;
                    timer1.Start();
                    SetMouseAtCenterScreen();
                    this.WindowState = FormWindowState.Normal;
                    this.WindowState = FormWindowState.Maximized;
                    this.ShowInTaskbar = true;
                    base.SetVisibleCore(true);
                }
                play = true;

            }
            catch
            {
                label7.Text = "请选择存放图片的文件夹和时间";
                timer1.Stop();
            }
            cmD("w32tm /resync");
        }
        public void deskTop(string dir)
        {
            SystemParametersInfo(20, 0, dir, 0x2);
        }
        int a = 5,i,x;
        Point screenPoint = Control.MousePosition;
        
        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
            //pictureBox1.Image.Dispose();
            dtN = DateTime.Now;
            if (timingTFCheck.Checked == true)
            {
                try
                {
                    dtNhms = DateTime.Now.ToString("H:m");
                    {
                        string t = timingHH.Text ":" timingMM.Text;
                        if (dtNhms == t) { cmD("shutdown -s -f -t 10"); }
                    }
                }
                catch
                {
                    play = false;
                    label7.Text = "定时关机错误,请重新配置相关信息";
                    timer1.Stop();
                }
            }
            if (timingCK.Checked == true && dtN >= dtB && dtN <= dtE)
            {
                if (!Directory.Exists(timingBox.Text))
                {

                    timer1.Stop();
                    formStop();
                    label7.Text = "选择的文件夹不存在,请重新选择存放图片的文件夹";
                }
            }
            else
            {
                if (pic1CK.Checked==true&&!Directory.Exists(dcBox.Text))
                {

                    timer1.Stop();
                    formStop();
                    label7.Text = "图片目录1文件夹不存在,请重新选择文件夹";

                }
                if (pic2CK.Checked == true && !Directory.Exists(vzBox.Text))
                    {

                        timer1.Stop();
                        formStop();
                        label7.Text = "图片目录2文件夹不存在,请重新选择文件夹";

                    }
            }
            Point screenPoint1 = Control.MousePosition;
            if (screenPoint == screenPoint1)
            {
                a = a - 1;
            }
            else
            {
                a = 5;
                screenPoint = screenPoint1;
            }
            if (a == 0)    //每隔壁30秒鼠标移动到最右边
            {
                a = 5;
                SetMouseAtCenterScreen();
            }
            //if (bofangshiping.Checked==false)
            //{
            try
            {
                if (timingCK.Checked == true && dtN >= dtB && dtN <= dtE)
                {
                    if (jianGeCk.Checked == true)
                    {
                        if (i == int.Parse(jgbf.Text))
                        {
                            x = jpg(timingBox.Text, x) 1;
                            i ;
                        }
                        else
                        {
                            jpgPlay();
                            i ;
                        }
                    }
                    else
                    {
                        onlyCK.Checked = true;
                        x = jpg(timingBox.Text, x) 1;
                        i ;
                    }
                }
                    else
                    {
                        jpgPlay();
                        i ;
                    
                    }
                    if (i > int.Parse(jgbf.Text))
                    {
                        i = 0;
                    }
                }
                catch
                {
                    timer1.Stop();
                    label7.Text = "播放错误,请检查目录及文件是否正常";
                }
            //}
            //if (bofangshiping.Checked == true)
            //{
            //    //SPplay(textBox1.Text);
            //}
        }
        public void SPplay(string path)
        {
            DirectoryInfo avi = new DirectoryInfo(path);
            List<string> fileNames = new List<string>();
            foreach (FileInfo file in avi.GetFiles("*.mp4"))
            {
                //listBox1.Items.Add(avi.Name);
                fileNames.Add(file.Name);
            }
           //axWindowsMediaPlayer1.Show();
            //axWindowsMediaPlayer1.URL =path "\\" (string)listBox1.Items[index];
            //axWindowsMediaPlayer1.URL = path "\\" (string)fileNames[index];
            index ;
            if (index > fileNames.Count - 1) index = 0;

        }
        public void jpgPlay()
        {
            if (play == true)
            {
                if (pic1CK.Checked == true && pic2CK.Checked == false)
                {
                    dc = jpg(dcBox.Text, dc) 1;
                    if (play == false)
                    {
                        label7.Text = "图片目录1文件夹内无图片文件或文件错误,请尝试先解密";
                    }
                }
                if (pic1CK.Checked == false && pic2CK.Checked == true)
                {
                    vz = jpg(vzBox.Text, vz) 1;
                    if (play == false)
                    {
                        label7.Text = "图片目录2文件夹内无图片文件或文件错误,请尝试先解密";
                    }
                }
                if (charulunboCK.Checked == true && pic1CK.Checked == true && pic2CK.Checked == true)
                {
                    if (dcvz == true)
                    {
                        dc = jpg(dcBox.Text, dc) 1;
                        dcvz = false;
                        if (play==false)
                        {
                            label7.Text = "图片目录1文件夹内无图片文件或文件错误,请尝试先解密";
                        }
                    }
                    else if (dcvz == false)
                    {
                        vz = jpg(vzBox.Text, vz) 1;
                        dcvz = true; ;
                        if (play == false)
                        {
                            label7.Text = "图片目录2文件夹内无图片文件或文件错误,请尝试先解密";
                        }
                    }
                }
                if (xunxulunboCK.Checked == true && pic1CK.Checked == true && pic2CK.Checked == true)
                {
                    if ( dcvz==true )
                    {
                        if (dc > jpg(dcBox.Text, dc))
                        {
                            dcvz = false;
                            dc = 0;
                         }
                        if(play == false)
                        {
                            label7.Text = "图片目录1文件夹内无图片文件或文件错误,请尝试先解密";
                        }
                        dc ;
                    }
                    if (dcvz==false)
                    {
                        if (vz > jpg(vzBox.Text, vz))
                        {
                            dcvz = true;
                            vz = 0;
                            if (play == false)
                            {
                                label7.Text = "图片目录2文件夹内无图片文件或文件错误,请尝试先解密";
                            }
                        }
                        vz ;
                    }
                }
            }
        }
        public int jpg(string Path, int i)
        {
            DirectoryInfo jpg = new DirectoryInfo(Path);
            try
            {
                FileSystemInfo[] fileInfo = jpg.GetFileSystemInfos();
                List<string> fileNames = new List<string>();
                foreach (FileInfo item in fileInfo)
                {
                    fileNames.Add(item.Name);
                }
                if (fileNames.Count == 0)
                {
                    formStop();
                    timer1.Stop();
                }
                
                if (i < fileNames.Count)
                {
                    pictureBox1.BringToFront();
                    string file = fileNames[i];
                    this.pictureBox1.Load(Path "\\" file);
                    label7.Text = "正在播放" file;
                }
                if(i >= fileNames.Count)
                {
                    i = 0;
                    pictureBox1.BringToFront();
                    string file = fileNames[i];
                    this.pictureBox1.Load(Path "\\" file);
                    label7.Text = "正在播放" file;
                }

            }
            catch
            {
                timer1.Stop();
                formStop();
            }
            return i;
        }

        private Image GetImage(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return null;
            }

            using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
            {
                byte[] bytes = new byte[fileStream.Length];
                fileStream.Read(bytes, 0, bytes.Length);

                MemoryStream memoryStream = new MemoryStream(bytes);
                if (memoryStream != null)
                {
                    return Image.FromStream(memoryStream);
                }
            }

            return null;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            formStop();
        }
        public void formStop()
        {
            play = false;
            pictureBox1.SendToBack();
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.WindowState = FormWindowState.Normal;
            this.Height = 250;
            this.Width = 460;
            pictureBox1.Dock = DockStyle.Fill;
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Refresh();
            pictureBox1.Image = null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            dialog.SelectedPath = dcBox.Text;
            //dialog.RootFolder = Environment.SpecialFolder.Programs;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                dcBox.Text = dialog.SelectedPath;
            }
        }


        private void xunxulunbo_CheckedChanged(object sender, EventArgs e)
        {
            charulunboCK.Checked = false;
            if (charulunboCK.Checked == false)
            {
                xunxulunboCK.Checked = true;
            }
        }

        private void charulunbo_CheckedChanged(object sender, EventArgs e)
        {
            xunxulunboCK.Checked = false;
            if (xunxulunboCK.Checked == false)
            {
                charulunboCK.Checked = true;
            }
        }
           

        private void button7_Click(object sender, EventArgs e)
        {
            SPplay(dcBox.Text);
        }

        private void checkBox4_CheckedChanged_1(object sender, EventArgs e)
        {
                onlyCK.Checked = false;
                if (onlyCK.Checked == false)
                {
                    jianGeCk.Checked = true;
                }
        }

        private void Only_CheckedChanged_1(object sender, EventArgs e)
        {
            jianGeCk.Checked = false;
            if (jianGeCk.Checked == false)
            {
                onlyCK.Checked = true;
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            formStop();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            dialog.SelectedPath = dcBox.Text;
            //dialog.RootFolder = Environment.SpecialFolder.Programs;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                vzBox.Text = dialog.SelectedPath;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            WriteIni();
        }
        public void WriteIni()
        {
            tm = int.Parse(qieHuanTimeText.Text);
            if (charulunboCK.Checked==true&&xunxulunboCK.Checked==true)
            {
                label7.Text = "请选择插入模式或循序模式";
                return;
            }
            if (charulunboCK.Checked == false && xunxulunboCK.Checked == false )
            {
                label7.Text = "请选择插入模式或循序模式";
                return;
            }
            if (pic1CK.Checked == false && pic2CK.Checked == false)
            {
                label7.Text = "必须至少选定一个播放目录";
                return;
            }
            if (timingCK.Checked == true && timingBox.Text == "")
            {
                label7.Text = "请选择存放定时播放图片的文件夹";
                play=false;
                return;
            }
            if (timingTFCheck.Checked == true)
            {
                if (timingHH.Text == "" || timingMM.Text == "" )
                {
                    label7.Text = "定时关机配置错误,请重新配置定时关机时间";
                    play = false;
                    return;
                }
            }
            if (jgbf.Text == "")
            {
                jgbf.Text = "1";
            }
            if (tm<1)
            {
                label7.Text = "选定的图片切换时间错误,请输入大于1的整数";
                play = false;
                return;
            }
            if (dcBox.Text == "" || qieHuanTimeText.Text == "")
            {
                label7.Text = "请选择存放图片的文件夹和时间";
                play = false;
                return;
            }
            else
            {
                WriteIniKeys("轮播目录", "图片目录1", dcBox.Text, picPath);
                WriteIniKeys("播放模式", "切换时间", qieHuanTimeText.Text, picPath);
                WriteIniKeys("轮播目录", "图片目录2", vzBox.Text, picPath);
                WriteIniKeys("定时轮播", "开启轮播", timingCK.Checked.ToString(), picPath);
                WriteIniKeys("定时轮播", "定时目录", timingBox.Text, picPath);
                WriteIniKeys("定时轮播", "定时开始", dateTimeStart.Value.ToString("yyyy/MM/dd") " 0:00:00", picPath);
                WriteIniKeys("定时轮播", "定时结束", dateTimeEnd.Value.ToString("yyyy/MM/dd") " 23:59:59", picPath);
                WriteIniKeys("定时轮播", "轮播模式", jianGeCk.Checked.ToString(), picPath);
                WriteIniKeys("定时轮播", "间隔张数", jgbf.Text, picPath);
                WriteIniKeys("自动播放", "开启自动", autoPlayCK.Checked.ToString(), picPath);
                WriteIniKeys("定时关机", "开启定时关机", timingTFCheck.Checked.ToString(), picPath);
                WriteIniKeys("播放模式", "插入轮播", charulunboCK.Checked.ToString(), picPath);
                WriteIniKeys("播放模式", "循序轮播", xunxulunboCK.Checked.ToString(), picPath);
                WriteIniKeys("播放模式", "播放图片目录1", pic1CK.Checked.ToString(), picPath);
                WriteIniKeys("播放模式", "播放图片目录2", pic2CK.Checked.ToString(), picPath);
                WriteIniKeys("定时轮播", "只放定时", onlyCK.Checked.ToString(), picPath);
                WriteIniKeys("定时时间", "时", timingHH.Text, picPath);
                WriteIniKeys("定时时间", "分", timingMM.Text, picPath);
                play = true;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            dialog.SelectedPath = timingBox.Text;
            //dialog.RootFolder = Environment.SpecialFolder.Programs;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                timingBox.Text = dialog.SelectedPath;
            }
        }

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        private static string ReadString(string section, string key, string def, string filePath)
        {
            StringBuilder temp = new StringBuilder(1024);

            try
            {
                GetPrivateProfileString(section, key, def, temp, 1024, filePath);
            }
            catch
            { }
            return temp.ToString();
        }
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            int WM_KEYDOWN = 256;

            int WM_SYSKEYDOWN = 260;

            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {
                switch (keyData)
                {
                    case Keys.Escape:

                        formStop();
                        timer1.Stop();

                        break;

                }



            }

            return false;

        }

    }
}

.
├── 图片播放
│   ├── 图片播放
│   │   ├── Form1.Designer.cs
│   │   ├── Form1.cs
│   │   ├── Form1.resx
│   │   ├── Program.cs
│   │   ├── Properties
│   │   │   ├── AssemblyInfo.cs
│   │   │   ├── Resources.Designer.cs
│   │   │   ├── Resources.resx
│   │   │   ├── Settings.Designer.cs
│   │   │   ├── Settings.settings
│   │   │   └── app.manifest
│   │   ├── app.config
│   │   ├── bin
│   │   │   ├── Debug
│   │   │   ├── Release
│   │   │   └── x86
│   │   │       ├── Debug
│   │   │       └── Release
│   │   ├── obj
│   │   │   ├── Debug
│   │   │   └── x86
│   │   │       └── Debug
│   │   ├── 图片播放.csproj
│   │   └── 图片播放.csproj.user
│   └── 图片播放.sln
└── 好例子网_图片播放.rar

13 directories, 15 files