我有一个按钮,可以打开窗口颜色托盘,然后将选择的颜色分配给某个虚拟工作室中的选定元素。用户首先通过鼠标单击选择元素,然后根据元素 ID 分配颜色。因此,每次单击按钮时,相同或不同元素的颜色都会发生变化。元素 ID 是从当鼠标单击某个元素时触发的委托获取的。颜色设置按钮的代码如下:
private void Btn_Choose_Color_Click(object sender, RoutedEventArgs e)
{
uint id_selected = (uint)selected_element; //get id of selected element from clickintocallback
//open windows color dialog
System.Windows.Forms.ColorDialog my_dialog = new System.Windows.Forms.ColorDialog();
my_dialog.ShowDialog();
//get the color from windows dialog
int red = my_dialog.Color.R;
int green = my_dialog.Color.G;
int blue = my_dialog.Color.B;
//create cinector color object and pass rgb values from windows dialog
ByteRGBColor desired_color = new ByteRGBColor((byte)red, (byte)green, (byte)blue); //assign color statically
for (int i = 0; i < all_color_elements_in_loaded_studio.Count; i++)
{
uint id_current = all_color_elements_in_loaded_studio.ElementAt(0).colorElementID; //get id of current element in a loop
if(id_current == id_selected) //compare selected and current element
{
//all_color_elements_in_loaded_studio.ElementAt(i).colorElementColor = test_color; //set the test color
instance.SetStudioColorElement(id_current, desired_color); //assign the color to the element
break;
}
}
//after we choose a color
Btn_Pick_Element_Clicked = false;
Btn_Choose_Color.IsEnabled = false;
}
现在,我的问题是一旦分配到用户设置中,如何保存元素 ID 及其颜色?我知道我可以转到“属性”->“设置”并在那里手动定义用户设置,但这里必须以某种方式以编程方式完成。然后,如何加载这些设置呢?
Set
Properties.Settings.Default.myColor = Color.AliceBlue;
Get
this.BackColor = Properties.Settings.Default.myColor;
Save
如果要在应用程序会话之间保留对用户设置的更改,请调用 Save 方法,如以下代码所示:
Properties.Settings.Default.Save();
参考 https://msdn.microsoft.com/en-us/library/aa730869.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)