CEdit::LineFromChar

调用该函数检索包含指定的字符的索引行的行号。

int LineFromChar( 
   int nIndex = -1  
) const;

参数

  • nIndex
    在编辑控件的文本包含所需字符的从零开始的索引值或包含– 1。 如果 nIndex 为– 1,它指定当前行,即,一个包含插入符号的行。

返回值

包含字符的索引的行的从零开始的行号指定 nIndex。 如果 nIndex 为– 1,包含选定内容的第一行字符数返回。 如果未选择,当前行号返回。

备注

字符的索引是字符数从最初编辑控件。

多行仅使用该成员函数的编辑控件。

有关更多信息,请参见 Windows SDK的 EM_LINEFROMCHAR

示例

// The index of the char to get information on. 
int nIndex = 4;
CString strText;

m_myEdit.GetWindowText(strText);
strText = strText.Mid(nIndex, 1);

// Get the text extent of the character.
CDC* pDC = m_myEdit.GetDC();
CSize sz = pDC->GetTextExtent(strText);
m_myEdit.ReleaseDC(pDC);

CPoint pt = m_myEdit.PosFromChar(nIndex);

// Dump the index, character, line number, and character bounds.
TRACE(_T("nIndex = %d, character = %c, line = %d, bounds = ")
   _T("{%d, %d, %d, %d}\r\n"),
   nIndex, strText[0], m_myEdit.LineFromChar(nIndex),
   pt.x /* left */, pt.y /* top */,
   pt.x+sz.cx /* right */, pt.y+sz.cy /* bottom */);

要求

Header: afxwin.h

请参见

参考

CEdit Class

层次结构图

CEdit::LineIndex