Click here to Skip to main content
15,893,904 members
Home / Discussions / C#
   

C#

 
GeneralRe: change Items selected in a listbox in runtime Pin
Luc Pattyn31-Jan-10 1:47
sitebuilderLuc Pattyn31-Jan-10 1:47 
GeneralRe: change Items selected in a listbox in runtime Pin
Dan Mos31-Jan-10 2:20
Dan Mos31-Jan-10 2:20 
AnswerRe: change Items selected in a listbox in runtime Pin
Mycroft Holmes31-Jan-10 0:12
professionalMycroft Holmes31-Jan-10 0:12 
AnswerRe: change Items selected in a listbox in runtime Pin
googoojkhan31-Jan-10 0:19
googoojkhan31-Jan-10 0:19 
QuestionItem in C# Pin
jojoba201030-Jan-10 19:05
jojoba201030-Jan-10 19:05 
QuestionRe: Item in C# Pin
jojoba201030-Jan-10 21:39
jojoba201030-Jan-10 21:39 
QuestionFind maximum font size where string fits in a box [modified] Pin
hain30-Jan-10 11:43
hain30-Jan-10 11:43 
AnswerRe: Find maximum font size where string fits in a box Pin
Luc Pattyn30-Jan-10 12:24
sitebuilderLuc Pattyn30-Jan-10 12:24 
Hi,

there is Graphics.MeasureString() which calculates the required width (for single-line) or required height (for multi-line and given a fixed width); it works pretty well provided you give it the exact same parameters (font, style, etc) you are going to give DrawString later. So you would need a little iteration:
1. choose some rather large fontsize;
2. calculate required height;
3. reduce fontsize by available_size/required_size;
4. repeat 2+3 two or three times.

Warning: there are some minor deviations; I once saw a CP article on the very subject. The solution then is to use TextRenderer class; I never felt a need to do that though.

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]


GeneralRe: Find maximum font size where string fits in a box Pin
DaveyM6930-Jan-10 13:46
professionalDaveyM6930-Jan-10 13:46 
GeneralRe: Find maximum font size where string fits in a box Pin
Luc Pattyn30-Jan-10 13:56
sitebuilderLuc Pattyn30-Jan-10 13:56 
GeneralRe: Find maximum font size where string fits in a box Pin
DaveyM6930-Jan-10 14:07
professionalDaveyM6930-Jan-10 14:07 
GeneralRe: Find maximum font size where string fits in a box Pin
hain6-Feb-10 17:19
hain6-Feb-10 17:19 
AnswerRe: Find maximum font size where string fits in a box Pin
Dave Kreskowiak30-Jan-10 14:07
mveDave Kreskowiak30-Jan-10 14:07 
AnswerRe: Find maximum font size where string fits in a box Pin
#realJSOP31-Jan-10 0:16
mve#realJSOP31-Jan-10 0:16 
QuestionSorting Pin
BobInNJ30-Jan-10 11:00
BobInNJ30-Jan-10 11:00 
AnswerRe: Sorting Pin
Luc Pattyn30-Jan-10 11:30
sitebuilderLuc Pattyn30-Jan-10 11:30 
GeneralRe: Sorting Pin
BobInNJ30-Jan-10 12:06
BobInNJ30-Jan-10 12:06 
GeneralRe: Sorting Pin
Luc Pattyn30-Jan-10 12:14
sitebuilderLuc Pattyn30-Jan-10 12:14 
GeneralRe: Sorting Pin
Gideon Engelberth30-Jan-10 19:15
Gideon Engelberth30-Jan-10 19:15 
GeneralRe: Sorting Pin
Luc Pattyn1-Feb-10 3:32
sitebuilderLuc Pattyn1-Feb-10 3:32 
GeneralRe: Sorting Pin
Gerry Schmitz30-Jan-10 14:43
mveGerry Schmitz30-Jan-10 14:43 
GeneralRe: Sorting [modified] Pin
PIEBALDconsult30-Jan-10 17:09
mvePIEBALDconsult30-Jan-10 17:09 
GeneralRe: Sorting [modified] Pin
Gideon Engelberth30-Jan-10 19:18
Gideon Engelberth30-Jan-10 19:18 
GeneralRe: Sorting Pin
Luc Pattyn31-Jan-10 1:58
sitebuilderLuc Pattyn31-Jan-10 1:58 
GeneralRe: Sorting Pin
Gideon Engelberth31-Jan-10 6:46
Gideon Engelberth31-Jan-10 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.