vb.net - VB How to Limit Line number of RichTextBox -
i have problems richtextbox.i have limit rtb's sizes regarding required character number(10 height 10 width).i tried limit number of lines using maxlength property.i mean can limit line length e.g. 10 if define max length 100 there can 10 lines.everything ok without enter key. when press enter not count rest of current line.if press enter after 6th char of line skips next line. , count previous line 6.so box gets longer through downwards. in advance...my code below.
private sub textbox1_keydown(byval sender object, byval e system.windows.forms.keyeventargs) handles richtextbox1.keydown 'here im trying count character number of each line dim count integer = 0 each s string in me.richtextbox1.lines count = count + 1 msgbox(count) dim nextlinetext string = s if e.keycode = keys.enter if count < (takefromcombo(combobox1)) richtextbox1.maxlength = richtextbox1.maxlength - (takefromcombo(combobox1) - nextlinetext.length) end if end if 'i tried disable enter key @ last line if count = takefromcombo(combobox1) if e.keycode = keys.enter e.handled = true end if end if next end sub
how this? (where rtb1 richtextbox):
private sub rtb1_keydown(sender object, e keyeventargs) handles rtb1.keydown if rtb1.text.length > 0 if rtb1.lines.count = 11 e.suppresskeypress = true end if if rtb1.lines(rtb1.getlinefromcharindex(rtb1.getfirstcharindexofcurrentline)).length > 9 , e.keycode <> keys.return e.suppresskeypress = true end if end if end sub
the tools manipulating situation little crude. getfirstcharindexofcurrentline
returns character index within entire string of rtb text. getlinefromcharindex(i)
gets index of line of text contains i. lines()
returns array of lines (which text of rtb, split on carriage returns, , lines(i)
, array, returns member of array @ index (found using 2 described rtb methods).
Comments
Post a Comment