當復選框在另一個用戶表單中被選中時,我在嘗試使物件在一個用戶表單中可見時遇到問題。(例如,當在用戶表單 1 中選中復選框時,獲取要在用戶表單 2 中顯示的標簽)
有沒有辦法解決這個問題?
uj5u.com熱心網友回復:
剛才我做一個測驗。
創建兩個用戶表單:uf1 和 uf2。
我在每個用戶表單屬性上將“顯示模式”設定為 false。
在uf1中我放了兩個復選框:cb1和cb2。
在 uf2 我放了一個標簽: Label1
然后我打開兩個用戶表單。
勾選uf1中的cb1,標簽1顯示在uf2中取消勾選cb1,標簽1
隱藏在uf2中。

如果這就是你的意思,代碼是這樣的:
uf1中的子
Private Sub cb1_Click()
If cb1 = True Then uf2.Label1.Visible = True Else uf2.Label1.Visible = False
End Sub
uf2中的子
Private Sub UserForm_Initialize()
Label1.Visible = False
End Sub
請注意,uf1 中的代碼不會進行錯誤檢查,例如:如果 uf2 不存在(不顯示)那么.....
uj5u.com熱心網友回復:
另一個用戶表單中的物件
- 在兩種用戶表單中,手動將
ShowModal屬性設定為False。
UserForm1
Option Explicit
Private Sub CheckBox1_Click()
ShowLabel
End Sub
Private Sub UserForm_Initialize()
If UserForm2.Visible Then CheckCheckBox
End Sub
UserForm2
Option Explicit
Private Sub UserForm_Initialize()
ShowLabel
End Sub
Module1
Option Explicit
Sub CheckCheckBox()
UserForm1.CheckBox1 = UserForm2.Label1.Visible
End Sub
Sub ShowLabel()
UserForm2.Label1.Visible = UserForm1.CheckBox1
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/465694.html
