Cursor line in RichTextBox

D

Don Gollahon

..NET 1.1

How do I get the line # the cursor is currently in in a RichTextBox?
Cursor x, y coordinates in the component would be nice.

Thanks.
 
C

ClayB

Try using

Point pt =
richtextBox1.GetPositionFromCharIndex(richtextBox1.SelectionStart);

=============
Clay Burch
 
D

Don Gollahon

ClayB said:
Try using

Point pt =
richtextBox1.GetPositionFromCharIndex(richtextBox1.SelectionStart);

=============
Clay Burch

Yes. I found the following:

public class cPosition
{
int x, y;

public int X
{
get
{
return x;
}
set
{
x = value;
}
}

public int Y
{
get
{
return y;
}
set
{
y = value;
}
}
}

//Declare the SendMessage:
public class Win32
{
public Win32()
{
//
// TODO: Add constructor logic here
//
}
[DllImport("User32.Dll")]
public static extern int SendMessage(IntPtr hWnd,int Msg,int
wParam,int lParam);
public const int EM_LINEINDEX = 0xBB;
}

private cPosition CursorPosition() //ref int x, ref int y)
{
int ColIndex;
int RowIndex;
int RowStartIndex;
cPosition cpos;

RowIndex = Memo1.GetLineFromCharIndex(Memo1.SelectionStart)+1;


Memo1.GetCharIndexFromPosition(Memo1.GetPositionFromCharIndex(Memo1.Sele
ctionStart));
RowStartIndex = Win32.SendMessage(Memo1.Handle,
Win32.EM_LINEINDEX, -1, 0);
ColIndex = Memo1.SelectionStart-RowStartIndex+1;
cpos = new cPosition();
cpos.X = ColIndex;
cpos.Y = RowIndex;
return cpos;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top