如何更改 LockScreen 背景(找到 windows.system.UserProfile.dll)? [英] How to Change the LockScreen back ground (find windows.system.UserProfile.dll)?

查看:17
本文介绍了如何更改 LockScreen 背景(找到 windows.system.UserProfile.dll)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启动了一个 windows 窗体应用程序,它从文件中导入图像并存储它们,并为每个图像指定一个单选按钮.

I started a windows form application which imports images from files and store them and specify a radio button to each one.

它有一个名为锁定"的按钮所以如果用户选择一个单选按钮然后按下按钮,应用程序应该更改锁定屏幕图像,然后锁定屏幕.

it have a button with the name 'Lock' so if user select one radio button and then press the button the app should change the lock screen image and then Lock the screen.

但是我不知道如何设置图像和锁定屏幕.

But I don't know how to set the image and lock the screen.

我后来用谷歌搜索,关于 LockScreen.blabla 的答案对我不起作用,因为我不能使用 windows.system.userprofile;

I googled later and the answer about the LockScreen.blabla didn't work for me because I can't do using windows.system.userprofile;

如果有人给我集会,我会做这件事.

If some one get me the assembly i will do the thing.

有事件:

private void rB_CheckedChanged(object sender, EventArgs e)
        {
            MyRadioButton radioButton = sender as MyRadioButton;
            pictureBox1.Image = radioButton.Image;
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
                foreach (Control control in FindForm().Controls)
                {
                    if (control.GetType() == typeof(MyRadioButton))
                    {
                        MyRadioButton mrb = control as MyRadioButton;
                        if (mrb.Checked == true)
                        {
                            mrb.Image = pictureBox1.Image;
                        }
                    }
                }
            }
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            //should set the lock screen background

            LockScreen.LockScreen.SetImageFileAsync(imagefile);//shows error 'the name lock screen does not exist
        }

推荐答案

我已经制作了一个 UWP 应用程序来使用 windows.userProfile.dll 提供的 LockScreen 类和事件更改为:

I have made a UWP application to use the LockScreen class provided by windows.userProfile.dll And the event's changed to:


        private Dictionary<string, string> Images = new Dictionary<string, string>();
        private async void btnLock_Click(object sender, RoutedEventArgs e)
        {
            string path;
            if (Images.TryGetValue(selectedRadioButton.Name, out path))
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);
                await LockScreen.SetImageFileAsync(file);
                try
                {
                    HttpClient httpClient = new HttpClient();
                    Uri uri = new Uri("http://localhost:8080/lock/");

                    HttpStringContent content = new HttpStringContent(
                        "{ "pass": "theMorteza@1378App" }",
                        UnicodeEncoding.Utf8,
                        "application/json");

                    HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(
                        uri,
                        content);

                    httpResponseMessage.EnsureSuccessStatusCode();
                    var httpResponseBody = await httpResponseMessage.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

private async void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                using (var imageStream = await file.OpenReadAsync())
                {
                    var bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(imageStream);
                    image.Source = bitmapImage;
                }
                StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                await file.CopyAsync(storageFolder, selectedRadioButton.Name+file.FileType,NameCollisionOption.ReplaceExisting);
                addOrUpdate(selectedRadioButton.Name, Path.Combine(storageFolder.Path, selectedRadioButton.Name + file.FileType));
                save();
            }
        }
        private async void rb_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            selectedRadioButton = rb;
            btnBrowse.IsEnabled = true;
            string path;
            if (Images.TryGetValue(rb.Name, out path))
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);
                using (var imageStream = await file.OpenReadAsync())
                {
                    var bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(imageStream);
                    image.Source = bitmapImage;
                }
            }
        }
        private void addOrUpdate(string key, string image)
        {
            if (Images.Keys.Contains(key))
            {
                Images.Remove(key);
                Images.Add(key, image);
            }
            else
            {
                Images.Add(key, image);
            }
        }

        private async void save()
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile file = await storageFolder.CreateFileAsync("sample.txt", CreationCollisionOption.ReplaceExisting);
            await FileIO.WriteTextAsync(file, JsonConvert.SerializeObject(Images));
        }

        private async void load()
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile sampleFile = await storageFolder.GetFileAsync("sample.txt");
            string fileText = await FileIO.ReadTextAsync(sampleFile);
            try
            {
                Images = JsonConvert.DeserializeObject<Dictionary<string, string>>(fileText);
            }
            catch (Exception)
            {
            }
        }

并且您可以在锁定按钮单击事件中看到有一个对网络服务器的请求,因为您无法直接在 UWP 应用中锁定屏幕,您可以在我的下一个答案.

and you can see in the lock button click event there is a request to a web server cause you cannot directly lock the screen in a UWP app and you can follow the rest of your question in my next answer to the question "why I can't directly lock screen in UWP app?and how to do so?".

这篇关于如何更改 LockScreen 背景(找到 windows.system.UserProfile.dll)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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