Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unsafe code safety question Pin
jschell27-Dec-11 10:18
jschell27-Dec-11 10:18 
QuestionResizing Controls According to Forms' Size Pin
AmbiguousName27-Dec-11 2:15
AmbiguousName27-Dec-11 2:15 
AnswerRe: Resizing Controls According to Forms' Size Pin
PIEBALDconsult27-Dec-11 2:29
mvePIEBALDconsult27-Dec-11 2:29 
AnswerRe: Resizing Controls According to Forms' Size Pin
David C# Hobbyist.27-Dec-11 2:34
professionalDavid C# Hobbyist.27-Dec-11 2:34 
AnswerRe: Resizing Controls According to Forms' Size Pin
Shameel27-Dec-11 4:08
professionalShameel27-Dec-11 4:08 
AnswerRe: Resizing Controls According to Forms' Size Pin
BillWoodruff27-Dec-11 4:38
professionalBillWoodruff27-Dec-11 4:38 
GeneralRe: Resizing Controls According to Forms' Size Pin
Roger Wright27-Dec-11 20:58
professionalRoger Wright27-Dec-11 20:58 
GeneralRe: Resizing Controls According to Forms' Size Pin
BillWoodruff29-Dec-11 2:31
professionalBillWoodruff29-Dec-11 2:31 
I once tried a WinForm experiment where I:

a. in the Form Load event:

1. did a recursive parsing of every Control on the Form, to locate all Controls that had a Font property (Labels, TextBoxes, etc.) that one might want to be changed when the Form was resized.

Each of these selected Controls, and their Font, were stored as Dictionary entries:
private Dictionary<Control, Font> cFontDict = new Dictionary<Control, Font>();
The initial Form Size was then stored.

b. in the Form SizeChanged EventHandler:

1. calculated change ratios in width and height based on the obvious.

2. traversed the Dictionary<control, font="">, via for-loop (so I could alter entries), and messed around with changing the Font based on the calculated change ratios.

WinForms does not make this easy since Control.Font.Size, and Control.Font.SizeInPoints are both read-only properties.

A look at the typical Font assignment code in a Designer.cs file:
this.textBox1.Font = new System.Drawing.Font("Arial", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
Suggests the tediousness involved in changing the whole damn Font just to get a change in FontSize. I did this so long ago I forget exactly how I coded that up.

And what did I end up with: when the app was run, and the Form resized arbitrarily: a lot of bad-looking UI, with the Fonts often looking crummy. I forget whether I limited this to an experiment involving only certain types of Fonts (TrueType ?), or not.

After all, a change in FontSize means you need to have the AutoSize properties of TextBoxes, Labels, etc., set to 'True. And as their "container" size increases or decreases based on new line-height parameters, they then may be out of alignment with other fixed size Controls. So the container itself needs to be scaled.

So, the next step would have been to resize every Control by the same ratios, perhaps address special properties of certain Controls, like the ItemHeight of a ListBox ... but I never took that next step: because, by that time, I had already concluded that reasonable continuous scaling of Fonts in WinForms was a losing proposition, and that if I really had to have that functionality, I should change over to WPF where it appears to me that functionality is ready-to-go out-of-the-box.

The only scenario I can imagine, currently, in WinForms, where I might try to vary FontSize based on the changing Form Size would be one where some client demanded (and was willing to pay for) an App that "snapped" between two or four different sizes, where I could do the right thing, to make all the Fonts that needed to change look good at each size.

best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle

GeneralRe: Resizing Controls According to Forms' Size Pin
BobJanova30-Dec-11 14:44
BobJanova30-Dec-11 14:44 
GeneralRe: Resizing Controls According to Forms' Size Pin
BillWoodruff2-Jan-12 14:29
professionalBillWoodruff2-Jan-12 14:29 
AnswerRe: Resizing Controls According to Forms' Size Pin
RaviRanjanKr31-Dec-11 3:41
professionalRaviRanjanKr31-Dec-11 3:41 
Questionhow can we write large source code in 2 or more seperate units? Pin
Fred 3427-Dec-11 2:04
Fred 3427-Dec-11 2:04 
AnswerRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 2:30
mvePIEBALDconsult27-Dec-11 2:30 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Shameel27-Dec-11 3:32
professionalShameel27-Dec-11 3:32 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Tosche Station27-Dec-11 3:55
Tosche Station27-Dec-11 3:55 
AnswerRe: how can we write large source code in 2 or more seperate units? Pin
AmitGajjar27-Dec-11 3:10
professionalAmitGajjar27-Dec-11 3:10 
AnswerRe: how can we write large source code in 2 or more seperate units? Pin
Shameel27-Dec-11 3:34
professionalShameel27-Dec-11 3:34 
AnswerRe: how can we write large source code in 2 or more seperate units? Pin
#realJSOP27-Dec-11 4:08
professional#realJSOP27-Dec-11 4:08 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 4:29
mvePIEBALDconsult27-Dec-11 4:29 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Shameel27-Dec-11 4:42
professionalShameel27-Dec-11 4:42 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 4:56
mvePIEBALDconsult27-Dec-11 4:56 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Shameel27-Dec-11 5:09
professionalShameel27-Dec-11 5:09 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 5:30
mvePIEBALDconsult27-Dec-11 5:30 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
#realJSOP27-Dec-11 7:37
professional#realJSOP27-Dec-11 7:37 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Shameel27-Dec-11 8:02
professionalShameel27-Dec-11 8:02 

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.