VB.NET:带有“类别框”内的复选框的表格,当某些问题被选中/未选中时,需要隐藏和向上移动这些框

时间:2019-03-18 13:46:10

标签: vb.net

我有一个通过函数调用的问题列表:

Call newquestion("Address correct?") 
Call newquestion("Borrower name correct?") 
Call newquestion("Occupant correct?") 

此功能如下:

    Public Sub newquestion(qtext as String)

 'ClickCount is used for tracking the number of click events throughout the form
    ClickCount = ClickCount + 1

 'qcount keeps the steady location of each question within a container. Sets the order of ControlIDs within each container
    qcount = qcount + 1
    IDName = "CB" & CInt(qcount).ToString
    newcheck = New CheckBox()
    newcheck.ControlID = IDName
    newcatbox.Controls.Insert(newcheck)
    newcheck.text = qtext
    newcheck.font = New HTMLFont("Arial", 14, 0, 0, 0)
    AddHandler newcheck.Click, AddressOf clickhandler 
    newcheck.visible = True
    newcheck.position = New Point(0, QN)
    QN = newcheck.Top + newcheck.size.height

 'Sets the position of the last question called for the size of the encasing Container
    bxlo = newcatbox.bottom

 'Resizes the encasing container
    newcatbox.size = New Size(500, QN + 35)

    If InStr(masterlist, newcheck.controlid.ToString() & "-0") Then
        newcheck.checked = False
        masterlist = Replace(masterlist, newcheck.controlid.ToString() & "-0" & ",", "")
    ElseIf InStr(masterlist, newcheck.controlid.ToString() & "-1") Then  
        newcheck.checked = True
    End IF

End Sub

此外,我添加了插入类别框的功能,以便使用以下方法将问题从另一个移至另一个:

Call newcat("Subject Property")


    Public Sub newcat(ctlt as String, Optional vizi as Object = 1)

    Catname = "Catbox" & catnum
    newcatbox = New CategoryBox()
    newcatbox.ControlID = Catname
    Form1.controls.insert(newcatbox)
    newcatbox.title = ctlt
    catnum = catnum + 1
    newcatbox.backcolor = Color.FromArgb(101, 157, 189)
    newcatbox.Position = New Point(0, bxlo + bxlor)
    bxlo = newcatbox.bottom + level.size.height
    newcatbox.size = New Size(500, 100)

    QN = 0
    'Number will increase based on the additions of buttons at top of forms
    bxlor = 20

    If vizi = 1 Then
        newcatbox.Visible = True
        Level = CType(FindControl(newcatbox.ToString()), CategoryBox)
    ElseIf vizi = 0 Then
        newcatbox.Visible = False
    End If

    CPPOINT = level.right
End Sub

此部分可以按我的要求完美地工作,但是,表单上的某些问题需要隐藏或取消隐藏继续进行操作的类别框。我试图将其写入ClickHandler事件,以便当用户选中或取消选中一个问题时,它要么隐藏下一个类别框,然后将下一个类别框移到列表中。或者单击后将列表向下移动,然后在其中添加隐藏的类别框作为下一个。关于最佳方法的任何想法?这是我的clickhandler事件:

   Private Sub clickhandler(sender as Object, e as EventArgs)
    Dim CID = CType(sender, Checkbox)
    Dim SetState as Integer
    Dim OldState as Integer
    Dim scut as String = CID.controlID.ToString() & "-"
    Dim Volca as String = CID.text.ToString()
    Dim Mono as String = CID.GetParent()

    'msgbox("This is the ClickHAndler Event" & " " & CID.ControlID.ToString())

    If CID.Checked = True Then
        SetState = 1
        OldState = 0
        'msgbox("Checked")
    ElseIF CID.Checked = False Then 
        SetState = 0
        OldState = 1
        'msgbox("Unchecked")
    End If

    If masterlist.contains(scut) Then
    masterlist = Replace(masterlist, scut & OldState & ",", scut & SetState & ",")
    Else
    masterlist = masterlist & scut & SetState & ","
    End If

Select Case Volca

    Case "PUD?"
       'This is where I want it to add or remove the next catbox and move the remaining ones up or down accordingly.

End Select

0 个答案:

没有答案