Jump to content

Recommended Posts

Posted

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?


Posted

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

   
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?

Posted
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

Posted

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?

Posted

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

Posted

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

Posted

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)

Posted
notepad2 does this... freeware

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

Posted
my notepad alternative

Those three words say it all. There is no better way of getting exactly what you want than making it yourself!

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...