簡體   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