using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices

namespace 自动切换图像
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private bool Stara_Stop = true;
string path1,path2;
int i = 1;
private void timer1_Tick(object sender, EventArgs e)//自动切换
{
try
{
if (!Stara_Stop && (i < (Convert.ToInt16(textBox1.Text) + 1)))
{

//Thread.Sleep(1000);
pictureBox1.Image = null;
path2 = path1 + i.ToString() + Image_format();
pictureBox1.Image = Image.FromFile(path2);
if (i == Convert.ToInt16(textBox1.Text))
{
i = 0;
}
i++;

}
}
catch (Exception ex)
{
timer1.Enabled = false;
MessageBox.Show(ex.Message,"error!",MessageBoxButtons.OK);
}
}

private void button1_Click(object sender, EventArgs e)//开始停止
{
if(m_Data_null())
{
if (Stara_Stop)
{
path1 = path();
button1.Text = "停止切换";
button1.BackColor = Color.Red;
Stara_Stop = false;
timer1.Enabled = true;
timer1.Interval = Convert.ToInt16(textBox3.Text);

textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
comboBox1.Enabled = false;
button2.Enabled = false;
}
else
{
button1.Text = "开始切换";
button1.BackColor = Color.White;
Stara_Stop = true;
timer1.Enabled = false;

textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
comboBox1.Enabled = true;
button2.Enabled = true;

}
}
}

private bool m_Data_null()
{
bool m_Data = false;
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty && textBox3.Text != string.Empty
&& comboBox1.Text != string.Empty)
{
m_Data = true;
}
else
{
m_Data = false;
MessageBox.Show("请设置切换的图像及条件!", "提示!", MessageBoxButtons.OK);
}
return m_Data;
}

private string path()//图像路径
{
string m_path;
if (textBox1.Text == string.Empty)
{
m_path = @"D:\_VS2015_\图像自动切换\Image\robot\";

}
else
{
m_path = textBox2.Text+ @"\";
}
return m_path;
}

private string Image_format()//图像格式
{
string format;
format = comboBox1.Text;
return format;
}

private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = ".PNG";
}

private void button2_Click(object sender, EventArgs e)
{
i = 1;
pictureBox1.Image = null;
}

private void textBox2_MouseDoubleClick(object sender, MouseEventArgs e)
{
//选择打开文件
//OpenFileDialog of = new OpenFileDialog();
//if (of.ShowDialog() == DialogResult.OK)
//{
// textBox2.Text = of.FileName;
//}

//选择文件夹路径

FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
textBox2.Text = folderBrowserDialog.SelectedPath;
//获取文件数量
var flies = Directory.GetFiles(textBox2.Text);
textBox1.Text = (flies.Length).ToString();
}
}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

}
}

//以下是UI界面

C# 图像自动切换的更多相关文章

  1. 【温故而知新-Javascript】图片效果(图像震动效果、闪烁效果、自动切换图像)

    1.当鼠标指针经过图像时图像震动效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  2. 自定义Image自动切换图像控件

    做这么一个控件,图片自动切换,形成动画效果. 随便的码码,码完发现东西太少了,不过还算完善. public class MyPictureBox : PictureBox { Timer timer ...

  3. 原生js+css3实现图片自动切换,图片轮播

    运用CSS3transition及opacity属性 制作图片轮播动画 自己这两天根据用js来控制触发CSS3中transition属性,从而写出来的以CSS3动画为基础,js控制过程的图片轮播 运用 ...

  4. 获取bing.com的图片并在gnome3中设置自动切换

    发现 bing.com 上的图片很好看,因此打算每天把 bing.com 的图片下载下来,用作桌面. 需要做的是两个部分,爬取图片到目录和设置目录图片为桌面背景并可以自动切换. 第一部分,下载图片,使 ...

  5. 在 Visual Studio 等编辑器/IDE中自动切换输入法,不需要手动的有没有?

    使用Visual Studio写代码,经常遇到的一个问题就是切换中文输入法麻烦,输入完注释//,要切换到中文,输入完引号,要输入中文,然后还需要切换回来,有没有? 有时候中文输入法忽然失效有没有?明明 ...

  6. jquery背景自动切换特效

    查看效果网址:http://keleyi.com/a/bjad/4kwkql05.htm 本特效的jquery版本只支持1.9.0以下. 代码如下: <!DOCTYPE html PUBLIC ...

  7. jquery叠加页片自动切换特效

    查看效果:http://keleyi.com/keleyi/phtml/jqtexiao/34.htm 下面是HTML代码: <!DOCTYPE html> <html xmlns= ...

  8. Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片

    Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在Vie ...

  9. ios基础篇(二十三)—— 定时器NSTimer与图片的自动切换

    一.NSTimer NSTimer是一个能在从现在开始到后面的某一个时刻或者周期性的执行我们指定的方法的对象.可以按照一定的时间间隔,将制定的信息发送给目标对象.并更新某个对象的行为.你可以选择在未来 ...

随机推荐

  1. Sql求和异常——对象不能从 DBNull 转换为其他类型

    做项目遇到一个以前没遇到的问题,就是要计算一个用户消费总额, 关键代码如下: string sql = "select sum(Tmoney) from [order] where uid= ...

  2. C#中如何创建xml文件 增、删、改、查 xml节点信息

    XML:Extensible Markup Language(可扩展标记语言)的缩写,是用来定义其它语言的一种元语言,其前身是SGML(Standard Generalized Markup Lang ...

  3. ServiceStack支持跨域提交

    //ServiceStack对浏览器有一定的限制 //修改AppHost.cs文件 using Funq;using ServiceStack;using ServiceStackTest.Servi ...

  4. PAT 1053 住房空置率 (20)(代码+思路)

    1053 住房空置率 (20)(20 分) 在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断.判断方法如下: 在观察期内,若存在超过一半的日子用电量低于某给定的阈值 ...

  5. KbmMW 4.30.00 发布

    今天早上,KbmMW发布了4.30.00 版,这个版本开始支持XE4 的WIN/WIN64/OSX. 暂时不支持ios开发,同时加强了通过JSON 的对象序列化.还有就是解决了我提交的几个有关 汉字处 ...

  6. 2018.09.07 Amount of degrees(数位dp)

    描述 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和. 例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 17 = 24+20, ...

  7. ESP8266-01一些内容

    系统有些指令必须特性状态下才可以执行,即先执行一些其它AT指令 1.设置station模式的IP信息 AT+CIPSTA="192.168.19.1","192.168. ...

  8. jar 包和 mysql 服务器部署

    (1)创建好本地服务器: navicat新建链接: 链接名:自定义,这里命名为test 配置同jar包 (2)给予登陆权限,loclhost_3306,右击选择“命令行界面”,输入如下: create ...

  9. if_elseif

    用MATLAB写了个这样的程序 if ((0 < pwr <=2) ) wf_temp1 = round(temp_wf0/2^7); elseif( (2 < pwr<= 4 ...

  10. qt编程遇到的东西

    setWindowFlags http://blog.chinaunix.net/uid-23500957-id-3876399.html move()方法,的作用是设置QWidget部件的pos坐标 ...