在C#中更改桌面背景 [英] Change desktop background in C#

查看:114
本文介绍了在C#中更改桌面背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用C#。例改变背景:

I try to change the background using C#.Example:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32
    uiParam, String pvParam, UInt32 fWinIni);
    private static UInt32 SPI_SETDESKWALLPAPER = 20;
    private static UInt32 SPIF_UPDATEINIFILE = 0x1;



然后

And then

  SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, @"C:\background.bmp", SPIF_UPDATEINIFILE);
                            }



但它不工作...帮助?

But it doesn't work...Help?

推荐答案

pvParam 应该是一个本地文件。它不会对网址的工作......

pvParam should be a local file. It will not work for urls...

首先下载的图像,然后给 SystemParametersInfo 本地路径法

First download the image, then give its local path to SystemParametersInfo method.

var filename = "4.jpg";
new WebClient().DownloadFile("http://www.scottgames.com/4.jpg", filename);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, filename, SPIF_UPDATEINIFILE);

这篇关于在C#中更改桌面背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆