Board logo

標題: [發問] ToggleButton按鈕 [打印本頁]

作者: ssooi    時間: 2021-3-4 15:07     標題: ToggleButton按鈕

設計一個ToggleButton1放在工作表1,希望去控制userform1的開啟或關閉
程式碼如附件
但是似乎只能開,卻無法關

而且開了之後,若點擊userform1右上角的關閉按鈕,ToggleButton1按鈕就偵測不到,就變得很尷尬

[attach]33091[/attach]
作者: luhpro    時間: 2021-3-6 03:33

回復 1# ssooi
你想要的結果是底下這樣嗎?
===== UserForm1 =====
  1. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  2.     With ActiveSheet
  3.       .ToggleButton1.Caption = " OFF "
  4.       .ToggleButton1.BackColor = RGB(248, 250, 250)
  5.     End With
  6.     Cancel = True
  7.     UserForm1.Hide
  8. End Sub
複製代碼
===== 工作表1 =====
  1. Private Sub ToggleButton1_Click()
  2.   If ToggleButton1.Caption = " ON " Then
  3.     ToggleButton1.Caption = " OFF "
  4.     ToggleButton1.BackColor = RGB(248, 250, 250)
  5.     UserForm1.Hide
  6.   Else
  7.     ToggleButton1.Caption = " ON "
  8.     ToggleButton1.BackColor = RGB(0, 255, 0)
  9.     UserForm1.Show
  10.   End If
  11. End Sub
複製代碼
[attach]33101[/attach]




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)