Form fit its components - Programmers Heaven

Howdy, Stranger!

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

Categories

Form fit its components

gustavo-serragustavo-serra Posts: 21Member
Hi, I am new to C# so I am struggling to accomplish some basics tasks. I have finished my application already and now I am polishing the user interface. The user interface changes according to the logged user (administrator can access more stuff than an employee). When I a hide a button, for example, it leaves a hole in the GUI. Is there a way to make the form adjust its own size to fit all of its components currently visible? I am searching the web for a while, and can't figure it out.

Thanks ;D

Comments

  • MuidemMuidem Posts: 1Member
    I don't know about resizing the form but you can dynamically size your buttons so they stretch to fit the form.

    Something like this perhaps.

    [code]
    int boundWidth = Screen.PrimaryScreen.Bounds.Width;
    int boundHeight = Screen.PrimaryScreen.Bounds.Height;

    button1.Location = new Point(5, 5);
    button1.Size = new Size(boundWidth / 2, boundHeight / 8);

    button2.Location = new Point(boundWidth / 2 + 5, 5);
    button2.Size = new Size(boundWidth / 2 - 10, boundHeight / 8);
    [/code]

    I'm sure you can figure it out from there =)
  • gustavo-serragustavo-serra Posts: 21Member
    Thanks for your reply.

    Actually I want to resize just the window. There in an option in the form properties called AutoSize that will make the window fit its components. This property will not work dinamically, however. I can use it and prevent the user from resizing the window. But this property does not work nicely. It will not make the components touch the left or upper border of the window, but resize the right and lower border. Thus, if the components are not left-up aligned, they will not be adjusted.

    Thanks again for your reply.
Sign In or Register to comment.