473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Cursor line in RichTextBox

..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.

--

Don Gollahon
Mar 26 '07 #1
2 2890
Try using

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

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

Mar 26 '07 #2
ClayB wrote:
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.GetPositionFr omCharIndex(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;

}

--

Don Gollahon
Mar 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an underscore?
2
by: anonymous | last post by:
is there a way to surpress the insertion cursor in a rich text box? for instance, i might want a RichTextBox to display some text as a Label would-- readonly, no insertion cursor though text...
1
by: rammohan | last post by:
hello how can we change cursor on particular text in richtext box using c# i.e i want to change the cursor from default to Hand when the mouse moves over a particular text. regards...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: GSX | last post by:
I've been reading and searching (and searching and reading) for far too many hours. I'm rather new - so I apologize if this is an over asked question... I'm working on a small text editor as a...
0
by: Sakharam Phapale | last post by:
Hi All, I am using RichTextBox control for text editing purpose. If user selects some text and right clicks on RichTextBox then context menu is displayed. Now, problem is when user sets...
2
by: gsb58 | last post by:
Hi! I'm new to VB.NET Anybody that could show me how to find the cursor position in a RichEdit? That is: when user click anywhere in the box and there's some text already, I want to...
0
by: Lou | last post by:
Dear all, I have two questions and need to get some hints from u. :0) 1. Editor with the syntax functionality. In my ongoing editor, when the user types the word, e.g. "ABC", the word "ABC"...
0
by: Rahna | last post by:
Hi, I'm using the DirectSS1 Speech Control in my VB 6 application. I tried to use the WordPosition Event to move the cursor along with the speech. the code goes like this Private Sub...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.