vb.net - How can I use the same code without having to retype it every time in different subs? -
so have textbox want allow numbers in, have code , works fine. want use in few textboxes, how can use same code without having retype in each textbox's keydown , keypress subs?
the code i'm using in keydown subs is
if e.keycode = keys.back         backspace = true     else         backspace = false     end if   and in keypress subs i'm using
if backspace = false         dim allowedchars string = "0123456789"         if allowedchars.indexof(e.keychar) = -1             e.handled = true         end if     end if   i'm using code few textboxes , wondering how can clean bit. can i? thank , time!
you make own version of textbox control inherits base textbox , extends custom code.
for example:
public class clevertextbox     inherits textbox      private backspace boolean = false      private sub clevertextbox_keydown(sender object, e keyeventargs) handles me.keydown         if e.keycode = keys.back             backspace = true         else             backspace = false         end if     end sub      private sub clevertextbox_keypress(sender object, e keypresseventargs) handles me.keypress         if backspace = false             dim allowedchars string = "0123456789"             if allowedchars.indexof(e.keychar) = -1                 e.handled = true             end if         end if     end sub end class   then recompile project, , should see new clevertextbox control has been added toolbox panel, , can drag , drop on form. 
Comments
Post a Comment