c#图片自动播放程序
2014-03-15 21:14
253 查看
filp_v2系统,是练习c#控件的很好Demo案例。它包含了菜单、多窗口、图片框、复选框、容器等控件。
功能如下:
1:通过定时器完成自动翻转
2:设置毫秒值保存到xml数据中
3:文件夹对话框
4:文件对话框
5:自定义输入文件或目录
6:多个form之间数据共享
由于代码比较多,下面贴出核心代码
|---获取所有可执行文件、初始化xml保存数据。
功能如下:
1:通过定时器完成自动翻转
2:设置毫秒值保存到xml数据中
3:文件夹对话框
4:文件对话框
5:自定义输入文件或目录
6:多个form之间数据共享
由于代码比较多,下面贴出核心代码
|---获取所有可执行文件、初始化xml保存数据。
using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Xml; namespace flip_v2 { /** 图片+Xml工具类*/ public class ImgTool { /** * * 传递一个完整路径,返回一个ilst集合,0为路径(不含文件名) 1:播放的文件名(不包含路径) * 如C:\Users\Public\Pictures\Sample Pictures\八仙花.jpg * 0:C:\Users\Public\Pictures\Sample Pictures * 1:八仙花.jpg */ public static string[] pathToList(string path){ string[] array = new string[2]; int last = path.LastIndexOf("\\"); if(last!=-1){ array[0]=(path.Substring(0,last)); array[1]=(path.Substring(last+1)); } return array; } /**把所有文件封装到map中 key为uint64 value=string*/ public static Dictionary<UInt64,string> pathToMap(string path){ Dictionary<UInt64,string> dict = new Dictionary<UInt64,string>(); DirectoryInfo info = new DirectoryInfo(path); FileSystemInfo[] fileSystem = info.GetFileSystemInfos(); UInt64 count = 1; //获取所有子文件(不包含子文件夹), foreach(FileSystemInfo f in fileSystem){ FileInfo file = f as FileInfo; if(file!=null && fileterEndName(file.Name)) dict.Add(count++,f.FullName); } return dict; } //文件过滤器:png,jpg,gif public static bool fileterEndName(string endName){ endName = endName.ToLower(); bool b = false; string tag = ".png|.jpg|.gif"; int last = endName.LastIndexOf("."); if(last!=-1){ endName = endName.Substring(last); if(tag.Contains(endName)) b= true; } return b; } /**操作xml:默认保存到c:\\property.xml*/ public static void createXml(string path){ //xml样式 XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineOnAttributes = false; //本地创建一个新的xml XmlWriter write = XmlWriter.Create(path,settings); write.WriteStartDocument(); write.WriteStartElement("property"); write.WriteStartElement("time"); write.WriteAttributeString("id","setTime"); write.WriteValue("3000"); write.WriteEndElement(); write.WriteStartElement("localhostPath"); write.WriteAttributeString("id","setInputBoxPath"); write.WriteValue(""); write.WriteEndElement(); write.WriteEndElement(); write.WriteEndDocument(); //刷新缓冲区,并释放资源 write.Flush(); write.Close(); } } }|----目录图片的核心代码
<pre code_snippet_id="237877" snippet_file_name="blog_20140315_2_3804652" name="code" class="csharp"> /*执行的事件*/ public void theout(object source, EventArgs e) { Boolean b = checkTag.Checked; if(!b){ myTimer.Stop(); //停止定时器 }else{ //执行获取图片 string pageStr = showImg.Text; UInt64 pageNum = UInt64.Parse(pageStr); pageNum = pageNum+1; try{ showPage(pageNum); }catch(Exception){ //循环 showPage(1); //MessageBox.Show("已是未尾"); } } } /**后退*/ void BackOffClick(object sender, EventArgs e) { string pageStr = showImg.Text; UInt64 pageNum = UInt64.Parse(pageStr); pageNum = pageNum-1; try{ showPage(pageNum); }catch(Exception){ MessageBox.Show("已是顶页"); } } /**前进*/ void ForwardClick(object sender, EventArgs e) { string pageStr = showImg.Text; UInt64 pageNum = UInt64.Parse(pageStr); pageNum = pageNum+1; try{ showPage(pageNum); }catch(Exception){ MessageBox.Show("已是未尾"); } } public bool showPage(UInt64 pageNum) { if(dict==null || dict.Count==0){ MessageBox.Show("抱歉,没有找到可执行文件!"); stopImg.ForeColor=Color.Red; startImg.ForeColor=Color.LimeGreen; /*还原*/ Reduction(); return false; } string showImgPath = dict[pageNum]; showImg.Image = Image.FromFile(showImgPath); //回显信息 string[] str = ImgTool.pathToList(showImgPath); Many.Text = "来自:"+str[0]; Single.Text = "正在浏览【"+str[1]+"】"; //回显页码 showImg.Text = Convert.ToString(pageNum); return true; }
</pre>
下面贴出程序执行图片
相关文章推荐
- 写入简谱(flash钢琴谱)自动播放简谱琴声程序 c#
- 微信小程序给视频加图片封面且点击图片自动播放视频并停止播放上一个视频
- 传图取字:微信小程序自动把图片上的文字提取出来
- C#之tcp自动更新程序
- android中ViewPager图片滑动和自动播放
- 程矢Axure夜话:Axure基础系列视频教程之图片自动播放鼠标悬停
- C# Winform程序上传图片到指定目录
- .NET自动服务程序—C#
- C# 手动/自动保存图片
- C# 让程序自动以管理员身份运行
- 自动播放图片,可以调整速度。
- Flex 图片自动播放(亦可手动控制)
- 图片 缩略 和 水印 以及 C#获取当前程序运行路径的方法集合
- c#自动更新+安装程序的制作
- 动态生成Gallery控件组合实现无限循环自动播放广告图片效果总结
- 【开源程序(C++)】获取bing图片并自动设置为电脑桌面背景
- C#程序中将图片转换为byte数组,并将byte数组转换为图片
- css图片的查找方式和c#程序查找方式不一致
- 自动更新程序源码下载(C#.Net)
- php图片幻灯片方式自动播放