返回列表 上一主題 發帖

[發問] CheckBox 及 optionbutton 點選選項後 可否設計帶出textbox 輸入資料

回復 1# user999
  1. Option Explicit
  2. Private Sub UserForm_Initialize()
  3.     Dim LeftPos As Integer, TopPos As Integer, NewHeight As Integer, NewWidth As Integer, Rng As Range, H As Integer, i As Integer
  4.     Dim NewOptionButton As MSForms.Control
  5.     H = 1
  6.     NewHeight = 15
  7.     With Sheet1
  8.         With .Columns(1)
  9.             Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
  10.             ComboBox1.List = Rng.Value
  11.         End With
  12.         With .Columns(2)
  13.             Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
  14.             NewWidth = (Frame2.Width - (Rng.Count * H)) / Rng.Count
  15.             TopPos = (Frame2.Height - NewHeight) / 2
  16.             For i = 1 To Rng.Count
  17.                 LeftPos = 1 * H + (i - 1) * NewWidth
  18.                 Set NewOptionButton = _
  19.                 Frame2.Controls.Add("forms.OptionButton.1")
  20.                 With NewOptionButton
  21.                     .Width = NewWidth
  22.                     .Caption = Rng.Cells(i)
  23.                     .Height = NewHeight
  24.                     .Left = LeftPos
  25.                     .Top = TopPos
  26.                     .AutoSize = True
  27.                 End With
  28.             Next
  29.         End With
  30.         With .Columns(3)
  31.             Set Rng = Sheet1.Range(.Cells(2), .Cells(2).End(xlDown))
  32.             NewWidth = (Frame3.Width - (Rng.Count * H)) / Rng.Count
  33.             TopPos = (Frame3.Height - NewHeight) / 2
  34.             For i = 1 To Rng.Count
  35.                 LeftPos = 1 * H + (i - 1) * NewWidth
  36.                 Set NewOptionButton = _
  37.                 Frame3.Controls.Add("forms.CheckBox.1")
  38.                 With NewOptionButton
  39.                     .Width = NewWidth
  40.                     .Caption = Rng.Cells(i)
  41.                     .Height = NewHeight
  42.                     .Left = LeftPos
  43.                     .Top = TopPos
  44.                     .AutoSize = True
  45.                 End With
  46.             Next
  47.         End With
  48.     End With
  49. End Sub
複製代碼

TOP

本帖最後由 GBKEE 於 2012-7-26 17:44 編輯

回復 5# user999
另一問題 optionbutton 及 checkbox 內容一多起來,在fram2,,fram3中,所有的option僅一行會顯示(壓縮會看不到,)如何讓它換行
如果多到Frame2 或 Frame3 換行後還是容不下去該如何處置?
所以建議你在 Frame2 用ComboBox 控制項  單選 , Frame3 用ListBox 控制項 可複選

TOP

回復 1# user999
類似的 型態 參考參考

TEST.rar (20.66 KB)

TOP

回復 11# user999
ListBox1 後 若要取消, 只能輸0表示,無法恢復未選狀態吧!
修改如下
  1. Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  2.     Dim ListText As Integer, i As Integer
  3.     i = ListBox1.ListIndex
  4.     ListText = Val(ListBox1.List(i, 1))
  5.     ListText = Application.InputBox("請輸入數字 : ", ListBox1.List(i), ListText, Type:=1)
  6.     If ListText >= 0 Then
  7.         If ListText > 0 Then ListBox1.List(i, 1) = ListText    '>0 輸入數值
  8.         If ListText = 0 Then ListBox1.List(i, 1) = ""          '=0 清除內容
  9.     End If
  10.     Ar(ComboBox2.ListIndex) = Application.Transpose(Application.Transpose(ListBox1.List))
  11.                                           '品別陣列的索引之陣列 = ListBox1
  12.     ITEM(ComboBox1.ListIndex) = Ar        '店別陣列的索引之陣列 = 品別陣列
  13.     顯示計數
  14. End Sub
複製代碼

TOP

        靜思自在 : 我們最大的敵人不是別人.可能是自己。
返回列表 上一主題