473,837 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

defining on which line the cursor is in a textbox

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?

I guess that posotioning the cursor on the lien I foudn is also something I
will need, so if somebody knows how to do that... :-)

Thansk a lot in advance,

Pieter
Nov 20 '05 #1
22 4552
Hi,

As far as I remember, this can be done at the API level. Take a look at the
text box messages (starting with the EM_ prefix), especially EM_LINEFROMCHAR
and EM_LINEINDEX.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:40******** **************@ news.skynet.be. ..
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?

I guess that posotioning the cursor on the lien I foudn is also something I will need, so if somebody knows how to do that... :-)

Thansk a lot in advance,

Pieter


Nov 20 '05 #2
Cor
Hi Pieter,

Did you look for
textbox.lines

Something as (roughly written here not tested and never tried)
\\\\
for i as integer = 200 to textbox1.lines. length-1
if x.............. ..
next
////
I hope this helps?

Cor

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?

I guess that posotioning the cursor on the lien I foudn is also something I will need, so if somebody knows how to do that... :-)

Nov 20 '05 #3
* "DraguVaso" <pi**********@h otmail.com> scripsit:
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.


Quick and dirty: Use a loop and loop through the textbox's 'Lines'
property and sum up the length of the lines (+ the length of the line
separator). Then set the position by using the overloaded version of
the textbox's 'Select' method.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
I found this VB functions:

Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"
(ByVal _
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Const EM_LINEFROMCHAR = &HC9

Function GetTextBoxCurre ntLine(TB As TextBox) As Long
GetTextBoxCurre ntLine = SendMessage(TB. hWnd, EM_LINEFROMCHAR , -1, _
ByVal 0&) + 1
End Function
But I'm not able to 'translate' them in VB.NET. Anybody can help with this?

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

As far as I remember, this can be done at the API level. Take a look at the text box messages (starting with the EM_ prefix), especially EM_LINEFROMCHAR and EM_LINEINDEX.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:40******** **************@ news.skynet.be. ..
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?

I guess that posotioning the cursor on the lien I foudn is also

something I
will need, so if somebody knows how to do that... :-)

Thansk a lot in advance,

Pieter

Nov 20 '05 #5
Indeed dirty, but not quick I'm affraid. Somewhere else I have to work
alreaddy with ther Lines-property and loop through all of them, but it takes
a lot of time! I sometimes have really big amounts of text! It can take
easily 10 seconds.

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bu******** ****@ID-208219.news.uni-berlin.de...
* "DraguVaso" <pi**********@h otmail.com> scripsit:
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.


Quick and dirty: Use a loop and loop through the textbox's 'Lines'
property and sum up the length of the lines (+ the length of the line
separator). Then set the position by using the overloaded version of
the textbox's 'Select' method.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #6
DraguVaso <pi**********@h otmail.com> wrote:
Indeed dirty, but not quick I'm affraid. Somewhere else I have to work
alreaddy with ther Lines-property and loop through all of them, but it takes
a lot of time! I sometimes have really big amounts of text! It can take
easily 10 seconds.


That sounds pretty excessive - how are you doing it? If you're doing it
in a way that repeatedly uses the Lines property, that would be pretty
slow. If you fetch the Lines property value once and then repeatedly
use that "cached" value it shouldn't take long at all.

You'll need to be very careful in case you've got some \n and some \r\n
separators in there though - you should definitely check whether or not
that confuses things.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 20 '05 #7
Cor
Hi Pieter,

What are you storing in that textbox, The bible?

But to be serious, I saw that the lines is not an implementation of Ilist,
so maybe you can copy it first to an Ilist array to get it faster.

Just an Idea.

Cor
Indeed dirty, but not quick I'm affraid. Somewhere else I have to work
alreaddy with ther Lines-property and loop through all of them, but it takes a lot of time! I sometimes have really big amounts of text! It can take
easily 10 seconds.

Nov 20 '05 #8
Hehe,

No bible, but coda-files :-) Files with bankmovements etc. According to the
format it has for every record 1-3 lines with a lenght of 128 or 360, and
can eaisliy have 2000 records in it, so a total of 5000 lines isn't an
exception. For that I need to get a key to go quick to some special marks in
it.

I guess that's a good idea to put it first in an other kind of list,
although I don't know the 'IList", but I'm gonna try all these usggestions
out now.

Thansk a lot, I let you guys know something.

Pieter

"Cor" <no*@non.com> wrote in message
news:#w******** ******@TK2MSFTN GP12.phx.gbl...
Hi Pieter,

What are you storing in that textbox, The bible?

But to be serious, I saw that the lines is not an implementation of Ilist,
so maybe you can copy it first to an Ilist array to get it faster.

Just an Idea.

Cor
Indeed dirty, but not quick I'm affraid. Somewhere else I have to work
alreaddy with ther Lines-property and loop through all of them, but it

takes
a lot of time! I sometimes have really big amounts of text! It can take
easily 10 seconds.


Nov 20 '05 #9
* "DraguVaso" <pi**********@h otmail.com> scripsit:
I found this VB functions:

Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"
(ByVal _
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Const EM_LINEFROMCHAR = &HC9


Untested:

\\\
Private Declare Auto Function SendMessage Lib "user32.dll " ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
)

Private Const EM_LINEFROMCHAR As Int32 = &HC9
..
..
..
Public Function GetTextBoxCurre ntLine(ByVal TB As TextBox) As Integer
Return SendMessage(TB. Handle, EM_LINEFROMCHAR , -1, 0)
End Function
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #10

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

Similar topics

7
5815
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
1
5073
by: Ramsin Savra | last post by:
Hi, I have below code, to move the cursor to a specific line in a text-box control (I don't want to use RichTextBox) but doesn't work! any suggestions? int charIndex = 1; for (int i = 0; i < snpObject.edtTextBody.Lines.Length && i < iRequestedLineNumber - 1; ++i) { charIndex += snpObject.edtTextBody.Lines.Length;
1
3285
by: VMI | last post by:
In my Windows app, if I'm in a multi-line textbox and I'm writing a postal address (ie. write ist line and press <Enter>, write 2nd line and press <Enter>, etc...) how can I make sure that the Enter key will ALWAYS make the cursor jump to the following line in the textbox? For some reason, and this happens everywhere except on my development PC, if a user's writing a line and presses the <Enter> key, the program interprets that as the user...
1
3898
by: objectref | last post by:
Hi to all, we have the MousePosition property that we can get the Point of the position of the mouse cursor on the screen, but is it there a way to get the respective Point of a cursor in a TextBox ?? (relative to screen) I mean, i have a textbox that i write some text and i want to know the exact point location of the cursor at any time a character is displayed.
9
4912
by: DotNetShadow | last post by:
Hi Guys, I have been having this problem recently where I have a form with a textbox and button, if in the button event I have the following: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Cursor = Cursors.WaitCursor Textbox1.text = Now.Tostring System.Threading.Thread.Sleep(2000) ' 2 second wait
2
1468
by: dinny | last post by:
I have a form and a multiline textbox with a message. The problem is that I can see the cursor, is there any way so move the focus away from the textbox so that I don't see the cursor on the form (unless someone actively clicks on the form, that is ok) I tried this, but it didn't work Public Declare Auto Function HideCaret Lib "user32.dll" ( _ ByVal hwnd As IntPtr) As Boolean
1
3163
by: Marc Robitaille | last post by:
Hello I build a usercontrol. On this new control, I added two controls, a TextBox and a ComboBox. My ComboBox is filled with a DataTable. When the user types something in the TextBox, I apply a filter to the DataView of the DataTable of my ComboBox. If there is more than one element, I dropdown the list. If I have one element, it is automatically selected. My problem is that the cursor works badly. When I type for the first time in...
1
6243
by: Gyetko | last post by:
I have a textbox on an ASP.NET webform (VB code behind). Is there a way for me to set the cursor to the end of the line on a gotfocus call? Right now I'm using the following to set the foucs to that textbox on a keypress (given certain criteria). Thanks. document.forms.myTextBox.focus() // document.forms.myTextBox.EOL --- would be nice here : ) Or I could use it somewhere here when it actually gets the focus:
3
12015
by: fbergroth | last post by:
Hi, I'm quite new to C# allthough I've been programming in other languages for quite a while. I'd like to change the blinking cursor inside a TextBox, I guess I must derive the class and override the OnPaint()-method, however I have no clue what to do next. I want to be able to switch the blinking cursor to a solid, non-blinking, cursor and preferable have it with a color. So, how should I do that?
0
10562
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10617
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
10265
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
9391
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...
1
7803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
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
5843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4036
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.