//输入HTML颜色代码的点击ok按钮事件 public void BtnOkClickForInputHTMLCode(FormInputBox frm) { string text = frm.txtInput.Text; try { //考虑到用户懒惰行为:不输入#,不带#的纯数字解析值不同 text = "#" + text; ColorTranslator.FromHtml(text); } catch (Exception) { try { text = frm.txtInput.Text; ColorTranslator.FromHtml(text); } catch (Exception) { MessageBox.Show("请输入正确的HTML颜色代码", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (text == string.Empty) { MessageBox.Show("不能为空", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { picColorView.BackColor = ColorTranslator.FromHtml(text); frm.Dispose(); } }
//修改磁贴名称的点击ok按钮事件 public void BtnOkClickForRePlaceName(FormInputBox frm) { string text = frm.txtInput.Text; string[] errorStrs = { "\\", "/", ":", "*", "\"", "<", ">", "|" }; string allErrorStr = null; foreach (var str in errorStrs) { allErrorStr += (str + " "); } foreach (var str in errorStrs) { if (text.Contains(str)) { MessageBox.Show("请勿输入以下文件名中不支持的字符\n" + allErrorStr, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (text == string.Empty) { MessageBox.Show("不能为空", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } txtNameView.Text = text; frm.Dispose(); }
//输入url链接 private void InputUrl() { var action1 = new Action <FormInputBox>(FormLoadForInputUrl); var action2 = new Action <FormInputBox>(BtnOkClickForInputUrl); var frm = new FormInputBox(action1, action2); frm.ShowDialog(); if (urlPath == null) { cmbCommand.SelectedIndex = 0; } else { txtPathView.Text = urlPath; if (File.Exists(myUrlIniPath)) { File.Delete(myUrlIniPath); } File.WriteAllText(myUrlIniPath, urlPath, Encoding.Default); txtNameView.Text = "我的网址"; myExePath = myUrlExePath; btnSaveStyle.Enabled = true; if (picEditedView.Image != null) { cmbTileShowMode.Enabled = true; } picColorView.BackColor = ThemeColor.GetThemeColor(); iconIndex = 0; iconPath = DefaultWebBroeser.DefaultWebBrowserFilePath(); Icon icon = Icon.ExtractAssociatedIcon(iconPath); picIconView.Image = icon.ToBitmap(); ShowPic(myExePath); } }
//输入HTML颜色代码的点击ok按钮事件 private void BtnOkClickForInputHTMLCode(FormInputBox frm) { string text = frm.txtInput.Text; try { //考虑到用户懒惰行为:不输入#,不带#的纯数字解析值不同 text = "#" + text; ColorTranslator.FromHtml(text); } catch (Exception) { try { text = frm.txtInput.Text; ColorTranslator.FromHtml(text); } catch (Exception) { new FormMyMessageBox("请输入正确的HTML颜色代码").Show(); return; } } picColorView.BackColor = ColorTranslator.FromHtml(text); frm.Dispose(); }
//修改磁贴名称 private void ReplaceName(object sender, EventArgs e) { var action1 = new Action <FormInputBox>(FormLoadForRePlaceName); var action2 = new Action <FormInputBox>(BtnOkClickForRePlaceName); var frm = new FormInputBox(action1, action2); frm.ShowDialog(); }
//输入HTML颜色代码 private void InputColorCode(object sender, EventArgs e) { var action1 = new Action <FormInputBox>(FormLoadForInputHTMLCode); var action2 = new Action <FormInputBox>(BtnOkClickForInputHTMLCode); var frm = new FormInputBox(action1, action2); frm.ShowDialog(); }
//输入url链接点击ok按钮事件 private void BtnOkClickForInputUrl(FormInputBox frm) { string text = frm.txtInput.Text; if (text == string.Empty) { MessageBox.Show("不能为空", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { urlPath = text; frm.Dispose(); } }
//输入url链接 private void InputUrl() { var action1 = new Action <FormInputBox>(FormLoadForInputUrl); var action2 = new Action <FormInputBox>(BtnOkClickForInputUrl); var frm = new FormInputBox(action1, action2); frm.ShowDialog(); if (urlPath == null) { cmbCommand.SelectedIndex = 0; } else { txtPathView.Text = urlPath; if (File.Exists(myUrlIniPath)) { File.Delete(myUrlIniPath); } File.WriteAllText(myUrlIniPath, urlPath, Encoding.Default); txtNameView.Text = "我的网址"; myExePath = myUrlExePath; btnSaveStyle.Enabled = true; if (picEditedView.Image != null) { cmbTileShowMode.Enabled = true; } picColorView.BackColor = ThemeColor.GetThemeColor(); iconIndex = 0; //创建一个Internet快捷方式文件,获取默认浏览器图标 iconPath = urlFolder + "\\" + MyName + ".url"; StreamWriter sw = File.CreateText(iconPath); sw.WriteLine("[InternetShortcut]"); sw.WriteLine("URL=" + gitHubUrl); sw.Close(); Icon icon = Icon.ExtractAssociatedIcon(iconPath); picIconView.Image = icon.ToBitmap(); ShowPic(myExePath); } }
//修改磁贴名称的点击ok按钮事件 private void BtnOkClickForRePlaceName(FormInputBox frm) { string text = frm.txtInput.Text; string[] errorStrs = { "\\", "/", ":", "*", "\"", "<", ">", "|" }; string allErrorStr = null; foreach (var str in errorStrs) { allErrorStr += (str + " "); } foreach (var str in errorStrs) { if (text.Contains(str)) { new FormMyMessageBox("请勿输入以下文件名中不支持的字符\n" + allErrorStr).Show(); return; } } txtNameView.Text = text; frm.Dispose(); }
//修改磁贴名称的输入框窗体初始化 public void FormLoadForRePlaceName(FormInputBox frm) { frm.Icon = this.Icon; frm.Text = "请输入新名称"; frm.txtInput.Text = txtNameView.Text; }
//输入HTML颜色代码的输入框窗体初始化 public void FormLoadForInputHTMLCode(FormInputBox frm) { frm.Icon = this.Icon; frm.Text = "请输入HTML颜色代码"; frm.txtInput.Text = txtCodeView.Text; }
//输入url链接输入框窗体初始化 private void FormLoadForInputUrl(FormInputBox frm) { frm.Text = "请输入URL地址或文件夹路径"; frm.txtInput.Text = txtPathView.Text; frm.Icon = this.Icon; }
//输入url链接点击ok按钮事件 private void BtnOkClickForInputUrl(FormInputBox frm) { urlPath = frm.txtInput.Text; frm.Dispose(); }