如何使用My.Settings.Save Visual Basic保存表单背景图像 [英] How to save a Forms Background Image using My.Settings.Save Visual Basic
问题描述
我正在尝试用Visual Basic(当然是基于程序)制作一个操作系统,并且需要个性化.
I'm trying to make an Operating System in Visual Basic (program based of course) and it needs personalisation.
我希望用户能够从存储在项目资源中的一组选定的图像中进行选择,并且希望保存该图像,以便下次用户登录该软件时使用该表单与他们选择保存的图像相同.
I want the user to be able to choose from a select group of images, stored in the Resources of the project, and I want that image to be saved, so that the next time they log on to the software, the form has the same image they selected saved.
其他信息:
图像选择是单独的形式.使用:
The image selection is on a seperate form. Using:
If ComboBox1.Text = "Beach Fade" Then
PictureBox1.BackgroundImage = My.Resources.beach_fade
End If
主桌面窗体使用背景图像"来选择图像.
Main Desktop form uses the "Background image" to have the image selected.
推荐答案
使用我的设置保留用户设置.
这是我用来演示的代码.我有一个带有ComboBox1和PictureBox1的表单.使用此代码,您可以继续选择图像.
This is the code I used to demo it. I have a form with ComboBox1 and PictureBox1. With this code, you can have your image selection persist.
进入您的项目属性,然后单击左侧的设置"选项.创建名为String的BackgroundImageName设置.您可以选择是按用户还是按应用程序保存范围.
Go into your project properties and click the Settings option on the left. Create a setting called BackgroundImageName of type String. You can choose if the scope is saved per-user or per-application.
然后在项目属性中转到资源",并添加两个名为"beach_fade"和"mountain_fade"的图像.你知道该怎么做
Then in project properties go to Resources and add two images named "beach_fade" and "mountain_fade". You know how to do this
然后粘贴此代码
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ComboBox1.Items.Add("Beach Fade")
Me.ComboBox1.Items.Add("Mountain Fade")
Me.ComboBox1.Text = My.Settings.BackgroundImageName
setBackgroundImage()
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
My.Settings.BackgroundImageName = Me.ComboBox1.Text
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
setBackgroundImage()
End Sub
Private Sub setBackgroundImage()
If ComboBox1.Text = "Beach Fade" Then
PictureBox1.BackgroundImage = My.Resources.beach_fade
ElseIf ComboBox1.Text = "Mountain Fade" Then
PictureBox1.BackgroundImage = My.Resources.mountain_fade
End If
End Sub
End Class
每次关闭前,应用程序都会使用ComboBox中选择的图像启动.
The application will start up every time with the image selected in the ComboBox before last close.
这篇关于如何使用My.Settings.Save Visual Basic保存表单背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!