本文整理汇总了C#中System.Windows.Forms.RichTextBox.GetFirstCharIndexFromLine方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.GetFirstCharIndexFromLine方法的具体用法?C# RichTextBox.GetFirstCharIndexFromLine怎么用?C# RichTextBox.GetFirstCharIndexFromLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.GetFirstCharIndexFromLine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckAndRemoveLineRichTextBox
private void CheckAndRemoveLineRichTextBox(RichTextBox richTextBox)
{
if (richTextBox.Lines.Length > LINE_MAX_COUNT)
{
int st_idx = richTextBox.GetFirstCharIndexFromLine(0);
int nx_idx = richTextBox.GetFirstCharIndexFromLine(1);
richTextBox.Text = richTextBox.Text.Remove(st_idx, nx_idx - st_idx);
}
}
示例2: removeTopLine
private static void removeTopLine(RichTextBox box)
{
int start = box.GetFirstCharIndexFromLine(0);
int count = box.Lines[0].Length + 1;
box.SelectionStart = start;
box.SelectionLength = count;
box.SelectedText = "";
}
示例3: PaintLine
/*
着色程序
考虑程序效率,改变SelectionStart以及SelectionColor等属性不会恢复,请自行恢复。
当富文本框有0个字符时不能处理,会引发错误。
*/
private void PaintLine(int LineNum, ref RichTextBox RTB)
{
string LineStr;
LineStr = RTB.Lines[LineNum];
int StartIndex = RTB.GetFirstCharIndexFromLine(LineNum); //本行开头的CharIndex
int StrPos = 0; //LineStr中的pos,从该行首个字符开始
string t = null;
while (true)
{
t = lexer.Next(ref StrPos,LineStr);
if (t == null) break;
// Console.WriteLine(t);
if (lexer.IsKeyWord(t))
{
//Console.WriteLine("SelectionStart:" + (StartIndex + StrPos - t.Length) + " Length:" + t.Length);
RTB.Select(StartIndex + StrPos - t.Length, t.Length);
RTB.SelectionColor = Color.Blue;
}
else if (lexer.IsString(t))
{
RTB.Select(StartIndex + StrPos - t.Length, t.Length);
RTB.SelectionColor = Color.Brown;
}else if(lexer.IsComment(t))
{
RTB.Select(StartIndex + StrPos - t.Length, t.Length);
RTB.SelectionColor = Color.Green;
}
else
{
RTB.Select(StartIndex + StrPos - t.Length, t.Length);
RTB.SelectionColor = Color.Black;
}
}
} //End of void PaintLine()
示例4: compilar
//.........这里部分代码省略.........
Code.brfalseVar[3] = (Code.BrfalseENUM)Code.BrfalseENUM.BGTenum;
Code.brfalseVar[4] = (Code.BrfalseENUM)Code.BrfalseENUM.BGEenum;
Code.brfalseVar[5] = (Code.BrfalseENUM)Code.BrfalseENUM.BEQenum;
//para usar luego como cil[nroDeInstrCorriente].indBrTrue = brtrueVar[x.relop - Token.EQ]; //BGEenum, etc
// public enum BrtrueENUM { BEQenum, BGEenum, BGTenum, BLEenum, BLTenum, BNEenum };
Code.brtrueVar = new Code.BrtrueENUM[6];
Code.brtrueVar[0] = (Code.BrtrueENUM)Code.BrtrueENUM.BEQenum;
Code.brtrueVar[1] = (Code.BrtrueENUM)Code.BrtrueENUM.BGEenum;
Code.brtrueVar[2] = (Code.BrtrueENUM)Code.BrtrueENUM.BGTenum;
Code.brtrueVar[3] = (Code.BrtrueENUM)Code.BrtrueENUM.BLEenum;
Code.brtrueVar[4] = (Code.BrtrueENUM)Code.BrtrueENUM.BLTenum;
Code.brtrueVar[5] = (Code.BrtrueENUM)Code.BrtrueENUM.BNEenum;
Parser.pilita.tope = -1; //inicializacion de E Stack
//Restaura Vars Locales
for (int i = 0; i < Parser.maxCantVarsLocales; i++) Parser.locals[i] = 0;
//Restaura Boton de continuar
if (Parser.ejecuta)
{
Parser.muestraProducciones = false;
Parser.muestraCargaDeInstrs = false;
}
else
{
// Parser.muestraProducciones = true;
Parser.muestraCargaDeInstrs = true;
}
//pantalla.Text = ""; //Pantallita del monitor
//pantalla.Visible = false; ////Pantallita del monitor no visible
Program1.form1.richTextBox9.Text = ""; //salida real (con la maqu virtual real)
Parser.cantVarLocales = 0;
Parser.nroDeInstrCorriente = 0;
//Restaura scroll al principio
Editor.SelectionStart = 0; // al principio
Editor.ScrollToCaret();
//limpia ventanas
richTextBox2.Text = ""; //Dejo vacio Stack
richTextBox3.Text = ""; //Dejo vacio Instr CIL
richTextBox4.Text = ""; //Vars Locales
//richTextBox6.Text = ""; //Arbol de derivacion
//redirige salida a "salida.txt"
StreamWriter sw = new StreamWriter("salida.txt");
sw.AutoFlush = true;
Console.SetOut(sw); //redirige salida a sw = "salida.txt"
//debe releer pestania.SelectedTab.Controls[0] y alimentar program con el contenido de pestania.SelectedTab.Controls[0]
//relee pestania.SelectedTab.Controls[0]
pestania.SelectedTab.Controls[0].Update();
string myString1 = Editor.Text;
//restaura color negro en pestania.SelectedTab.Controls[0]
Code.restaurarRichTextBox1conNegro();
//alimentar program con el contenido de pestania.SelectedTab.Controls[0] (myString1)
if (!Parser.ejecuta) Parser.MessageBoxCon3Preg();
try
{
Parser.inicializaCil();
/* Quitar los comentarios para que funcione el Scanner */
if (ZZ.Program) Console.WriteLine("Main Compilador 2");
if (ZZ.Principal)
{
Console.WriteLine("ha pasado new ScannerTest()");
Console.WriteLine("ha pasado SCTest.CRLFLineSeparators()");
Console.WriteLine("ha pasado SCTest.LFLineSeparators");
}
if (ZZ.Program) Console.WriteLine("pasó InvalidSymbols()\n\nTERMINÓ TODO EL SCANNER");
/////////////////////////////////////////////////////////////////////////////
Parser.Parse(myString1);
/////////////////////////////////////////////////////////////////////////////
if (ZZ.Program) Console.WriteLine("Tab.mostrarTab().....al final");
if (ZZ.Program) Tab.mostrarTab();
ZZ.Program = false;
if (ZZ.Program) Console.WriteLine("TERMINA TODO");
if (ZZ.Program) Console.ReadKey();
}
catch (ErrorMio e1)
{
int linea1 = e1.linea; int col1 = e1.columna; int sizeToken1 = e1.sizeToken;
Editor.Select(Editor.GetFirstCharIndexFromLine(linea1 - 1) + col1 - 1, sizeToken1);
Editor.SelectionColor = Color.Red;
System.Windows.Forms.MessageBox.Show("error 3245..." + e1.msg);
errorEnComilacion = true;
}
//Program1.form1.maquVirtualToolStripMenuItem.Enabled = true;
Program1.form1.depurarToolStripMenuItem.Enabled = true;
sw.Close();
} //Fin compilar()
示例5: parseLine
public void parseLine(int line, RichTextBox scripttext)
{
if (line < 0 || scripttext.Text.Length == 0)
return;
string linetext = scripttext.Lines[line];
if (linetext.Trim().Length == 0)
return;
int charindex = scripttext.GetFirstCharIndexFromLine(line);
parseFunction(charindex, linetext);
}
示例6: UpdateLineNumbers
void UpdateLineNumbers(RichTextBox lineNumbers, RichTextBox thisRtb)
{
//getLinefromCharindex isn't the same as line number when dealing with wordwrap
// string[] textLines = thisRtb.Text.Split('\n');
int topLine = lineFromCharIndex(thisRtb.Text, (thisRtb.GetCharIndexFromPosition(new Point(0,0))));
int bottomLine = thisRtb.GetLineFromCharIndex(thisRtb.GetCharIndexFromPosition(new Point(1, thisRtb.Height)));
int currentLine = 0;
lineNumbers.Text = "";
int lastLine = 0;
for (int i = topLine; i <= bottomLine; i++)
{
currentLine = lineFromCharIndex(thisRtb.Text, thisRtb.GetFirstCharIndexFromLine(i-1));
if (lastLine != currentLine)
{
lineNumbers.AppendText(currentLine + "");
lastLine = currentLine;
}
lineNumbers.AppendText("\n");
}
lineNumbers.SelectAll();
lineNumbers.SelectionAlignment = HorizontalAlignment.Right;
}
示例7: HighlightLine
/// <summary>
/// Highlight a line of text.
/// </summary>
/// <param name="textbox">Textbox to highlight.</param>
/// <param name="line">Index of the line to highlight.</param>
/// <param name="start">Starting column on the highlight.</param>
/// <param name="end">Ending column of the highlight.</param>
/// <param name="color">Color of the highlight.</param>
private static void HighlightLine(RichTextBox textbox, int line, int start, int end, Color color)
{
// Get the start and end of the line
string text = textbox.Text;
int lineStart = textbox.GetFirstCharIndexFromLine(line - 1);
start = lineStart + Math.Max(0, start - 1);
end = (end < 0) ?
textbox.GetFirstCharIndexFromLine(line) - 1 :
lineStart + Math.Max(0, end - 1);
// Trim whitespace from each end
while (start < end)
{
if (char.IsWhiteSpace(text[start]))
{
start++;
}
else if (char.IsWhiteSpace(text[end]))
{
end--;
}
else
{
break;
}
}
// Set the background color
HighlightText(textbox, start, end, color);
}
示例8: ColorLine
private void ColorLine(RichTextBox textBox, int line, Color color)
{
int index = textBox.GetFirstCharIndexFromLine(line);
if (index >= 0)
{
textBox.Select(index, textBox.Lines[line].Length);
textBox.SelectionBackColor = color;
}
}
示例9: ReplaceLastLines
public static void ReplaceLastLines(RichTextBox rtb, string text) {
int firstCharOfLineIndex = rtb.GetFirstCharIndexFromLine(rtb.Lines.Length - 2);
int lengthOfLine = rtb.Lines[rtb.Lines.Length - 2].Length;
rtb.Select(firstCharOfLineIndex, lengthOfLine);
rtb.SelectedText = text;
}
示例10: RTBSelectLine
static public void RTBSelectLine(RichTextBox a_rtb, int a_line)
{
int start = a_rtb.GetFirstCharIndexFromLine(a_line);
int end = a_rtb.GetFirstCharIndexFromLine(a_line + 1);
if( start < 0 )
{
start = 0;
end = 0;
}
if( end < 0 )
{
end = a_rtb.Text.Length;
}
a_rtb.Select(start, end - start);
}
示例11: Evaluate
private static Match[] Evaluate(HtmlDocument document, Control tb, ListBox lb, Control hb, ToolStripItem status, IEnumerable<Match> oldMatches, RichTextBox rtb)
{
var input = tb.Text.Trim();
tb.ForeColor = SystemColors.WindowText;
var elements = new HtmlNode[0];
if (string.IsNullOrEmpty(input))
{
status.Text = "Ready";
hb.Text = null;
}
else
{
try
{
//
// Simple way to query for elements:
//
// nodes = document.DocumentNode.QuerySelectorAll(input).ToArray();
//
// However, we want to generate the human readable text and
// the element selector in a single pass so go the bare metal way
// here to make all the parties to talk to each other.
//
var generator = new SelectorGenerator<HtmlNode>(new HtmlNodeOps());
var helper = new HumanReadableSelectorGenerator();
Parser.Parse(input, new SelectorGeneratorTee(generator, helper));
if (document != null)
elements = generator.Selector(Enumerable.Repeat(document.DocumentNode, 1)).ToArray();
hb.Text = helper.Text;
status.Text = "Matches: " + elements.Length.ToString("N0");
}
catch (FormatException e)
{
tb.ForeColor = Color.FromKnownColor(KnownColor.Red);
status.Text = "Error: " + e.Message;
hb.Text = "Oops! " + e.Message;
}
}
if (oldMatches != null)
Highlight(rtb, oldMatches, null, SystemColors.Info, null);
lb.BeginUpdate();
try
{
lb.Items.Clear();
if (!elements.Any())
return new Match[0];
var html = rtb.Text;
var matches = new List<Match>(elements.Length);
foreach (var element in elements)
{
var index = rtb.GetFirstCharIndexFromLine(element.Line - 1) + element.LinePosition - 1;
var match = _tagExpression.Match(html, index);
if (match.Success)
matches.Add(match);
}
Highlight(rtb, matches, null, Color.Yellow, null);
lb.Items.AddRange(elements.Select(n => n.GetBeginTagString()).ToArray());
return matches.ToArray();
}
finally
{
lb.EndUpdate();
}
}