我在获取用户选择的颜色并将其保存到数据库中遇到麻烦,以便当他们重新加载程序时,它将自动应用于标签背景
让用户选择颜色
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If ColorDialog1.ShowDialog = DialogResult.OK Then
Quiz.LTitle.BackColor = ColorDialog1.Color
End If
End Sub
然后我有一个按钮来保存它的代码到目前为止
Private Sub BTitleSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTitleSave.Click
BackGroundWork.Title_SettingsBindingSource.AddNew()
BackGroundWork.Title_BColorTextBox.Text = Quiz.LTitle.BackColor.ToArgb
BackGroundWork.Title_SettingsBindingSource.EndEdit()
BackGroundWork.Title_SettingsTableAdapter.Update(BackGroundWork.QuizSettingsDataSet)
End Sub
back地基是一个形式,我有我所有的数据库运行测验是每个人都会看到的形式。
如有任何帮助,不胜感激
你可以试试ColorInHex…
Private Sub BTitleSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTitleSave.Click
BackGroundWork.Title_SettingsBindingSource.AddNew()
BackGroundWork.Title_BColorTextBox.Text = Quiz.LTitle.BackColor.ToArgb.ToString("X")
BackGroundWork.Title_SettingsBindingSource.EndEdit()
BackGroundWork.Title_SettingsTableAdapter.Update(BackGroundWork.QuizSettingsDataSet)
End Sub
当你叫它…
Dim sColor as String = ... -> this retrieve from database
Quiz.LTitle.BackColor = System.Drawing.ColorTranslator.FromHtml(sColor)