Connecting Tech Pros Worldwide Forums | Help | Site Map

How to count character in a textbox, xbap application

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: 4 Weeks Ago
Hi!

I have textbox that have fixed size in GUI and I need to know how many character I can put into it.

For example, the textbox can contain 5 character in GUI and I wan to check if this string "234567.333" is not to large for the textbox, if it is then I wan to highlight the textbox.text = "#####" (like exel).

Is there any easy way to count how many character a fixed size textbox can contain? Cant use Graphics.MeasureString method cause it is a xbap application.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,763
#2: 4 Weeks Ago

re: How to count character in a textbox, xbap application


Is the font also a fixed width, like courier?
If you are using a variable width font like Ariel then the short answer is 'no'.
MMMMMMMMMMMMMMMMMMMM
IIIIIIIIIIIIIIIIIIII

Expand|Select|Wrap|Line Numbers
  1. MMMMMMMMMMMMMMMMMMMM
  2. IIIIIIIIIIIIIIIIIIII
See the difference?
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: 4 Weeks Ago

re: How to count character in a textbox, xbap application


The font is arial or times
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,763
#4: 4 Weeks Ago

re: How to count character in a textbox, xbap application


Quote:

Originally Posted by HenrikL View Post

The font is arial or times

Those are both proportional-width fonts. (Not fixed width)
So you can't predict the number of characters that will fit since more skinny characters will fit than fat characters.
Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 220
#5: 4 Weeks Ago

re: How to count character in a textbox, xbap application


What you might be able to do, and I stress *might* (because I don't really know much about XBAP other than what I just wikipedia'd right now), is write to a hidden auto-size label object and see if the width of that label is larger than your text box (ie, pixel width).

I know, I know, total hack (if it even works) but hey, it never hurts to try and be creative :D
Reply

Tags
count character, measurestring, textbox, xbap


Similar C# / C Sharp bytes