Click here to Skip to main content
11,638,173 members (77,185 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Java Android
Need for some ui layout manipulations. Is this possible and how? Please help.
EDIT: If I know text size.
Posted 27-Dec-12 10:27am
Edited 27-Dec-12 23:49pm
Sergey Alexandrovich Kryukov at 27-Dec-12 17:27pm
TorstenH. at 28-Dec-12 5:58am
what are you trying to do? I expect you to be doing something wrong, so please share some more info about why you want to determine the length of a text.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are looking in wrong direction. By their nature, strings do not have lengths in in pixels or something like that. Strings are data structures totally abstracted from the way they are presented, such as fonts, colors, rendering styles, geometrical sizes, etc. Those are all some properties of some UI elements, whatever they are.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

string sta = "Hi This is Word";
Font arialBold = new Font("Garamond", 11.5F);
Size st1 = TextRenderer.MeasureText(sta, arialBold);
float pixcel = st1.Width;
halabella at 29-Dec-12 13:45pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 348
1 Sergey Alexandrovich Kryukov 314
2 stibee 288
3 OriginalGriff 190
4 Mika Wendelius 185
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408

Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100