By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,931 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,931 IT Pros & Developers. It's quick & easy.

How to count character in a textbox, xbap application

P: 4
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.
Oct 26 '09 #1
Share this Question
Share on Google+
4 Replies


tlhintoq
Expert 2.5K+
P: 3,525
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?
Oct 26 '09 #2

P: 4
The font is arial or times
Oct 26 '09 #3

tlhintoq
Expert 2.5K+
P: 3,525
@HenrikL
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.
Oct 26 '09 #4

GaryTexmo
Expert 100+
P: 1,501
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
Oct 27 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.