zoukankan      html  css  js  c++  java
  • 小创意之-C#设置电脑壁纸

    小创意— 设置电脑壁纸

    看着面黄肌肉的电脑壁纸,默默打卡了百度,搜索美丽的壁纸。看着风格古怪,分辨率里五五六六的图片。默默的流了几滴汗。于是单生了一个念头,为什么不抓去合适的图片自动设置成电脑壁纸呢?于是便用C#写了一个小程序。

    寻找合适的代码图片下载到本地

    提供几个常见的图片网址

    https://unsplash.it/1600/900?random(国外的随机图片)

    https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture(必应每日图片)

    https://uploadbeta.com/api/pictures/random(随机图片)

    通过C#下载图片和预览图片

    
                 // 图片下载下来 保存到本地
                string url = "https://uploadbeta.com/api/pictures/random/";
                 System.Net.WebClient mywebclient = new System.Net.WebClient();
                 mywebclient.DownloadFile(url, filePath);
                // this.pictureBox1.Load(filePath);
                // 把图片预览在C#的 pictureBox控件
                FileStream pFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                pictureBox1.Image = Image.FromStream(pFileStream);
                pFileStream.Close();
                pFileStream.Dispose();
    

    调用win的库 设置为壁纸

     /// <summary>
            ///  图片设置为背景图片
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button2_Click(object sender, EventArgs e)
            {       
                MessageBox.Show(filePath);
                SystemParametersInfo(20,1,filePath,1);
            }
    
            [DllImport("user32.dll",EntryPoint= "SystemParametersInfo")]
            public static extern int SystemParametersInfo(
                int uAction,
                int uParam,
                string lpvParam,
                int fuWinIni
                );
        }
    

    最后样式

    窗体设置样式

    image-20200514225248365

    运行效果

    image-20200514225305663 image-20200514225440199

    具体的代码在github连接里面

  • 相关阅读:
    JS数组去重
    正则表达式验证邮箱手机号等
    js中的事件委托
    c++刷题(6/100)最长上升子序列
    c++刷题(3/100)数独,栈和队列
    在express中HMR(合并express和webpack-dev-server)
    面试整理(3)js事件委托
    面试整理(2)跨域:jsonp与CORS
    面试整理(1):原生ajax
    styled-components真的好吗?
  • 原文地址:https://www.cnblogs.com/fangyuandoit/p/13713777.html
Copyright © 2011-2022 走看看