我正在使用tabcontrol創建第一頁與設計器。我正在以編程方式在頁面上創建帶有控件的新標籤頁。在每個頁面上有幾個面板,每個面板有兩個單選按鈕(一個是,另一個是否)。第一個面板內嵌有一個面板,其可見屬性設置爲false。如果用戶選擇是,我想嵌套面板的可見屬性設置爲true,這將顯示更多的單選按鈕,他們必須從中做出更多選擇。在tabcontrol的標籤頁上自動設置控件的屬性
我的問題是更改任何頁面上的嵌套面板的屬性,而不是第一頁。我可以檢測到單選按鈕,但我似乎無法找到一種方法來使嵌套面板可見。
Public Class ControlProgram
Dim pageindx as integer
Private Sub btnAddPrgm1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddPrgm1.Click
Dim newTab As New TabPage()
pageindx = (TabControl1.TabPages.Count + 1)
newTab.Text = "Step " & pageindx
'define fill panel controls
Dim newpnlFill As New Panel
Dim newlblFill As New Label
Dim newFillY As New RadioButton
AddHandler newFillY.CheckedChanged, AddressOf CheckforCheckedChanged
Dim newFillN As New RadioButton
AddHandler newFillN.CheckedChanged, AddressOf CheckforCheckedChanged
'add fill panel controls
With newTab.Controls
.Add(newpnlFill)
With newpnlFill
.Location = New System.Drawing.Point(6, 6)
.Size = New System.Drawing.Size(171, 137)
.BorderStyle = BorderStyle.FixedSingle
.Controls.Add(newlblFill)
With newlblFill
.Name = "Fill"
.Text = "Fill ?"
.Font = New Font(newlblFill.Font, FontStyle.Bold)
.Location = New Drawing.Point(5, 3)
End With
.Controls.Add(newFillY)
With newFillY
.Name = "FillY"
.Text = "Yes"
.Location = New Drawing.Point(23, 28)
.Size = New System.Drawing.Size(43, 17)
End With
.Controls.Add(newFillN)
With newFillN
.Name = "FillN"
.Text = "No"
.Location = New Drawing.Point(88, 28)
.Size = New System.Drawing.Size(39, 17)
End With
.Controls.Add(newpnlFill2)
With newpnlFill2
.Location = New System.Drawing.Point(2, 60)
.Size = New System.Drawing.Size(164, 68)
.BorderStyle = BorderStyle.FixedSingle
.Visible = False
End With
End With
End With
Private Sub CheckforCheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If TypeOf sender Is RadioButton Then
bEvent = CType(sender, RadioButton).Name
End If
End Sub
末級
因爲我已經想出了一個解決方案,我delima,使用您的建議作爲出發點。
我添加了幾個varribles: 昏暗RB作爲控制 昏暗bEvent作爲字符串 昏暗booFillY布爾 昏暗booFillN布爾
我還增加了的TabControl TabControl1.TabPages.Add(NEWTAB)
我還做了這些改變:
Private Sub CheckforCheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If TypeOf sender Is RadioButton Then
rb = sender
bEvent = CType(sender, RadioButton).Name
If bEvent = "FillY" Then
Dim newpnlFill2 As Panel = rb.Parent.Controls(3)
newpnlFill2.Visible = True
End If
If bEvent = "FillN" Then
Dim newpnlFill2 As Panel = rb.Parent.Controls(3)
newpnlFill2.Visible = False
End If
End If
End Sub
現在我可以讓嵌套面板(newpnlFill2)O可見通過在創建的任何標籤頁上選擇是或否單選按鈕來看不到。 感謝您的幫助。我懷疑我會自己得到那裏。