本文整理汇总了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;
}
示例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;
}
示例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];
}
示例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;
}
示例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;
}
示例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];
}
}
示例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);
}
}
示例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]);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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
}
}
示例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;
}