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


C# RichTextBox.GetLineFromCharIndex方法代码示例

本文整理汇总了C#中System.Windows.Forms.RichTextBox.GetLineFromCharIndex方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.GetLineFromCharIndex方法的具体用法?C# RichTextBox.GetLineFromCharIndex怎么用?C# RichTextBox.GetLineFromCharIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.RichTextBox的用法示例。


在下文中一共展示了RichTextBox.GetLineFromCharIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getRowAndColFromRichTextBox

        public static void getRowAndColFromRichTextBox(RichTextBox rtbToProcess, ref int iRowIndex, ref int iColIndex)
        {
            int RowStartIndex;

            iRowIndex = rtbToProcess.GetLineFromCharIndex(rtbToProcess.SelectionStart) + 1;
            RowStartIndex = win32.SendMessage(rtbToProcess.Handle, win32.EM_LINEINDEX, -1, 0);
            iColIndex = rtbToProcess.SelectionStart - RowStartIndex + 1;
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:8,代码来源:windowsForms.cs

示例2: GetCurrentLine

		public static string GetCurrentLine(RichTextBox richTextbox) {
			int charIndex = richTextbox.SelectionStart;
			int currentLineNumber = richTextbox.GetLineFromCharIndex(charIndex);
			if (currentLineNumber < richTextbox.Lines.Length)
				return richTextbox.Lines[currentLineNumber];
			return string.Empty;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:7,代码来源:RichTextboxHelper.cs

示例3: GetLastLine

		public static string GetLastLine(RichTextBox richTextbox) {
			int charIndex = richTextbox.SelectionStart;
			int currentLineNumber = richTextbox.GetLineFromCharIndex(charIndex);
			if (richTextbox.Lines.Length <= currentLineNumber)
				return richTextbox.Lines[richTextbox.Lines.Length - 1];
			return richTextbox.Lines[currentLineNumber];
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:7,代码来源:RichTextboxHelper.cs

示例4: getCurLine

 private string getCurLine(RichTextBox rtb)
 {
     #if false
     int line = rtb.GetLineFromCharIndex(rtb.SelectionStart);
     string cmd = rtb.Lines[line];
     #else
     string cmd = rtb.Lines[rtb.Lines.ToArray().Length - 1];
     #endif
     if (cmd.IndexOf(this.prompt_string, 0) == 0) {
         cmd = cmd.Replace(this.prompt_string, "");
     }
     if (cmd.IndexOf(this.subprompt_string, 0) == 0) {
         cmd = cmd.Replace(this.subprompt_string, "");
     }
     return cmd;
 }
开发者ID:kuyon,项目名称:siren,代码行数:16,代码来源:term.cs

示例5: Line

        public static int Line(RichTextBox e, int index)
        {
            int correction = 0;
            try
            {
                correction = GetCorrection(e, index);
            }
            catch (Exception)
            {
            }
            return e.GetLineFromCharIndex(index) - correction + 1;

            //  MessageBox.Show(ex.ToString());

            // return 0;
        }
开发者ID:BrentKnowles,项目名称:YourOtherMind,代码行数:16,代码来源:CursorPositionclass.cs

示例6: getCurrentLine

 /// <summary>
 /// Gets the current line from a RichTextBox control.
 /// </summary>
 /// <param name="rtb">the RichTextBox control.</param>
 /// <returns>the current line.</returns>
 public static String getCurrentLine(RichTextBox rtb)
 {
     if (rtb.Lines.Length == 0)
     {
         return rtb.Text;
     }
     else
     {
         int startIndex = rtb.GetFirstCharIndexOfCurrentLine();
         int currentLineNumber = rtb.GetLineFromCharIndex(startIndex);
         return rtb.Lines[currentLineNumber];
     } 
 }
开发者ID:dineshkummarc,项目名称:SWAT_4.1_Binaries_Source,代码行数:18,代码来源:ControlsUtils.cs

示例7: getCurrentLineNo

 /// <summary>
 /// Gets the current line number.
 /// </summary>
 /// <param name="tb">a RichTextBox.</param>
 /// <returns>the current line number.</returns>
 public static int getCurrentLineNo(RichTextBox rtb)
 {
     if (rtb.Lines.Length == 0)
     {
         return 0;
     }
     else
     {
         int startIndex = rtb.GetFirstCharIndexOfCurrentLine();
         return rtb.GetLineFromCharIndex(startIndex);
     }
 }
开发者ID:dineshkummarc,项目名称:SWAT_4.1_Binaries_Source,代码行数:17,代码来源:ControlsUtils.cs

示例8: getCurrentLineAndLineNo

 /// <summary>
 /// Gets a key/value pair containing currentLineNumber/currentLine.
 /// </summary>
 /// <param name="tb">the TextBox.</param>
 /// <returns>a key/value pair containing currentLineNumber/currentLine.</returns>
 public static KeyValuePair<int, String> getCurrentLineAndLineNo(RichTextBox rtb)
 {
     if (rtb.Lines.Length == 0)
     {
         return new KeyValuePair<int, String>(0, rtb.Text);
     }
     else
     {
         int startIndex = rtb.GetFirstCharIndexOfCurrentLine();
         int currentLineNumber = rtb.GetLineFromCharIndex(startIndex);
         return new KeyValuePair<int, String>(currentLineNumber, rtb.Lines[currentLineNumber]);
     }
 }
开发者ID:dineshkummarc,项目名称:SWAT_4.1_Binaries_Source,代码行数:18,代码来源:ControlsUtils.cs

示例9: MakeDescText

		// Makes a transparent, read only text box used to describe
		// something
		internal static RichTextBox MakeDescText(String text, Control con)
		{
			RichTextBox tb = new RichTextBox();
			tb.TabStop = false;
			tb.Text = text;
			tb.BorderStyle = BorderStyle.None;
			tb.Multiline = true;
			tb.AutoSize = true;
			tb.ReadOnly = true;
			tb.WordWrap = true;
			tb.HideSelection = true;
			tb.BackColor = con.BackColor;
			// Get number of actual lines the text box needs 
			// given the current width
			int lines = (1 + tb.GetLineFromCharIndex(tb.TextLength));
			tb.Height = tb.PreferredHeight * lines;
			return tb;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:20,代码来源:Utils.cs

示例10: 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

示例11: SetLineColumnIndex

        /// <summary>
        /// Sets the line column index.
        /// </summary>
        /// <param name="charIndex"> The char index.</param>
        /// <param name="lineStartCharIndex"> The line start char index.</param>
        /// <param name="textbox"> The textbox control.</param>
        private void SetLineColumnIndex(int charIndex, int lineStartCharIndex, RichTextBox textbox)
        {
            if ( textbox.Text == "" ) return;

            int cIndex = charIndex;
            int lineIndex = textbox.GetLineFromCharIndex(cIndex);

            // new charIndex
            int columns = 0;
            int lineCharIndex = 0;
            columns = cIndex - lineStartCharIndex;
            lineCharIndex = columns+1;

            // count tabs
            char[] chars = textbox.Lines[lineIndex].ToCharArray();

            if ( cIndex > 0 )
            {
                for (int k=lineStartCharIndex;k<cIndex;k++)
                {
                    if ( textbox.Text.Substring(k,1) == "\t" )
                    {
                        columns += 3;
                    }
                }
            }

            ChangeStatusBarEventArgs e = new ChangeStatusBarEventArgs();

            e.Index=3;
            e.Text="Line " + (lineIndex+1) + " Col " +  (columns+1) + " Char " + lineCharIndex + " Abs Char " + cIndex;

            ChangeStatusBarPanelEvent(this,e);
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:40,代码来源:GBInspectorWorkspace.cs

示例12: GetLineForRtf

 /// <summary>
 /// Get current line of the Textbox.
 /// </summary>
 /// <param name="rtf"></param>
 /// <returns></returns>
 private static int GetLineForRtf(RichTextBox rtf)
 {
     int index = rtf.SelectionStart;
     return rtf.GetLineFromCharIndex(index);
 }
开发者ID:Helmut-Ortmann,项目名称:EnterpriseArchitect_hoTools,代码行数:10,代码来源:ActiveX.cs

示例13: PasteString

        private void PasteString(RichTextBox oTB, string sText)
        {
            StringBuilder oBuffer = new StringBuilder(sText);

            if (sText == Environment.NewLine)
            {
                int iSelStart = oTB.SelectionStart;
                int iLigne = oTB.GetLineFromCharIndex(iSelStart);

                if (oTB.Lines.Length > iLigne)
                {
                    string sLigne = oTB.Lines[iLigne];
                    foreach (char c in sLigne)
                    {
                        if (c == ' ' || c == '\t')
                        {
                            oBuffer.Append(c);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            oTB.SelectedText = oBuffer.ToString();
        }
开发者ID:artiche,项目名称:AwkEverywhere,代码行数:28,代码来源:AwkEverywhereMainForm.cs

示例14: UpdateCaretPos

        /// <summary>
        /// A helper method for determining the current caret position.
        /// </summary>
        public void UpdateCaretPos(RichTextBox txtContent)
        {
            try
            {
                var index = txtContent.SelectionStart;
                var line = txtContent.GetLineFromCharIndex(index);
                var col = index - SendMessage(txtContent.Handle, EM_LINEINDEX, -1, 0);
                var newPosition = string.Format("Line: {0} - Col: {1}", (++line), (++col));

                // let's notify the listeners (unless there are none)
                if (CaretPositionChanged != null)
                {
                    CaretPositionChanged(newPosition);
                }
            }
            catch (ObjectDisposedException)
            {
                // it shouldn't be possible for a disposed Noc to be updated
                // "caret position" -wise, but we'll catch it here either way
            }
        }
开发者ID:mikkoj,项目名称:nocs,代码行数:24,代码来源:Noc.cs

示例15: GetCurrentPos

 public static void GetCurrentPos(RichTextBox rtfMain, ref int line, ref int col)
 {
     Point pt;
     int index;
     index = rtfMain.SelectionStart;
     line = rtfMain.GetLineFromCharIndex(index);
     pt = rtfMain.GetPositionFromCharIndex(index);
     pt.X = 0;
     col = index - rtfMain.GetCharIndexFromPosition(pt);
     line ++;
     col ++;
     return;
 }
开发者ID:caesay,项目名称:Asn1Editor,代码行数:13,代码来源:FormConvertData.cs


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