7 Replies - 2576 Views - Last Post: 12 August 2012 - 06:42 AM Rate Topic: -----

#1 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

How Can I create a TextBox with Digit Grouping option

Posted 10 August 2012 - 03:12 AM

hi friends....
I want to create a textbox like Windows XP Calculator's textbox by this condition:

1 -the digits separate by comma (digit Grouping) like Windows XP Calculator's textbox
2 -the decimal part of number don't get digit grouping option .

example of this textbox format :

1,234,567.6576
0.2123423423423423
-1,2332,33.232023
Is This A Good Question/Topic? 0
  • +

Replies To: How Can I create a TextBox with Digit Grouping option

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How Can I create a TextBox with Digit Grouping option

Posted 10 August 2012 - 03:56 AM

You will need to format your string to currency format. Look this example:
http://www.java2s.co...matCurrency.htm
Was This Post Helpful? 0
  • +
  • -

#3 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: How Can I create a TextBox with Digit Grouping option

Posted 11 August 2012 - 03:17 AM

thanks...
but i don't want to use the currency format.i know that it is possible to use FormatNumber to do this.how? i don't know
if you know how please tell me.
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How Can I create a TextBox with Digit Grouping option

Posted 11 August 2012 - 03:50 AM

Ya sure you can, the .net has number format which you can use to do what you want to do:
Look at the following msdn library on how to use group separator for number format.
http://msdn.microsof...v=vs.71%29.aspx
http://msdn.microsof...y/0c899ak8.aspx
Was This Post Helpful? 0
  • +
  • -

#5 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: How Can I create a TextBox with Digit Grouping option

Posted 11 August 2012 - 06:05 AM

View Postsmohd, on 11 August 2012 - 03:50 AM, said:

Ya sure you can, the .net has number format which you can use to do what you want to do:
Look at the following msdn library on how to use group separator for number format.
http://msdn.microsof...v=vs.71%29.aspx
http://msdn.microsof...y/0c899ak8.aspx

thanks dear friend
this two way exactly are what i want.but a problem remains.how can do this in each time that i press the key.see below :
Perss Key ::::> 1
textbox.text=1

Perss Key ::::> 12
textbox.text=12

Perss Key ::::> 123
textbox.text=123

Perss Key ::::> 1234
textbox.text=1,234

Perss Key ::::> 1234.5
textbox.text=1,234.5

i hope you understand what i want.
in your guidance the number complete send to func and it's return value is my purpose .but i want that it work in each time i press the key and input new added value
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How Can I create a TextBox with Digit Grouping option

Posted 11 August 2012 - 06:23 AM

Then you will need to put in either TextChanged or KeyUp or other related events of the textbox you are referring to.
Was This Post Helpful? 0
  • +
  • -

#7 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: How Can I create a TextBox with Digit Grouping option

Posted 12 August 2012 - 05:47 AM

View Postsmohd, on 11 August 2012 - 06:23 AM, said:

Then you will need to put in either TextChanged or KeyUp or other related events of the textbox you are referring to.

hi again...
i put this code in Text_Change event :
Private Sub T_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles T.TextChanged
        T.Text = FormatNumber(T.Text, , , , TriState.True)
        T.Selectionstart = T.TextLength
End Sub


but it doesn't work.only first digit that i press has shown with two decimal digit.for example first key =1 then textbox1.text=1.00 and it doesn't change.
please tell me why it happens.and what should i do?

EDIT*: Please use code tags, they will format your code better than using color

This post has been edited by smohd: 12 August 2012 - 06:44 AM
Reason for edit:: code tags added

Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How Can I create a TextBox with Digit Grouping option

Posted 12 August 2012 - 06:42 AM

Try to put in Leave or LostFocus, but you will need to to click to another control for the code to take effect.
Or you can put a label where a formatted string is displayed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1