当前位置: 首页>>代码示例>>C#>>正文


C# RichTextBox.GetFirstCharIndexFromLine方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:mikanovic20,项目名称:TimerExample,代码行数:9,代码来源:Form2.cs

示例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 = "";
        }
开发者ID:pmsanford,项目名称:sic-debug,代码行数:9,代码来源:SimpleCharacterTerminal.cs

示例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()
开发者ID:jingjiajie,项目名称:SmartEditor,代码行数:42,代码来源:Painter.cs

示例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()
开发者ID:compitool,项目名称:compi-version-6,代码行数:101,代码来源:Form1.cs

示例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);
 }
开发者ID:captain-mayhem,项目名称:captainsengine,代码行数:10,代码来源:PcdkParser.cs

示例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;
        }
开发者ID:blindsight,项目名称:CSSControl,代码行数:29,代码来源:EditorForm.cs

示例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);
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:38,代码来源:Viewer.cs

示例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;
            }
        }
开发者ID:michyer,项目名称:canape,代码行数:10,代码来源:BaseDiffControl.cs

示例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;
		}
开发者ID:nbomeroglu37,项目名称:GUI-ffmpeg,代码行数:6,代码来源:LogWindow.cs

示例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);
    }
开发者ID:fmutant,项目名称:scriptorium,代码行数:17,代码来源:OutputWin.cs

示例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();
            }
        }
开发者ID:Sword-Breaker,项目名称:fizzler,代码行数:74,代码来源:MainForm.cs


注:本文中的System.Windows.Forms.RichTextBox.GetFirstCharIndexFromLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。