Cyber Axe Posted June 1, 2005 Posted June 1, 2005 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 anymorei 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 boxdoes anyone know how to achive this?
dman Posted June 1, 2005 Posted June 1, 2005 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 IntegerPrivate Const EM_LINEFROMCHAR As Short = &HC9sSub 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?
Cyber Axe Posted June 1, 2005 Author Posted June 1, 2005 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
dman Posted June 1, 2005 Posted June 1, 2005 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?
Cyber Axe Posted June 2, 2005 Author Posted June 2, 2005 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 exiti didnt want to overcomplicate it or bloat it like seems to have happend with most others that are out thereive 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
dman Posted June 2, 2005 Posted June 2, 2005 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 stringDim s As String = Text1.Text.Trim'convert string to an array of stringsDim sArray As String() = s.Split(Environment.NewLine)'remove whitespaces (optional, depends on your need)Dim i As IntegerFor i = 0 To sArray.Length - 1 sArray(i) = sArray(i).TrimNext'sort the arrayArray.Sort(sArray)'Convert array back to strings = String.Join(Environment.NewLine, sArray)'refill the textbox with sorted contentsText1.Text = s
dman Posted June 2, 2005 Posted June 2, 2005 Seems we can't edit posts any more. This is shorthand version of above...'convert textbox contents to an array of StringsDim sArray As String() = Text1.Text.Split(Environment.NewLine)'remove whitespacesDim i As IntegerFor i = 0 To sArray.Length - 1 sArray(i) = sArray(i).TrimNext'sort the arrayArray.Sort(sArray)'convert array back to string and refill textbox Text1.Text = String.Join(Environment.NewLine, sArray)
Cyber Axe Posted June 2, 2005 Author Posted June 2, 2005 notepad2 does this... freeware<{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 clonesmy notepad alternative is clean, fast and simple and keeps the "rawness" as it were of the origonalthanks for that alpha sort code dman almost perfect just need to mod it to remove extra spaces and smart number sorting
dman Posted June 2, 2005 Posted June 2, 2005 my notepad alternative Those three words say it all. There is no better way of getting exactly what you want than making it yourself!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now