使用c#在vs2005下写的换桌面图片的小程序(from: http://www.wangchao.net.cn/bbsdetail_26766.html)
2008-07-09 15:30
711 查看
首先,建一个windows应用程序,所需控件有pictureBox, OpenFileDialog, textBox, 2个Button
其次,构造函数前添加
其次,构造函数前添加
[DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); private string filePath;
添加两个Button的click事件//桌面只能显示bmp图片 private void button1_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = @"C:/"; //打开的初始位置 pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //设置图片显示的大小 if (openFileDialog1.ShowDialog() == DialogResult.OK) { this.textBox1.Text = openFileDialog1.FileName; string[] strA = this.textBox1.Text.Split('.'); Bitmap bm = new Bitmap(this.textBox1.Text); //只选择bmp格式的图片 if (strA[1] != "bmp") { //filePath = strA[0] + ".bmp"; //bm.Save(filePath); MessageBox.show("not bmp"); this.button2.enabled = false; } else { filePath = this.textBox1.Text; this.pictureBox1.Image = bm; } } } //设置桌面,其实只用一句话 private void button2_Click(object sender, EventArgs e) { int nResult; if (File.Exists(filePath)) { nResult = SystemParametersInfo(20, 1, filePath, 0x1 | 0x2); if (nResult == 0) { MessageBox.Show("picture is not changed"); } else { MessageBox.Show("picture has been changed"); } } else { MessageBox.Show("pic is not existed"); } }
个人觉得挺不错,所以拿来试试,结果还不错
相关文章推荐
- 谨慎使用Date 和 Time 类 转载自:http://www.wangchao.net.cn/bbsdetail_1478942.html
- Java Servlet 和 JSP教程(1)(http://www.wangchao.net.cn/bbsdetail_547177.html)
- SQL Server使用Bulk Insert把一个文本导入到数据库--http://www.wangchao.net.cn/it/detail_59013.html
- 重学C++(2)——指向类成员的指针(转自:http://www.wangchao.net.cn/bbsdetail_73812.html)
- asp.net(C#)调用C++程序并交互操作【转】http://www.cnblogs.com/greatverve/archive/2010/06/07/Csharp-transfer-Cpp.html
- 转:自动更新程序源码下载(C#.Net) http://www.cnblogs.com/jenry/archive/2006/08/15/477302.html
- ubuntu 自添加开机启动程序(一种使ethtool设置永久保存在网络设备中的曲线救国方法) 转自:http://www.groad.net/bbs/read.php?tid-1393.html
- 使用Modernizr 检测HTML5和CSS3浏览器支持功能 (转自http://www.adobe.com/cn/devnet/dreamweaver/articles/using-modernizr.html)
- XDocReport 的简单使用 操作word 替换变量,动态图片,指定操作指令(程序)扩展(转自:http://www.cnblogs.com/fish-in-sky/p/4973237.html)
- asp.net中使用窗体身份验证 [转]来源:小灰http://www.svnhost.cn/Article/Detail-23.shtml
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- ASP.NET 缓存(五)--使用文件依赖项缓存页输出http://www.opent.cn/?action=show&id=192
- NOKIA各机型相对应操作系统平台及屏幕参数http://www.nokiacn.net/thread-213829-1-1.html
- http://bbs.itcast.cn/thread-15273-1-1.html?from=gkk
- 使用eclipse生成javadoc(转自:http://www.blogjava.net/soddabao/archive/2007/04/09/109434.html)
- 二、nodejs图片处理(gm) api: https://www.npmjs.com/package/gm 及 MD5加密:http://nodejs.cn/doc/node/crypto.html#crypto_crypto_createhash_algorithm
- js 调用C#.NET后台方法 转载自:http://www.cnblogs.com/lizhao/archive/2010/11/23/1990436.html
- setInterval和setTimeout的使用区别(转自 <a href="http://www.cnblogs.com/sk-net/archive/2008/01/24/1050770.html">http://www.cnblogs.com/sk-net/archive/2008/01/24/1050770.html</a>)
- 使用::std::vector作为管理动态数组的优先选择 作者原文出处:http://www.cpphelp.net/issue/vector.html