繁体   English   中英

调整表单上某些控件大小的最佳方法是什么?

[英]What is the best way to resize only certain controls on a form?

我正在编码一个聊天/服务器客户端,但在尝试重新调整大小时遇到​​了一些问题。

我有一个看起来像这样的聊天表格。

在此处输入图片说明

我想使顶部标签,文本框和按钮的大小和位置完全相同。 我要调整聊天文本框,列表框以及在其上键入消息的底部的文本框。 我也想保持相同大小的发送按钮,并且总是在发送文本框的右侧。 我很难弄清楚如何编写代码的大小调整部分。

我已经尝试过很多类似的东西,我真的可以使用一些帮助。

txtchat.height = me.scaleheight - 100 ,在其中添加100,以尝试txtchat.height = me.scaleheight - 100表单顶部的控件。 也尝试过

txtchat.height = me.scaleheight - txtsend.height - 100和大量其他内容。 我想我只是不了解此调整大小是如何工作的。

就像我说的那样,这在.Net中会简单得多(Winforms具有可自动完成此操作的对接面板),但这是在VB6中需要执行的操作:

我没有安装VB6,所以我不会写出代码,但是步骤应该足够正确。

我假设txtSend是“发送”按钮左侧的文本框。 要获取聊天框的大小,您需要:

Bottom_area_height = Statusbar.Height + Statusbar_Padding + _
    txtSend.Height + txtSend_Padding
txtChat.Height = ScaleHeight - (txtChat.Top + Bottom_area_height) ' Fixed here
txtChat.Width = ScaleWidth - lstUsers.Width

txtSend.Top = ScaleHeight - Bottom_area_height
txtSend.Width = ScaleWidth - btnSend.Width

btnSend.Top = txtSend.Top

填充值是控件之间的垂直间隙-状态栏填充看起来像2个网格单元,而txtSend的填充似乎是一个网格单元的一半。 您使用的网格不正确,因此很难看到控件的距离。

编辑

要添加水平填充,只需将控件的左边缘移到要有左边距的位置,然后从文本框的宽度中减去两次边距(以解决这两个边距)。

txtChat.Width = ScaleWidth - (txtChat.Left * 2 + User_list_padding)
txtSend.Width = ScaleWidth - (txtSend.Left * 2 + Send_button_padding)
btnSend.Left = ScaleWidth - (btnSend.Width + Send_button_padding)

如果需要,填充值是控件之间的水平间隙。

Dim intAreaHeight As Integer

intAreaHeight = stsBar.Height + 40 + txtSend.Height

txtChat.Height = Me.ScaleHeight - 1450
txtChat.Width = Me.ScaleWidth - lstUsers.Width

lstUsers.Height = Me.ScaleHeight - 1450
lstUsers.Left = txtChat.Width + 40

txtSend.Top = Me.ScaleHeight - intAreaHeight + 20
txtSend.Width = Me.ScaleWidth - cmdSend.Width

cmdSend.Left = txtSend.Width + 40
cmdSend.Top = txtSend.Top

这使我得到了这个结果,因为您可以看到左侧填充和右侧填充抵靠表单的一面,完全没有填充。 我似乎无法找到一个好的解决方案来获得填充。

在此处输入图片说明

编辑:下面更新的代码非常感谢您的帮助。

Dim intAreaHeight As Integer

intAreaHeight = stsBar.Height + 40 + txtSend.Height

txtChat.Height = Me.ScaleHeight - 1450
txtChat.Width = Me.ScaleWidth - lstUsers.Width - (txtChat.Left * 2 + 40)

lstUsers.Height = Me.ScaleHeight - 1450
lstUsers.Left = txtChat.Width + 80

txtSend.Top = Me.ScaleHeight - intAreaHeight + 20
txtSend.Width = Me.ScaleWidth - cmdSend.Width - (txtSend.Left * 2 + 40)

cmdSend.Left = txtSend.Width + 80
cmdSend.Top = txtSend.Top

怎么样:

只需调整您想要调整的尺寸即可。

对我来说听起来“最好”。 我尝试过希望Windows能读懂我的想法,但我还没有运气。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM