void ToEscapeChars() { var txt = RequestDocument["txt"].ToString(); try { var jsonStringData = RichTextBoxHelper.CompressJsonString(txt); //因为引号使用了反斜杠\ , 所以先操作反斜杠\ 再操作引号 // 如果先操作引号的话, 那引号转义后产生的反斜杠\再转义将会产生更多的反斜杠\ string str = jsonStringData.Replace("\\", "\\\\").Replace("\"", "\\\""); //rpc调用(包括网站) var jd = new JsonData() { ["txt"] = string.Empty }; if (!string.IsNullOrEmpty(str)) { jd["txt"] = str; } Json((int)ReturnStatus_Ext.Success, string.Empty, jd); } catch (Exception exception) { Json((int)ReturnStatus_Ext.ServerError, exception.Message); } }
public void Query(DatabaseObjectDisplayInfo displayInfo) { this.ucSqlQuery.Editor.AppendText(displayInfo.Content); RichTextBoxHelper.Highlighting(this.ucSqlQuery.Editor, displayInfo.DatabaseType, false); this.ucSqlQuery.RunScripts(displayInfo); }
private readonly RichTextBoxHelper logHelper; // provides access to log /// <summary> /// Initializes a new instance of the class. /// </summary> public ConfigBuilder(IAdminContext adminContext, ScadaProject project, RichTextBoxHelper logHelper) { this.adminContext = adminContext ?? throw new ArgumentNullException(nameof(adminContext)); this.project = project ?? throw new ArgumentNullException(nameof(project)); this.logHelper = logHelper ?? throw new ArgumentNullException(nameof(logHelper)); BuildResult = false; DeviceConfigs = new List <DeviceConfigEntry>(); }
private void txtEditor_SelectionChanged(object sender, EventArgs e) { this.txtEditor.SelectionFont = this.txtEditor.Font; if (this.isPasting) { this.isPasting = false; RichTextBoxHelper.Highlighting(this.txtEditor, this.DatabaseType); } }
private void ShowScripts(RichTextBox textBox, string scripts) { textBox.Clear(); if (!string.IsNullOrEmpty(scripts)) { textBox.AppendText(scripts.Trim()); RichTextBoxHelper.Highlighting(textBox, this.targetDbProfile.DatabaseType, false); } }
private void SetTabPageContent(DatabaseObjectDisplayInfo info, TabPage tabPage) { if (info.DisplayType == DatabaseObjectDisplayType.Script) { UC_SqlQuery sqlQuery = this.GetUcControl <UC_SqlQuery>(tabPage); if (sqlQuery == null) { sqlQuery = this.AddControlToTabPage <UC_SqlQuery>(tabPage); } sqlQuery.Show(info); if (!string.IsNullOrEmpty(sqlQuery.Editor.Text)) { RichTextBoxHelper.Highlighting(sqlQuery.Editor, info.DatabaseType, false); if (info.Error != null) { RichTextBoxHelper.HighlightingError(sqlQuery.Editor, info.Error); } } else { sqlQuery.Editor.Focus(); } } else if (info.DisplayType == DatabaseObjectDisplayType.Data) { UC_DataViewer dataViewer = this.GetUcControl <UC_DataViewer>(tabPage); if (dataViewer == null) { dataViewer = this.AddControlToTabPage <UC_DataViewer>(tabPage); dataViewer.OnDataFilter += this.DataFilter; } dataViewer.Show(info); } else if (info.DisplayType == DatabaseObjectDisplayType.TableDesigner) { UC_TableDesigner tableDesigner = this.GetUcControl <UC_TableDesigner>(tabPage); if (tableDesigner == null) { tableDesigner = this.AddControlToTabPage <UC_TableDesigner>(tabPage); tableDesigner.OnFeedback += this.Feedback; } tableDesigner.Show(info); } }
private bool stopReading; // indicates that a read operation should stop /// <summary> /// Initializes a new instance of the class. /// </summary> public TopicReader(MqttConnectionOptions mqttConnectionOptions, RichTextBoxHelper logHelper) { connOptions = mqttConnectionOptions ?? throw new ArgumentNullException(nameof(mqttConnectionOptions)); this.logHelper = logHelper ?? throw new ArgumentNullException(nameof(logHelper)); mqttLock = new object(); tokenSource = null; messageDT = DateTime.MinValue; stopReading = false; ReadResult = false; WirenBoardModel = new WirenBoardModel(); }
private void btnCompressEscapeChars_Click(object sender, EventArgs e) { try { var jsonStringData = RichTextBoxHelper.CompressJsonString(textBox.Text); //因为引号使用了反斜杠\ , 所以先操作反斜杠\ 再操作引号 // 如果先操作引号的话, 那引号转义后产生的反斜杠\再转义将会产生更多的反斜杠\ string str = jsonStringData.Replace("\\", "\\\\").Replace("\"", "\\\""); textBox.Text = str; btnCompressEscapeChars.Visible = false; } catch (Exception exception) { this.ShowException(exception); } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmWirenBoardWizard(IAdminContext adminContext, ScadaProject project, RecentSelection recentSelection) : this() { this.adminContext = adminContext ?? throw new ArgumentNullException(nameof(adminContext)); this.project = project ?? throw new ArgumentNullException(nameof(project)); ctrlLineSelect = new CtrlLineSelect(adminContext, project, recentSelection); ctrlLog = new CtrlLog(); ctrlDeviceTree = new CtrlDeviceTree(); ctrlEntityID = new CtrlEntityID(adminContext, project, recentSelection); logHelper = new RichTextBoxHelper(ctrlLog.RichTextBox); AddUserControls(); step = Step.SelectLine; topicReader = null; configBuilder = null; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmTransfer(AppData appData, ScadaProject project, ProjectInstance instance, DeploymentProfile profile) : this() { this.appData = appData ?? throw new ArgumentNullException(nameof(appData)); this.project = project ?? throw new ArgumentNullException(nameof(project)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); this.profile = profile ?? throw new ArgumentNullException(nameof(profile)); setCancelEnabledAction = b => SetCancelEnabled(b); setProgressAction = d => SetProgress(d); setResultAction = (b, d) => SetResult(b, d); logHelper = new RichTextBoxHelper(txtLog); extensionLogic = null; uploadMode = false; operationResult = false; tokenSource = null; }
private async void LoadArticleContent(LoadedArticle item) { grLoading.Visibility = Visibility.Visible; grMain.IsEnabled = false; SelectedArticle = item; SetDirection(Trend.Unknown); SetWeight(int.MinValue); rtbArticleContent.Document = RichTextBoxHelper.LoadText(item.Content); var needFindMatch = cbCheckAutomatically.IsChecked.HasValue && cbCheckAutomatically.IsChecked.Value; Pattern pattern = null; if (needFindMatch) { ctrAnimation.AnimationText = "Searching for patterns ..."; await Task.Run(() => { pattern = FindMatch(); }); } if (pattern != null) { HighlightMatch(pattern.Regex, pattern.Trend); tbRegexPattern.Text = pattern.RawRegexText; SetDirection(pattern.Trend); SetWeight(pattern.Weight); } if (cbFindMarket.IsChecked.Value) { HighlightMatch(new Regex(BeforeOpeningPatternsKeeper.Market), Colors.Blue, true); } if (cbFindExpect.IsChecked.Value) { HighlightMatch(new Regex(BeforeOpeningPatternsKeeper.Expect), Colors.DarkOrange, true); } grLoading.Visibility = Visibility.Hidden; grMain.IsEnabled = true; }
private void BtnCheck_OnClick(object sender, RoutedEventArgs e) { try { if (Validate() == false) { return; } rtbText.Document = RichTextBoxHelper.CleanAndReformat(rtbText.Document); var regex = tbGeneratedPattern.Text; var ranges = RichTextBoxMatchFinder.FindMatches(rtbText.Document, new Regex(regex, RegexOptions.Singleline | RegexOptions.IgnoreCase)); RichTextBoxMatchFinder.HighlightMatches(ranges, Colors.Red, FontWeights.Bold); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 改变richTextBox中指定字符串的颜色 /// 调用即可 /// </summary> /// <param name="str" value="为指定的字符串"></param> public int changeColor(string[] str) { ArrayList list = null; int b = 0; for (int i = 0; i < str.Length; i++) { list = RichTextBoxHelper.getIndexArray(richTextBox1.Text.ToLower(), str[i]); b += list.Count; } for (int i = 0; i < str.Length; i++) { list = RichTextBoxHelper.getIndexArray(richTextBox1.Text.ToLower(), str[i]); if (list.Count == 0) { continue; } if (a == b) { richTextBox1.SelectionColor = Color.Empty; return(b); } for (int j = 0; j < list.Count; j++) { int index = (int)list[j]; richTextBox1.Select(index, str[i].Length); richTextBox1.SelectionColor = Color.Blue; this.richTextBox1.Focus(); //设置光标的位置到文本尾 this.richTextBox1.Select(this.richTextBox1.TextLength, 0); //滚动到控件光标处 this.richTextBox1.ScrollToCaret(); richTextBox1.SelectionColor = Color.Empty; } } return(b); }
public static void ScrollLines(this RichTextBox richTextBox, int linesToScroll) { RichTextBoxHelper.ScrollLines(richTextBox, linesToScroll); }
public static void HideSelection(this RichTextBox richTextBox, bool hide) { RichTextBoxHelper.HideSelection(richTextBox, hide); }
public static int GetVisibleLines(this RichTextBox richTextBox) { return(RichTextBoxHelper.GetVisibleLines(richTextBox)); }
public static int GetLastVisibleCharIndex(this RichTextBox richTextBox) { return(RichTextBoxHelper.GetLastVisibleCharIndex(richTextBox)); }
public static void SetRedraw(this RichTextBox richTextBox, bool enableRedraw) { RichTextBoxHelper.SetRedraw(richTextBox, enableRedraw); }
/// <summary> /// Sets the font name for the selected text of the RichTextBox /// </summary> /// <param name="fontName">Name of the font to use</param> /// <returns>Returns true on success, false on failure</returns> public static bool SelectionFontName(this RichTextBox richTextBox, string fontName) { return(RichTextBoxHelper.SelectionFontName(richTextBox, fontName)); }
public static int GetEventMask(this RichTextBox richTextBox) { return(RichTextBoxHelper.GetEventMask(richTextBox)); }
public static int GetHScroll(this RichTextBox richTextBox) { return(RichTextBoxHelper.GetHScroll(richTextBox)); }
private void BtnReset_OnClick(object sender, RoutedEventArgs e) { rtbText.Document = RichTextBoxHelper.CleanAndReformat(rtbText.Document); }
void ToJson() { var txt = RequestDocument["txt"].ToString(); txt = RemoveEscapeChars(txt); var strList = new List <string>(); try { var lines = txt.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (lines.All(t => t.Contains(":"))) { foreach (var item in lines) { var keyValues = item.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (keyValues.Length == 2) { var key = keyValues[0].Trim(); var value = keyValues[1].Trim(); value = System.Web.HttpUtility.UrlDecode(value); value = value.Replace("\"", "\\\""); if (!string.IsNullOrEmpty(key)) { if (value == "true" || value == "false" || IsNum(value)) { strList.Add($"\"{key}\":{value},"); } else { strList.Add($"\"{key}\":\"{value}\","); } } } } } else { var items = txt.Split(new[] { "&" }, StringSplitOptions.RemoveEmptyEntries); if (items.All(t => t.Contains("="))) { foreach (var item in items) { var keyValues = item.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (keyValues.Length == 2) { var key = keyValues[0].Trim(); var value = keyValues[1].Trim(); value = System.Web.HttpUtility.UrlDecode(value); value = value.Replace("\"", "\\\""); if (!string.IsNullOrEmpty(key)) { if (value == "true" || value == "false" || IsNum(value)) { strList.Add($"\"{key}\":{value},"); } else { strList.Add($"\"{key}\":\"{value}\","); } } } } } } } catch (Exception ex) { } //rpc调用(包括网站) var jd = new JsonData() { ["txt"] = string.Empty }; if (strList.Count > 0) { var stringBuilder = new StringBuilder(); stringBuilder.Append("{"); strList[strList.Count - 1] = strList.Last().TrimEnd(','); foreach (var str in strList) { stringBuilder.Append(str); } stringBuilder.Append("}"); jd["txt"] = RichTextBoxHelper.FormatJsonString(stringBuilder.ToString()); } else if (JsonSerializerHelper.IsJsonString(txt)) { jd["txt"] = RichTextBoxHelper.FormatJsonString(txt); } else { jd["txt"] = string.Empty; } Json((int)ReturnStatus_Ext.Success, string.Empty, jd); }
private void ExportHelper(IWorksheet Sheet, GridModel gridModel, GridStyleInfo Style, RowColumnIndex RowColIndex) { if (Sheet != null) { int ivalue; double dvalue; bool bvalue; try { IRange range = Sheet.Range[RowColIndex.RowIndex, RowColIndex.ColumnIndex]; if (!range.HasFormula || Style.Text.Length == 0 || (Style.Text.Length > 0 && Style.Text[0] != '=')) { //To new Save Formula if (Style.CellValue != null && Style.CellValue.ToString() != string.Empty && Style.CellValue.ToString()[0] == '=') { if (Style.CellValue.ToString().Contains('!')) { range.Formula = ExcelLikeFormula(gridModel, Style.CellValue.ToString()); } else { range.Formula = Style.CellValue.ToString().ToUpper(); } if (int.TryParse(Style.FormattedText, out ivalue)) { Style.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; range.CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; } else if (double.TryParse(Style.FormattedText, out dvalue)) { Style.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; range.CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight; } } else { string cellvalue = string.Empty; if (Style.CellValue != null) { cellvalue = Style.CellValue.ToString(); } if (Style.CellType == "FormulaCell" && !string.IsNullOrEmpty(Style.Text) && Style.Text[0] == '=') { cellvalue = Style.FormattedText; } //To Save RichText else if (Style.CellType == "RichText") { RichTextBoxHelper.SetRichTextValue(range, Style.CellValue as FlowDocument, Style.FormattedText); return; } //To Save Number if (int.TryParse(cellvalue, out ivalue)) { range.Number = ivalue; } else if (double.TryParse(cellvalue, out dvalue)) { range.Number = dvalue; } //To Save Boolean value else if (bool.TryParse(cellvalue, out bvalue)) { range.Boolean = bvalue; if (bvalue) { Style.CellValue = "TRUE"; } else { Style.CellValue = "FALSE"; } } //To Save other value else { range.Value = cellvalue; } } } //To Save Formula else { if (Style.FormulaTag != null && Style.CellValue != null && Style.CellValue.ToString() != string.Empty && Style.CellValue.ToString()[0] == '=') { if (!range.HasFormula) { if (Style.CellValue.ToString().Contains('!')) { range.Formula = ExcelLikeFormula(gridModel, Style.CellValue.ToString()); } else { range.Formula = Style.CellValue.ToString().ToUpper(); } } else { range.Formula = ExcelLikeFormula(gridModel, Style.CellValue.ToString()); } } else if (!range.HasFormula) { range.Text = Style.FormattedText; } } } catch (Exception) { } } }
public static void SetHScroll(this RichTextBox richTextBox, int position) { RichTextBoxHelper.SetHScroll(richTextBox, position); }
/// <summary> /// Sets the font style for the selected text of the RichTextBox /// </summary> /// <param name="fontStyle">Font style to apply to selected text</param> /// <returns>Returns true on success, false on failure</returns> public static bool SelectionFontStyle(this RichTextBox richTextBox, FontStyle fontStyle) { return(RichTextBoxHelper.SelectionFontStyle(richTextBox, fontStyle)); }
public static void SetEventMask(this RichTextBox richTextBox, int mask) { RichTextBoxHelper.SetEventMask(richTextBox, mask); }
/// <summary> /// Sets the font color for the word in the selected point /// </summary> /// <param name="color">Color to apply</param> /// <returns>Returns true on success, false on failure</returns> public static bool WordFontColor(this RichTextBox richTextBox, Color color) { return(RichTextBoxHelper.WordFontColor(richTextBox, color)); }
/// <summary> /// Sets the font size for the selected text of the RichTextBox /// </summary> /// <param name="fontSize">Font size to use</param> /// <returns>Returns true on success, false on failure</returns> public static bool SelectionFontSize(this RichTextBox richTextBox, int fontSize) { return(RichTextBoxHelper.SelectionFontSize(richTextBox, fontSize)); }
/// <summary> /// Sets the background color for the selected text of the RichTextBox /// </summary> /// <param name="color">Color to apply</param> /// <returns>Returns true on success, false on failure</returns> public static bool SelectionBackColor(this RichTextBox richTextBox, Color color) { return(RichTextBoxHelper.SelectionBackColor(richTextBox, color)); }