Jump to content
Xtreme .Net Talk

Recommended Posts

Guest Cheung
Posted

Hey, Can I add input mask of a textbox controls in a windows form?

my requirement is simple, when user type in number, the textbox automatically displays the format "###,###.00" .

use type: 123456

the textbox shows : 123,456.00

 

THANKS!!

Guest Cheung
Posted
also, how can I limit the textbox to accept only numbers?? thx
Guest littledump
Posted

its all gotta be hardcoded

 

heres the way id do it

 


sub txt_textaddwhateverevent(key as integer, shift as integer) handles txt.keydown
Dim fj as string
if key >= 48 and key <=57 then
   if len(txt.text) > 3 then
          if mid(txt.text, len(txt.text)-3, 3) = ".00" then
                fj = mid(txt.text, 1, len(txt.text)-3)
          else
                fj = txt.text
          end if
    else
       fj = txt.text
    end if
   if len(fj) mod 3 = 0 then
         fj = fj & ","
   end if
   txt.text = fj & ".00"
else
  txt.text = mid(txt.text, 1, len(txt.text)-1)
end if
end sub

 

i know its not pretty, but from the way u describe what u want to happen this should work. u can of course modify it to work exactly the way you want it to.

Guest Cheung
Posted

Thanks a lot.

 

I need to write code like this?!

that's fine and I will try.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...