/// <summary> /// 载入配置/或文件 /// </summary> public static void Load(this TextBox textBox, string path = null) { ConsoleUtil.Print("TextBox({0}).Load()", textBox.Name); string text; if (string.IsNullOrEmpty(path)) { text = CacheUtil.GetFromFile <string>(textBox.Name); } else { text = FileUtil.GetText(path); } if (!string.IsNullOrEmpty(text)) { /* * 此处赋值textBox.Text = text * 如果textBox.Text == text 不会触发TextChanged * 如果textBox.Text != text 会触发TextChanged * 但是textBox进行前端输入(包括粘贴,输入相同字符) 无论==、!=都会触发TextChanged */ textBox.Text = text; } }
/// <summary> /// 获取文件夹路径,末尾不带斜杠"\\" /// if void main() add[STAThread] /// </summary> public static string SelectFloder() { var dialog = new FolderBrowserDialog(); dialog.SelectedPath = CacheUtil.GetFromFile <string>("FolderBrowserDialog.SelectedPath"); dialog.ShowDialog(); CacheUtil.SaveWithFile("FolderBrowserDialog.SelectedPath", dialog.SelectedPath); return(dialog.SelectedPath); }
/// <summary> /// 载入配置/或文件 /// </summary> public static void Load(this TextBox textBox, string path = null) { ConsoleUtil.Print("TextBox({0}).Load()", textBox.Name); string text; if (string.IsNullOrEmpty(path)) { text = CacheUtil.GetFromFile <string>(textBox.Name); } else { text = FileUtil.GetText(path); } if (!string.IsNullOrEmpty(text)) { textBox.Text = text; } }
/// <summary> /// 载入配置 /// </summary> public static void Load(this CheckBox checkBox) => checkBox.IsChecked = CacheUtil.GetFromFile <bool>(checkBox.Name);