本文介绍了如何更改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.

它有一个名为 Lock的按钮'
,因此,如果用户选择一个单选按钮,然后按该按钮,则应用程序应先更改锁定屏幕图像,然后再锁定屏幕。

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.

我后来在Google上搜索,关于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应用程序来使用 LockScreen 类由 windows.userProfile.dll 提供,该事件已更改为:

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)
            {
            }
        }

,您可以在锁定按钮单击事件中看到对Web服务器的请求,导致您无法直接将屏幕锁定在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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:42