private void OpenFileMenu() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Text Files (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf"; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { if (Path.GetExtension(openFileDialog.FileName) == ".txt") { MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText); } if (Path.GetExtension(openFileDialog.FileName) == ".rtf") { MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.RichText); } this.Text = Path.GetFileName(openFileDialog.FileName) + " - NotePad Application"; isFileAlreadySaved = true; isFileDirty = false; currentOpenFileName = openFileDialog.FileName; EnablrDisableUndoRedoProcess(false); MessageToolStripStatusLabel.Text = "File Is Opened"; } }
private void SaveAsFileMenue() { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Text Files (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf"; DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { if (Path.GetExtension(saveFileDialog.FileName) == ".txt") { MainRichTextBox.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.PlainText); } if (Path.GetExtension(saveFileDialog.FileName) == ".rtf") { MainRichTextBox.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.RichText); } this.Text = Path.GetFileName(saveFileDialog.FileName) + " - NotePad Application"; isFileAlreadySaved = true; isFileDirty = false; currentOpenFileName = saveFileDialog.FileName; } }
private void SaveFileMenu() { if (isFileAlreadySaved) { if (Path.GetExtension(currentOpenFileName) == ".txt") { MainRichTextBox.SaveFile(currentOpenFileName, RichTextBoxStreamType.PlainText); } if (Path.GetExtension(currentOpenFileName) == ".rtf") { MainRichTextBox.SaveFile(currentOpenFileName, RichTextBoxStreamType.RichText); } isFileDirty = false; } else { if (isFileDirty) { SaveAsFileMenue(); } else { ClearScreen(); } } }
private void RedoEditMenu() { MainRichTextBox.Redo(); UndoToolStripButton.Enabled = true; RedoToolStripButton.Enabled = false; redoToolStripMenuItem.Enabled = false; undoToolStripMenuItem.Enabled = true; }
private void MainRichTextBox_PreviewKeyDown(object sender, KeyEventArgs e) { OneChange = true; if (Keyboard.IsKeyDown(Key.Back)) { Back = true; } else { Back = false; } if (Keyboard.IsKeyDown(Key.Delete)) { Del = true; } else { Del = false; } if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && e.Key == Key.Tab) { string ss = new TextRange(MainRichTextBox.CaretPosition.GetLineStartPosition(0), MainRichTextBox.CaretPosition).Text; if (ss[ss.Length - 1] == '\t') { MainRichTextBox.CaretPosition = MainRichTextBox.CaretPosition.GetPositionAtOffset(-1, LogicalDirection.Backward); MainRichTextBox.CaretPosition.DeleteTextInRun(1); MainRichTextBox.CaretPosition = MainRichTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward); } Dispatcher.BeginInvoke( DispatcherPriority.ContextIdle, new Action(delegate() { MainRichTextBox.Focus(); })); e.Handled = true; return; } else if (e.Key == Key.Tab) { TextRange documentRange = new TextRange(MainRichTextBox.Document.ContentStart, MainRichTextBox.Document.ContentEnd); documentRange.ClearAllProperties(); MainRichTextBox.CaretPosition = MainRichTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward); MainRichTextBox.CaretPosition.InsertTextInRun("\t"); //string textRange = new TextRange(MainRichTextBox.Document.ContentStart, MainRichTextBox.Document.ContentEnd).Text; //MainRichTextBox.CaretPosition = MainRichTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward); //MainRichTextBox.CaretPosition.InsertTextInRun("\t"); //textRange = new TextRange(MainRichTextBox.Document.ContentStart, MainRichTextBox.Document.ContentEnd).Text; Dispatcher.BeginInvoke( DispatcherPriority.ContextIdle, new Action(delegate() { MainRichTextBox.Focus(); })); e.Handled = true; return; } }
private void ChatService_MessageReceived(object sender, MessageReceivedEventArgs e) { BeginInvoke(new Action(() => { MainRichTextBox.AppendText($"[{e.Timestamp.ToShortTimeString()} {_chatService.Name}]: {e.Content}\r\n", _otherColor); MainRichTextBox.ScrollToEnd(); })); }
public void MessageReceived(DateTime timestamp, string message) { BeginInvoke(new Action(() => { MainRichTextBox.AppendText($"[{timestamp.ToShortTimeString()} {_chatSettings.YourName}]: {message}\r\n", _otherColor); MainRichTextBox.ScrollToEnd(); })); }
private void RedoEditmenu() { MainRichTextBox.Redo(); redoToolStripMenuItem.Enabled = false; undoToolStripMenuItem.Enabled = true; toolStripButton11.Enabled = false; toolStripButton10.Enabled = true; undoToolStripMenuItem1.Enabled = true; redoToolStripMenuItem1.Enabled = false; }
private void SendText() { var line = MessageTextBox.Text; if (string.IsNullOrEmpty(line)) { return; } MainRichTextBox.AppendText($"[{DateTime.Now.ToShortTimeString()} Me]: {line}\r\n", _meColor); MainRichTextBox.ScrollToEnd(); MessageTextBox.Text = null; _chatService.ChatCallback.SendMessage(line); }
private void SendText() { var line = MessageTextBox.Text; if (string.IsNullOrEmpty(line)) { return; } MainRichTextBox.AppendText($"[{DateTime.Now.ToShortTimeString()} Me]: {line}\r\n", _meColor); MainRichTextBox.ScrollToEnd(); MessageTextBox.Text = null; SendMessage?.Invoke(this, new SendTextMessageEventArgs(line)); }
private void AppendMessage(ChatMessage chatMessage) { var foreground = chatMessage.IsFromMe ? _meBrush : _himBrush; var leftPart = $"[{chatMessage.Timestamp.ToLongTimeString()} {(chatMessage.IsFromMe ? (string) Application.Current.Resources["Me"] : (string) Application.Current.Resources["Client"])}]"; _currentParagraph.Inlines.Add( new Run( $"{leftPart}{new string(' ', _leftPartLength - leftPart.Length)}{chatMessage.Content}\r\n") { Foreground = foreground }); MainRichTextBox.ScrollToEnd(); }
private void BuildLoggerOnNewLogMessage(object sender, NewBuildLogMessageEventArgs newBuildLogMessageEventArgs) { Dispatcher.BeginInvoke( (MethodInvoker) delegate { Brush foreground; string prefix; switch (newBuildLogMessageEventArgs.BuildLogType) { case BuildLogType.Status: foreground = (Brush)Application.Current.Resources["BlackBrush"]; prefix = (string)Application.Current.Resources["Status"]; break; case BuildLogType.Warning: foreground = new SolidColorBrush(Color.FromArgb(255, 231, 76, 60)); prefix = (string)Application.Current.Resources["Warning"]; break; case BuildLogType.Error: foreground = new SolidColorBrush(Color.FromArgb(255, 192, 57, 43)); prefix = (string)Application.Current.Resources["Error"]; break; case BuildLogType.Success: foreground = new SolidColorBrush(Color.FromArgb(255, 39, 174, 96)); prefix = (string)Application.Current.Resources["Success"]; break; default: throw new ArgumentOutOfRangeException(); } _paragraph.Inlines.Add( new Run($"[{prefix.ToUpper()}] \t" + newBuildLogMessageEventArgs.Content + "\r\n") { Foreground = foreground }); MainRichTextBox.ScrollToEnd(); }); }
private void QuoteButton_Click(object sender, EventArgs e) //quoute { DocumentRange range = MainRichTextBox.Document.Selection; CharacterProperties crp = MainRichTextBox.Document.BeginUpdateCharacters(range); crp.FontName = crp.FontName; crp.FontSize = 12; crp.ForeColor = Color.Black; if (crp.Italic == false) { crp.Italic = true; } RichEditCommand paragraphAlignmentCenter = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleParagraphAlignmentCenter); paragraphAlignmentCenter.ForceExecute(paragraphAlignmentCenter.CreateDefaultCommandUIState()); MainRichTextBox.Document.EndUpdateCharacters(crp); }
private void Justify_Click(object sender, EventArgs e) //allign justify { RichEditCommand paragraphAlignmentJustify = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleParagraphAlignmentJustify); paragraphAlignmentJustify.ForceExecute(paragraphAlignmentJustify.CreateDefaultCommandUIState()); }
private void CUT_Click_1(object sender, EventArgs e)//cut button { MainRichTextBox.Cut(); }
public void NewToolStripMenuItem_Click(object sender, EventArgs e) { MainRichTextBox.Clear(); }
private void CopyToolStripMenuItem_Click(object sender, EventArgs e) { MainRichTextBox.Copy(); }
private void Number_Click(object sender, EventArgs e)//number list { RichEditCommand numberlist = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleNumberingListItem); numberlist.ForceExecute(numberlist.CreateDefaultCommandUIState()); }
private void Bullet_Click(object sender, EventArgs e) // bulleting numbers { RichEditCommand bulletCommand = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleBulletedListItem); bulletCommand.ForceExecute(bulletCommand.CreateDefaultCommandUIState()); }
private void Copy_Click_1(object sender, EventArgs e) //copy button { MainRichTextBox.Copy(); }
private void PASTE_Click_1(object sender, EventArgs e) //small paste button { MainRichTextBox.Paste(); }
private void redoToolStripMenuItem_Click(object sender, EventArgs e) { MainRichTextBox.Redo(); redoToolStripMenuItem.Enabled = true; undoToolStripMenuItem.Enabled = false; }
private void button15_Click_1(object sender, EventArgs e)//right indendetation scaling { RichEditCommand increaseIndent = MainRichTextBox.CreateCommand(RichEditCommandId.IncreaseIndent); increaseIndent.ForceExecute(increaseIndent.CreateDefaultCommandUIState()); }
private void button1_Click_2(object sender, EventArgs e) //big paste button { MainRichTextBox.Paste(); }
private void AppendToMainRichTextBox(string artist, string album) { MainRichTextBox.AppendText($"Artist:{artist}|Album:{album}\n"); }
private void button16_Click_1(object sender, EventArgs e)//left indendetation scaling { RichEditCommand decreaseIndent = MainRichTextBox.CreateCommand(RichEditCommandId.DecreaseIndent); decreaseIndent.ForceExecute(decreaseIndent.CreateDefaultCommandUIState()); }
private void PasteToolStripMenuItem_Click(object sender, EventArgs e) { MainRichTextBox.Paste(); }
private void RightAlign_Click(object sender, EventArgs e) //right allign { RichEditCommand paragraphAlignmentRight = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleParagraphAlignmentRight); paragraphAlignmentRight.ForceExecute(paragraphAlignmentRight.CreateDefaultCommandUIState()); }
private void SelectAllToolStripMenuItem_Click(object sender, EventArgs e) { MainRichTextBox.SelectAll(); }
private void MiddleAlign_Click(object sender, EventArgs e) //middle allign { RichEditCommand paragraphAlignmentCenter = MainRichTextBox.CreateCommand(RichEditCommandId.ToggleParagraphAlignmentCenter); paragraphAlignmentCenter.ForceExecute(paragraphAlignmentCenter.CreateDefaultCommandUIState()); }