锚定按钮以进行全屏应用 [英] Anchoring Buttons To Make Full Screen Application

查看:45
本文介绍了锚定按钮以进行全屏应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会直接介绍它.我在winforms申请表上有3个按钮和3个标签,如下所示:

I'll get straight into it. I have 3 buttons and 3 labels lay out like this on my winforms application form:

当用户使表单全屏显示时,我希望标签保持不变,并且按钮变宽.我也希望它们平均分布,如下所示:

When he user makes the form full screen, I want the label to stay the same, and the buttons to become wider. I also want them to spread out equally, like this:

我将按钮的锚点属性设置为上",左",右",当我使应用程序全屏显示时,按钮变得非常长并且彼此重叠.如果将anchor属性设置为Top,Right,则最终结果完全相同,但位于屏幕的右侧.做我想做的最好的方法是什么?

I set the anchor property of the buttons to Top, Left, Right and when I make the application full screen, the buttons become very long and overlap each other. If I set the anchor property to Top, Right, the end up exactly the same but on the right side of the screen. What is the best way to do what I want to do?

推荐答案

我建议您尝试将标签-按钮"对移动到单独的 Panels 中.这样一来,您就可以将面板的大小作为一个实体在表单上进行调整,例如,只需设置按钮的锚点,即可根据其所在的面板来调整其大小.

I would advise you to try and move the Label-Button pairs into separate Panels. That allows you to resize the panels as one entity on the form and, for example, simply set the the anchoring of buttons to resize with the panel they are in.

通过描述很难说出您到底想要实现什么.在您的问题中包括两个屏幕快照,分别显示非最大化形式的位置和大小以及最大化形式中所需的位置和大小.这样一来,您就能更轻松地了解自己的真正需求.

Panel 一起使用时,应使用 TableLayoutPanel ,其列数等于按钮数.编辑表格布局的列,使百分比数字为 Width (例如,当您使用3列时,每列的百分比为33.33%).

Together with the Panel you should use a TableLayoutPanel with the number of columns equal to the number of your buttons. Edit the columns of the tablelayout to have percentage numbers as Width (e.g. 33.33% for each column when you use 3 columns).

在面板中添加一个面板.在其中放置标签和按钮,并将按钮固定在左侧和右侧,而标签仅固定在左侧.将面板拖到表列之一中,并将其 Dock 设置为Fill.然后,最后将tablelayoutpanel的锚点设置为left + right,以使其随表单调整大小.

Add a panel to your form. Place a Label and a Button inside and anchor the button to the left and right and the label only to the left. Drag the panel into one of the table columns and set it's Dock to Fill. Then finally set the anchor of the tablelayoutpanel to left+right to make it resize with the form.

现在发生的是:

  1. 表单调整大小
  2. Tablelayout使用以下格式调整大小
  3. 表中的列随表调整大小
  4. 面板会随着列的大小调整
  5. 内部按钮随面板调整大小

对其他表列也执行此操作,您会很高兴.

Do this for the other table columns as well and you are golden.

小表格

大表格

这篇关于锚定按钮以进行全屏应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆