private void Scramble() { try { RichBox.SelectAll(); TextSelection sel = RichBox.Selection; int DocSize = RichBox.Document.ContentStart.GetOffsetToPosition(RichBox.Document.ContentEnd); for (int i = 0; i < DocSize - 5; i++) { TextPointer pointer1 = RichBox.Document.ContentStart.GetPositionAtOffset(i * 3); TextPointer pointer2 = RichBox.Document.ContentStart.GetPositionAtOffset(i * 3 + 3); RichBox.Selection.Select(pointer1, pointer2); sel = RichBox.Selection; sel.ApplyPropertyValue(FontFamilyProperty, new FontFamily(RandomFontList[rng.Next(RandomFontList.Count)])); sel.ApplyPropertyValue(FontSizeProperty, 12 + 8 * rng.NextDouble()); sel.ApplyPropertyValue(ForegroundProperty, "#FF" + rng.Next(0, 128).ToString("X2") + rng.Next(0, 128).ToString("X2") + rng.Next(0, 128).ToString("X2")); } } catch { // I the developer think this try-catch is not quite the right solution // but it works and it would probably cost at least 30 minutes to fund a better solution } }
private void Clear() { RichBox.SelectAll(); TextSelection sel = RichBox.Selection; sel.ApplyPropertyValue(FontFamilyProperty, new FontFamily("Comic Sans MS")); sel.ApplyPropertyValue(FontSizeProperty, (double)12); sel.ApplyPropertyValue(ForegroundProperty, "#FF000000"); }
public int reDraw(Boolean reNewElements) { this.RtfColors.setMode(this.drawMode); try { if (this.assignedRtf.Text.Length < 1) { return(0); } } catch (Exception ex) { return(0); } Stopwatch watch = new Stopwatch(); watch.Start(); this.drawingRtf.Rtf = this.assignedRtf.Rtf; this.drawingRtf.highlighting = true; int startpos = this.assignedRtf.SelectionStart; int endPos = this.assignedRtf.SelectionLength; int start = this.assignedRtf.GetCharIndexFromPosition(new Point(0, 0)); int end = this.assignedRtf.GetCharIndexFromPosition(new Point(this.assignedRtf.ClientSize.Width, this.assignedRtf.ClientSize.Height)); this.RtfColors.reAssign(this.drawingRtf); this.RtfColors.startLine = this.startLine; this.RtfColors.startPosition = this.startPos; if (reNewElements == true || this.elementsReaded == false) { if (this.markLine < 0) { this.getElements(); } } if (this.markLine < 0) { this.drawingRtf.Select(this.startPos, this.drawingRtf.TextLength); this.drawingRtf.SelectionColor = drawingRtf.ForeColor; this.drawingRtf.SelectionBackColor = HighlightStyle.defaultColor; foreach (DictionaryEntry de in this.KeyWords) { string word = de.Key.ToString(); HighlightStyle setColor = (HighlightStyle)de.Value; this.RtfColors.markWordsAll(word, setColor); } // must be at the end foreach (String keyWord in Projector.Script.RefScriptMaskMatch.KeyWords) { this.RtfColors.markTextLine(keyWord, KeyWordStyle); } //if (this.drawMode == RtfColoring.MODE_DIRECT) { }; string[] variables = new String[this.Srcipt.getAllStrings().Count]; int it = 0; foreach (DictionaryEntry de in this.Srcipt.getAllStrings()) { string word = de.Value.ToString(); string keyWord = de.Key.ToString(); if (this.drawMode == RtfColoring.MODE_DIRECT) { this.RtfColors.markTextLine("\"" + word + "\"", TextStyle); } //this.RtfColors.markTextLine(keyWord, VaribalesStyle); variables[it] = keyWord; it++; } watch.Stop(); this.preRuntime = watch.ElapsedMilliseconds.ToString(); this.runtimeValue = watch.ElapsedMilliseconds; watch.Restart(); this.RtfColors.markWordsAll(variables, VaribalesStyle); this.RtfColors.wordMode(); // full lines works in booth modes as the same foreach (int lino in this.Srcipt.getCommentLines()) { this.RtfColors.markFullLine(lino, CommentStyle); } foreach (ScriptErrors err in this.Srcipt.getAllErrors()) { if (err.wordPosition < 1) { this.RtfColors.markFullLine(err.lineNumber, ErrorStyle, true, false, err.errorMessage + " @" + err.lineNumber); } else { this.RtfColors.markFullLine(err.lineNumber, InProgressStyle, true, false, err.errorMessage + " @" + err.lineNumber, err.wordPosition); } } } // marks an line if (this.markLine > -1) { if (multiMarkLine) { if (!this.LastExecutedLines.ContainsKey(markLine)) { this.LastExecutedLines.Add(markLine, 10); } else { this.LastExecutedLines[markLine] = 10; } Hashtable copyThat = new Hashtable(); foreach (DictionaryEntry lastExecs in this.LastExecutedLines) { int execCount = (int)lastExecs.Value; execCount--; if (execCount > 0) { copyThat.Add(lastExecs.Key, execCount); if (execCount > 8) { this.RtfColors.markFullLine((int)lastExecs.Key, executionStyle, true, false); } else { HighlightStyle hStyle = new HighlightStyle(); hStyle.ForeColor = execColors[(int)lastExecs.Value]; this.RtfColors.markFullLine((int)lastExecs.Key, hStyle, true, false); } } } LastExecutedLines = copyThat; } else { this.RtfColors.markFullLine(markLine, executionStyle, true, false); } if (assignedRtf is RichBox) { RichBox rbt = (RichBox)assignedRtf; if (!rbt.selectionIsVisible()) { this.assignedRtf.ScrollToCaret(); } } else { this.assignedRtf.ScrollToCaret(); } } watch.Stop(); this.runtime = watch.ElapsedMilliseconds.ToString(); watch.Restart(); // ------------ end drawing ---------------- this.drawingRtf.highlighting = false; this.assignedRtf.Rtf = this.drawingRtf.Rtf; if (assignedRtf is RichBox) { RichBox rbt = (RichBox)assignedRtf; rbt.LineMarker = drawingRtf.LineMarker; } // try to scroll last visible position if (this.markLine < 0) { this.assignedRtf.SelectionLength = 0; this.assignedRtf.SelectionStart = end; if (this.updateScrols) { this.assignedRtf.ScrollToCaret(); } this.assignedRtf.SelectionStart = start + this.assignedRtf.Lines[this.assignedRtf.GetLineFromCharIndex(start)].Length + 1; if (this.updateScrols) { this.assignedRtf.ScrollToCaret(); } this.assignedRtf.SelectionStart = startpos; this.assignedRtf.SelectionLength = endPos; } else { int index = this.assignedRtf.GetFirstCharIndexFromLine(this.markLine); if (index > -1) { this.assignedRtf.SelectionStart = index; this.assignedRtf.SelectionLength = 1; if (this.updateScrols) { this.assignedRtf.ScrollToCaret(); } } } watch.Stop(); this.postRuntime = watch.ElapsedMilliseconds.ToString(); return(1); }
public ReflectionScriptHighLight(ReflectionScript script, RichTextBox rtf) { execColors[0] = Color.FromArgb(75, 20, 35); execColors[1] = Color.FromArgb(80, 40, 45); execColors[2] = Color.FromArgb(85, 60, 55); execColors[3] = Color.FromArgb(90, 80, 65); execColors[4] = Color.FromArgb(95, 100, 75); execColors[5] = Color.FromArgb(100, 120, 85); execColors[6] = Color.FromArgb(105, 140, 95); execColors[7] = Color.FromArgb(115, 160, 105); execColors[8] = Color.FromArgb(120, 180, 115); execColors[9] = Color.FromArgb(125, 200, 125); this.Srcipt = script; this.assignedRtf = rtf; this.drawingRtf = new RichBox(); drawingRtf.Rtf = assignedRtf.Rtf; this.RtfColors = new RtfColoring(drawingRtf); drawingRtf.highlighting = true; loadColors(); rtf.BackColor = HighlightStyle.defaultColor; this.ObjectStyle.ForeColor = Color.DarkMagenta; this.ObjectStyleReferenz.ForeColor = Color.SteelBlue; this.VaribalesStyle.ForeColor = Color.DarkGreen; //this.VaribalesStyle.BackColor = Color.Transparent; this.CommandStyle.ForeColor = Color.Blue; this.ReferenzStyle.ForeColor = Color.DarkGoldenrod; this.VarStyle.ForeColor = Color.DarkOrange; this.KeyWordStyle.ForeColor = Color.DarkBlue; this.CommentStyle.ForeColor = Color.DarkOliveGreen; this.CommentStyle.BackColor = Color.LightGray; this.ErrorStyle.ForeColor = Color.DarkRed; this.ErrorStyle.BackColor = Color.LightPink; this.InProgressStyle.ForeColor = Color.OrangeRed; this.InProgressStyle.BackColor = Color.Yellow; this.executionStyle.ForeColor = Color.LightGreen; this.executionStyle.BackColor = Color.DarkGreen; this.TextStyle.ForeColor = Color.SlateBlue; this.TextStyle.BackColor = Color.LightCyan; this.NumberStyle.ForeColor = Color.DarkGoldenrod; this.RtfColors.stringStyle = this.TextStyle; this.resetFonts(); }