ive looked all over google and i cant find a solution that works all the solutions are for old visual basic versions and dont work anymore
i want to get the current line number and cursor position of a text box it seems do able if i changed to a rich text box but i would rather keep it a normal text box
does anyone know how to achive this?
Page 1 of 1
get the current line and character position in a text box
#2
Posted 31 May 2005 - 08:25 PM
Hi Cyber Axe,
The examples for vb6 still work, you just have to adjust the syntax a little for .NET. This is for line number. cursor position code can be adjusted similarly.
put text1 and label1 on form and paste...
BTW, You are aware textbox has 32k limit, right?
The examples for vb6 still work, you just have to adjust the syntax a little for .NET. This is for line number. cursor position code can be adjusted similarly.
put text1 and label1 on form and paste...
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Integer, ByVal wMsg As Integer, _ ByVal wParam As Integer, ByRef lParam As Object) As Integer Private Const EM_LINEFROMCHAR As Short = &HC9s Sub Text1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Text1.TextChanged Dim currLine As Integer currLine = SendMessage(Text1.Handle.ToInt32, EM_LINEFROMCHAR, -1, 0) + 1 Label1.Text = "Line: " & Str(currLine) End Sub
BTW, You are aware textbox has 32k limit, right?
#3
Posted 01 June 2005 - 12:45 AM
Quote
BTW, You are aware textbox has 32k limit, right?
i changed the textbox to allow 999999999 i prefere using a standard text box because richtext boxes tend to mess up the tab aligning.
thanks for the code just tried it out and it works
#4
Posted 01 June 2005 - 11:33 AM
Glad I could help.
You can also set maxlength to 0 to allow theoretical max (I believe 65M or thereabouts, don't quote me).
What features are you including in your editor?
You can also set maxlength to 0 to allow theoretical max (I believe 65M or thereabouts, don't quote me).
What features are you including in your editor?
#5
Posted 02 June 2005 - 05:56 AM
i origonally planned on making it mroe or less an exact clone except supporting mac and unix text files and better find and replace (since normally this ends up almost crashing notepad)
but i'm also planning on adding a few extras such as alphabetizing the textbox and inserting text at the start or end of each line with auto incremental options and have been thinking about the possibly of multilingual support since it doesnt look that hard to do (also couldnt think of much else to add other than maybe colourization of html/xhtml tags and maybe auto tabbing though if i add them they probably wont appear in verison 1)
i even have it loading and using the origonal notpads settings though have yet to add saving to registry on exit
i didnt want to overcomplicate it or bloat it like seems to have happend with most others that are out there
ive almost got it completley replicating all of the origonals features except for find, find replace, and goto line and have yet to get alphabetization and inserting to work though the latter shouldnt be to hard after i figure out the goto line
but i'm also planning on adding a few extras such as alphabetizing the textbox and inserting text at the start or end of each line with auto incremental options and have been thinking about the possibly of multilingual support since it doesnt look that hard to do (also couldnt think of much else to add other than maybe colourization of html/xhtml tags and maybe auto tabbing though if i add them they probably wont appear in verison 1)
i even have it loading and using the origonal notpads settings though have yet to add saving to registry on exit
i didnt want to overcomplicate it or bloat it like seems to have happend with most others that are out there
ive almost got it completley replicating all of the origonals features except for find, find replace, and goto line and have yet to get alphabetization and inserting to work though the latter shouldnt be to hard after i figure out the goto line
#6
Posted 02 June 2005 - 09:26 AM
Sounds like a nice project. By "Alphebetize", you mean sort the contents of textbox by line right? Maybe this will help. Is easiest to read contents into an array, sort the array, rejoin the array and then refill the textbox.
'read textbox into string Dim s As String = Text1.Text.Trim 'convert string to an array of strings Dim sArray As String() = s.Split(Environment.NewLine) 'remove whitespaces (optional, depends on your need) Dim i As Integer For i = 0 To sArray.Length - 1 sArray(i) = sArray(i).Trim Next 'sort the array Array.Sort(sArray) 'Convert array back to string s = String.Join(Environment.NewLine, sArray) 'refill the textbox with sorted contents Text1.Text = s
#8
Posted 02 June 2005 - 11:03 AM
Seems we can't edit posts any more. This is shorthand version of above...
'convert textbox contents to an array of Strings Dim sArray As String() = Text1.Text.Split(Environment.NewLine) 'remove whitespaces Dim i As Integer For i = 0 To sArray.Length - 1 sArray(i) = sArray(i).Trim Next 'sort the array Array.Sort(sArray) 'convert array back to string and refill textbox Text1.Text = String.Join(Environment.NewLine, sArray)
#9
Posted 02 June 2005 - 12:15 PM
bledd, on Jun 2 2005, 03:31 PM, said:
notepad2 does this... freeware
<{POST_SNAPBACK}>
<{POST_SNAPBACK}>
i tried notepad 2 but i cant remember why but i disliked it ive tried all the so called note pad alternatives but all are either bloated, slow or over complicated they are more wordpad clones than notepad clones
my notepad alternative is clean, fast and simple and keeps the "rawness" as it were of the origonal
thanks for that alpha sort code dman almost perfect just need to mod it to remove extra spaces and smart number sorting
#10
Posted 02 June 2005 - 04:08 PM
Quote
my notepad alternative
Those three words say it all. There is no better way of getting exactly what you want than making it yourself!
- ← skins for dot net
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- [C++/C#/J#/VB] Miracle on Visual Studio Terrace →
Share this topic:
Page 1 of 1



Help
Back to top








