/// <summary> /// 显示序号 /// </summary> private void ShwoNumber() { System.Windows.Documents.List listx = new System.Windows.Documents.List(); listx.Margin = new Thickness() { Left = 3 }; // Set the space between the markers and list content to 25 DIP. listx.MarkerOffset = 5; // Use uppercase Roman numerals. listx.MarkerStyle = TextMarkerStyle.Decimal; // Start list numbering at 5. listx.StartIndex = 1; // Create the list items that will go into the list. System.Windows.Documents.ListItem liV = new System.Windows.Documents.ListItem(new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(""))); // Finally, add the list items to the list. listx.ListItems.Add(liV); if (RichTextBox1.Document.Blocks.Count == 2) { RichTextBox1.Document.Blocks.Remove(RichTextBox1.Document.Blocks.LastBlock); } RichTextBox1.Document.Blocks.Add(listx); RichTextBox1.Focus(); RichTextBox1.CaretPosition = this.RichTextBox1.Document.ContentEnd; }
private void cboFontFamilies_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cboFontFamilies.SelectedItem != null) { RichTextBox1.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, cboFontFamilies.SelectedItem); RichTextBox1.Focus(); e.Handled = true; } }
private void btnSetBulletList_Click(object sender, RoutedEventArgs e) { List list = GetList(); list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Box"); //获取当前选中的字体大小 Object obj = RichTextBox1.Selection.GetPropertyValue( FlowDocument.FontSizeProperty); //保证项目符号与文字大小一致 if (obj is double) list.FontSize = (double)obj; RichTextBox1.Focus(); }
private void listMarkerStyleChange(object sender, RoutedEventArgs e) { List list = GetList(); switch ((e.Source as MenuItem).Name) { case "mnuNone": case "mnuNone2": EditingCommands.ToggleBullets.Execute(null, RichTextBox1); break; case "mnuBox": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Box"); break; case "mnuSquare": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Square"); break; case "mnuDisc": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Disc"); break; case "mnuCircle": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Circle"); break; case "mnuDecimal": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Decimal"); break; case "mnuLowerLatin": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "LowerLatin"); break; case "mnuUpperLatin": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "UpperLatin"); break; case "mnuLowerRoman": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "LowerRoman"); break; case "mnuUpperRoman": list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "UpperRoman"); break; default: break; } //获取当前选中的字体大小 Object obj = RichTextBox1.Selection.GetPropertyValue( FlowDocument.FontSizeProperty); //保证项目符号与文字大小一致 if (obj is double) list.FontSize = (double)obj; RichTextBox1.Focus(); }
private void btnSetNumberList_Click(object sender, RoutedEventArgs e) { List list = rtfManager.FindListAncestor(this.RichTextBox1.Selection.Start.Parent); if (list == null) { EditingCommands.ToggleBullets.Execute(null, RichTextBox1); list = rtfManager.FindListAncestor(this.RichTextBox1.Selection.Start.Parent); } list.MarkerStyle = (TextMarkerStyle)Enum.Parse(typeof(TextMarkerStyle), "Decimal"); //获取当前选中的字体大小 Object obj = RichTextBox1.Selection.GetPropertyValue( FlowDocument.FontSizeProperty); //保证项目符号与文字大小一致 if (obj is double) list.FontSize = (double)obj; RichTextBox1.Focus(); }
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { try { string SelItem = null; int linN = 0; int colN = 0; SelItem = lstErrors.SelectedItem.ToString(); if (!string.IsNullOrEmpty(SelItem)) { linN = Convert.ToInt16(Regex.Replace(SelItem, "([0-9]+): ([0-9]+)(.*)", "$1")); colN = Convert.ToInt16(Regex.Replace(SelItem, "([0-9]+): ([0-9]+)(.*)", "$2")); MatchCollection mc = default(MatchCollection); int i = 0; int totc = 0; mc = Regex.Matches(RichTextBox1.Text, "\\n", RegexOptions.Singleline); try { RichTextBox1.Select(mc[linN - 2].Index + colN, 2); RichTextBox1.SelectionColor = Color.Blue; RichTextBox1.Focus(); } catch (Exception ex) { RichTextBox1.Focus(); } } } catch (Exception ex) { PepsiLiteErrorHandling.WriteErrorLog(ex.ToString()); } }
/// <summary> /// 窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window1_OnLoaded(object sender, RoutedEventArgs e) { if (File.Exists(CacheFileName)) { RichTextBoxTool.Read(RichTextBox1, CacheFileName); SetCaption(); } SkinM = new SkinManage().GetSkin(WindowSettings.BackColorName); //设置提醒 if (WindowSettings.RemindDateTime != null) { SetRemind((DateTime)WindowSettings.RemindDateTime); } //窗体效果设置 WindowsTool tool = new WindowsTool(this); tool.SetTopAutoShow(GridTitleBottom, GridTitle); tool.SetNotMax(GridTitle); tool.DragMove(GridTitle); RichTextBox1.Focus(); //Visibility = WindowSettings.NotepadState == NotepadState.Visible // ? Visibility.Visible // : Visibility.Collapsed; if (WindowSettings.Left != 0) { Left = WindowSettings.Left; } if (WindowSettings.Left != 0) { Top = WindowSettings.Top; } }
private void frmXMLViewer_Validation_Activated(object sender, EventArgs e) { RichTextBox1.Focus(); }
private void cmdFormatting_Click(object sender, RoutedEventArgs e) { // Ссылка на объект выделения TextSelection selection = RichTextBox1.Selection; // Если текст не найден, код интерпретирует // шрифт как обычный FontWeight weightState = FontWeights.Normal; FontStyle styleState = FontStyles.Normal; TextDecorationCollection currentState = null; if (e.OriginalSource == cmdBold) { // Проверка, выведен ли фрагмент полужирным цветом if (selection.GetPropertyValue(Run.FontWeightProperty) != DependencyProperty.UnsetValue) { weightState = (FontWeight)selection.GetPropertyValue( Run.FontWeightProperty); } if (weightState == FontWeights.Normal) { selection.ApplyPropertyValue(Run.FontWeightProperty, FontWeights.Bold); } else { selection.ApplyPropertyValue(Run.FontWeightProperty, FontWeights.Normal); } } if (e.OriginalSource == cmdItalic) { // Проверка, выведен ли фрагмент наклонным стилем if (selection.GetPropertyValue(Run.FontStyleProperty) != DependencyProperty.UnsetValue) { styleState = (FontStyle)selection.GetPropertyValue(Run.FontStyleProperty); } if (styleState == FontStyles.Italic) { selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Normal); } else { selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Italic); } } if (e.OriginalSource == cmdUnder) { // Проверка, выведен ли фрагмент с подчеркиванием if (selection.GetPropertyValue(Run.TextDecorationsProperty) != DependencyProperty.UnsetValue) { currentState = (TextDecorationCollection)selection.GetPropertyValue(Run.TextDecorationsProperty); } if (currentState != TextDecorations.Underline) { selection.ApplyPropertyValue(Run.TextDecorationsProperty, TextDecorations.Underline); } else { selection.ApplyPropertyValue(Run.TextDecorationsProperty, null); } } // Возврат фокуса полю, чтобы пользователь мог продолжить работу с ним RichTextBox1.Focus(); }