Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Resizing a form at runtime based on screen resolution

I want to resize a form and its controls based on a higher or lower screen resolution.

Comments

  • DrMartenDrMarten Member Posts: 748
    [b][red]This message was edited by DrMarten at 2006-4-23 21:51:23[/red][/b][hr]
    : I want to resize a form and its controls based on a higher or lower screen resolution.

    ======================================================================
    Hi,

    I don't know how to detect the current screen resolution though,
    not yet anyway. :-(

    From the HELP files.>>

    Form.Size PropertySee Also
    Form Class | Form Members | System.Windows.Forms Namespace | Width | Height | DesktopBounds | Bounds | Form Members (Visual J# Syntax) | Managed Extensions for C++ Programming
    Requirements
    Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
    Language
    C#

    C++

    JScript

    Visual Basic

    Show All
    Gets or sets the size of the form.

    [Visual Basic]
    Public Shadows Property Size As Size

    [C#]
    public new Size Size {get; set;}

    [C++]
    public: __property Size get_Size();
    public: __property void set_Size(Size);

    [JScript]
    public hide function get Size() : Size;
    public hide function set Size(Size);

    Property Value
    A Size that represents the size of the form.

    Remarks
    This property allows you to set both the height and width of the form at the same time instead of setting the Height and Width properties individually. If you want to set the size and location of a form, you can use the DesktopBounds property to size and locate the form based on desktop coordinates or use the Bounds property of the Control class to set the size and location of the form based on screen coordinates.

    Example
    [Visual Basic, C#, C++] The following example demonstrates how to create a form that is displayed with an opacity level of 75 percent. The example code creates a new form that is positioned in the center of the screen with an Opacity property set to change the opacity level of the form. The example code also sets the Size property to provide a larger sized form than the default size of the form. This example assumes that the method defined in this example is called from another form in an event handler or other method.

    [Visual Basic]
    [code]
    Private Sub CreateMyOpaqueForm()
    ' Create a new form.
    Dim form2 As New Form()
    ' Set the text displayed in the caption.
    form2.Text = "My Form"
    ' Set the opacity to 75%.
    form2.Opacity = 0.75
    ' Size the form to be 300 pixels in height and width.
    form2.Size = New Size(300, 300)
    ' Display the form in the center of the screen.
    form2.StartPosition = FormStartPosition.CenterScreen

    ' Display the form as a modal dialog box.
    form2.ShowDialog()
    End Sub
    [/code]

    You can also use
    Form.Height
    and
    Form.Width
    separately.


    Regards,

    Dr M.







    P.S. ScaleMode NOT supported.>>
    ScaleMode is not supportedSee Also
    Form Object Changes in Visual Basic .NET
    In Visual Basic 6.0, the ScaleMode property could be used to change the coordinate system for a form or PictureBox control from the default scale of twips.

    Visual Basic .NET does not support multiple coordinate systems; only pixels are supported. During upgrade, coordinates are automatically converted from twips to pixels; code that sets the ScaleMode property at run time will cause a compilation error and must be modified.

    Note The upgrade tool assumes that the design-time setting for the ScaleMode property was twips; if this is not the case, the conversion will be incorrect and must be fixed.
    What to do next

    Remove the line of code that sets the ScaleMode property.
    Review any code that was based on the ScaleMode property and modify any calculations as necessary. For example, the following code shows how to modify a procedure that used a ScaleMode of inches.
    ' Visual Basic 6.0
    Form1.ScaleMode = vbInches
    Text1.Move 2, 1
    The above procedure moves the text box 2 inches right and 1 inch down from the upper left corner of the form.

    ' After upgrade to Visual Basic .NET
    'UPGRADE ISSUE: Constant vbInches was not upgraded.
    'UPGRADE ISSUE: Form property Form1.ScaleMode is not supported.
    ' The next line must be removed in order to compile.
    Form1.ScaleMode = vbInches
    ' Twips are converted to pixels, but the original inch values are used.
    Text1.SetBounds(VB6.TwipsToPixelsX(2), VB6.TwipsToPixelsX(1),...
    After upgrade, the procedure moves the text box right by 2 pixels and down by 1 pixel not the desired result.

    ' Modified Visual Basic .NET code
    ' Removed the ScaleMode line.
    ' Convert the scale (1 inch = 1440 twips).
    Text1.SetBounds(VB6.TwipsToPixelsX(2880), VB6.TwipsToPixelsX(1440),...
    By multiplying the inches by 1440, the twips to pixel conversion now gives the same result as in the original Visual Basic 6.0 code.



Sign In or Register to comment.