excel - 使用用户窗体调整列表框大小
问题描述
我有一个调整用户sameCustomerForm
窗体窗口大小的代码:
Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long
Private Declare Function GetWindowLong _
Lib "User32.dll" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) _
As Long
Private Declare Function SetWindowLong _
Lib "User32.dll" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Const WS_THICKFRAME As Long = &H40000
Private Const GWL_STYLE As Long = -16
Public Sub FormResizable()
Dim lStyle As Long
Dim hWnd As Long
Dim RetVal
hWnd = GetForegroundWindow
lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME
RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)
End Sub
在用户窗体sameCustomerForm
代码中:
Private Sub UserForm_Activate()
Call FormResizable
End Sub
然后我lstSelector
在 userform 上有一个 Listbox sameCustomerForm
。在设计 WinForms 应用程序并将对象锚定到窗体的侧面时,我想坚持lstSelector
用户窗体的侧面,就像您在 Visual Studio 中所做的那样。
任何想法如何在 Excel 用户表单中实现?
编辑:
这几乎可以工作了。现在除了底部之外,所有东西都按比例调整大小。.Height = sameCustomerForm.Height / 1
如果.Height = sameCustomerForm.Height / 2
底部滚动条太高,我在调整窗口大小时缺少底部滚动条。有一些粘底的问题...
Private Sub UserForm_Resize()
With sameCustomerForm.lstSelector
.Width = sameCustomerForm.Width - 12
.Height = sameCustomerForm.Height / 2
.Top = 54
.Left = 0
End With
End Sub
编辑2:
这个成功了:
Private Sub UserForm_Resize()
With sameCustomerForm.lstSelector
.Width = sameCustomerForm.Width - 12
.Height = sameCustomerForm.InsideHeight - 54
.Top = 54
.Left = 0
End With
End Sub
解决方案
您应该使用您的用户表单指标来实现这一点。
下面是一个使用按钮将列表框靠边停靠的示例:
更新
重构了要使用的代码InsideHeight
和InsideWidth
用户窗体的属性。
这是按钮的代码:
Private Sub bottomButton_Click()
' dock bottom
With myForm.lstSelector
.Width = myForm.InsideWidth
.Height = myForm.InsideHeight / 3
.Top = myForm.InsideHeight - .Height
.Left = 0
End With
End Sub
Private Sub leftButton_Click()
' dock left
With myForm.lstSelector
.Width = myForm.InsideWidth / 3 ' just for example
.Top = 0
.Left = 0
.Height = myForm.InsideHeight
End With
End Sub
Private Sub rightButton_Click()
' dock right
With myForm.lstSelector
.Width = myForm.InsideWidth / 3 ' just for example
.Top = 0
.Left = myForm.InsideWidth - .Width
.Height = myForm.InsideHeight
End With
End Sub
Private Sub stickButton_Click()
' stick
With myForm.lstSelector
.Width = myForm.InsideWidth ' just for example
.Top = 0
.Left = 0
.Height = myForm.InsideHeight
End With
End Sub
Private Sub topButton_Click()
' dock up
With myForm.lstSelector
.Width = myForm.InsideWidth ' just for example
.Top = 0
.Left = 0
.Height = myForm.InsideHeight / 3
End With
End Sub
这是如何将其停靠到不同侧面的一般想法。如果您实现了可调整大小的 UserForm(手动或通过工作流) - 想法仍然相同,但您应该考虑将这些处理程序放入UserForm_Resize
事件。
如果您需要将其锚定在其他地方 - 您必须计算位置比例。
推荐阅读
- perl - apache DocumentRoot 可以更改 perl @INC 吗?
- c# - 有没有一种方法可以将光线投射击中的对象与另一个游戏对象进行比较?
- laravel - 我在将 Laravel 项目部署到服务器中的子域时遇到问题
- c# - 客户端和oracle服务器之间的重音字符编码问题
- intellij-idea - 如何调试 npm 应用程序
- angular - 如何在 ngContainer 中使用变量
- c++ - C ++ 11将一个向量移动到另一个向量 - 将右值引用传递给构造函数
- c++ - C++ 嵌套模板问题
- sql-server - SQL Server 中完整事务日志的实际原因
- docker - 错误:readlink /var/lib/docker/overlay2:无效参数