473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2916
Try using

Point pt =
richtextBox1.Ge tPositionFromCh arIndex(richtex tBox1.Selection Start);

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

Mar 26 '07 #2
ClayB wrote:
Try using

Point pt =
richtextBox1.Ge tPositionFromCh arIndex(richtex tBox1.Selection Start);

=============
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("User 32.Dll")]
public static extern int SendMessage(Int Ptr 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.GetLineFr omCharIndex(Mem o1.SelectionSta rt)+1;
Memo1.GetCharIn dexFromPosition (Memo1.GetPosit ionFromCharInde x(Memo1.Sele
ctionStart));
RowStartIndex = Win32.SendMessa ge(Memo1.Handle ,
Win32.EM_LINEIN DEX, -1, 0);
ColIndex = Memo1.Selection Start-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
9454
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
2362
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 could still be selected. help!
1
1760
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 --rammohan
22
4549
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 that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and not on line 1. Anybody has any ideas?
3
9173
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 learning project using the RichTextBox control. I wish to display the current line and total line count on the status bar, and also the cursor position on the current line. I have found the current line by using...
0
1380
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 cursor at some character position and then right clicks without selection, cursor automatically moves down at the end of RichTextBox text and context menu is displayed.
2
2815
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 programatically move to a new line and insert time, make a new line and user will be ready to insert new text.
0
1589
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" will appear in the RichTextBox with the changed color red. Afterwards, when the furhter action is taking on, e.g. user gives the input directly in the RichTextBox or types the other word, the color
0
1356
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 DirectSS1_WordPosition(ByVal hi as long, ByVal lo as long, ByVal ByteOffset as long) RichTextBox1.SelStart=ByteOffset/2
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.