两个方法,引入之后直接调用即可。
public class Win32Helper
{
[DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]
internal static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, string lpvparam, Int32 fuwinIni);
}存储的方法
void SetWallpaper(string imgPath)
{
int nResult;
nResult = Win32Helper.SystemParametersInfo(20, 1, imgPath, 0x1 | 0x2);
}验证过,可用。