Designer Generated Code: SizeF

What does the 'F' accomplish or stand for in designer generated code for form 'AutoScaleDimensions'

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

Immediately following this code in designer generated code:

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(292, 262);

Why have 'SizeF(6F, 13F)' when the size is explicitly declared as 'Size(292, 262)'

The Designer then adds the hidden methods:

this.ResumeLayout(false);

this.PerformLayout();

... attempting to create a new library class.




Answer this question

Designer Generated Code: SizeF

  • sureshv

    Hi, TMB.

    >> What does the 'F' accomplish or stand for in designer generated code for form 'AutoScaleDimensions'

    "f" or "F" after a number tells the compiler to treat the numeric literal as a float.

    System.Drawing.SizeF's constructor takes two floats:

    SizeF(float width, float height)

    If you use real numbers here without the proper suffix, the could would not compile. For example, this won't compile:

    this.AutoScaleDimensions = new System.Drawing.SizeF(6.0, 13.5);

    ...but this will:

    this.AutoScaleDimensions = new System.Drawing.SizeF(6.0F, 13.5F);

    The "F" literal suffix is postpended to float arguments for correctness and to eliminate ambiguity.

    There are more literal suffixes. Here are a few:

    "d" or "D" for double
    "m" or "M" for decimal
    "l" or "L" for long

    Check out section C.1.8 of the language specification.

    >> Why have 'SizeF(6F, 13F)' when the size is explicitly declared as 'Size(292, 262)'

    AutoScaleDimensions is defined as a SizeF while ClientSize is defined as a Size.

    Hope that helps,

    Damon
    Microsoft Visual C#


  • Dyna-Cube

    This article explains why floats are used instead of integers. The basic problem with the .NET 1.1 AutoScaleBaseSize property was that because the values were stored as integral values "rounding errors occur that become evident when a form is cycled through multiple resolutions." The AutoScaleDimensions is used to store information that allows controls to be scaled relative to the size of the system Font or DPI. The reason that the ClientSize is set with integers is because it's an absolute pixel size, whereas the AutoScaleDimensions is a scaling factor. I'm not sure if that makes it much clearer, but hopefully the article will help :)

    Anson



  • Interflex

    Thank you very much! I understand now.

    I hope you have a great day.



  • Helen999888

    Okay. So what does the 'floating' accomplish. I'm trying to understand the underlying concept of why the designer uses 'floating' for a form and literals for form controls. Does this whole 'F' thing make the size a relative size

  • Designer Generated Code: SizeF