vb.net - Huge amount of textboxes repeated code -
i have around 200 textboxes in form. pressing "enter" takes next textbox. pressing "up" takes upper textbox, etc... know coding it's 200 textboxes it's gonna huge amount of copy/paste. there short way can 200 textboxes ?
you want show users 200 textboxes on single form? should @ least group them in container control logically, example in panel
. use oftype
.
you add constructor of form-class uses anonymous event handler:
dim alltextboxes = txt in me.textboxpanel.controls.oftype(of textbox)() order txt.tabindex dim txtlist = alltextboxes.tolist() int32 = 0 txtlist.count - 1 dim thistxt = txtlist(i) dim nextindex = if(i + 1 >= txtlist.count, 0, + 1) dim previndex = if(i - 1 < 0, txtlist.count - 1, - 1) dim nexttxt = txtlist(nextindex) dim prevtxt = txtlist(previndex) addhandler thistxt.keydown, sub(txt object, e keyeventargs) if e.keycode = 38 'up me.activecontrol = prevtxt elseif e.keycode = 13 'enter me.activecontrol = nexttxt end if end sub next
Comments
Post a Comment