我有一个标签控件,上面有 5 个标签。每个选项卡上都有大量单独的控件。(范围从 3 到 70 个控件,所有标准复选框、文本框、组合框和单选按钮。)
运行时,绘图似乎在更改选项卡的过程中冻结。因此,您最终会将旧选项卡的部分控件与新选项卡的部分控件绘制在一起。
我希望能够在所有控件完全加载并且代码完成运行“评分”代码之前停止绘图。
我曾尝试在选项卡控件和单个页面上使用暂停/恢复布局,但它似乎对绘图没有任何影响。
我还尝试使用在搜索答案时找到的自定义类,但它要么不会暂停绘图,要么会导致表单在视觉上变得不稳定。
Imports System.Runtime.InteropServices
Friend Class DrawingControl
<DllImport("user32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Boolean, ByVal lParam As Int32) As Integer
End Function
Private Const WM_SETREDRAW As Integer = 11
Public Shared Sub SuspendDrawing(ByVal parent As Control)
SendMessage(parent.Handle, WM_SETREDRAW, False, 0)
End Sub
Public Shared Sub ResumeDrawing(ByVal parent As Control)
SendMessage(parent.Handle, WM_SETREDRAW, True, 0)
parent.Refresh()
End Sub
End Class
*** 编辑 11/22/2019:添加在更改选项卡时运行的“评分”代码
以下是更改选项卡时运行的事件序列:
1) TabControl 取消选择
Private Sub tabDetails_Deselecting(sender As Object, e As TabControlCancelEventArgs) Handles tabDetails.Deselecting
tabDetails.SuspendLayout()
pgAcademic.SuspendLayout()
pgBusiness.SuspendLayout()
pgLIS.SuspendLayout()
pgPatient.SuspendLayout()
pgRegulatory.SuspendLayout()
End Sub
2) TabControl Selected - 这里没有代码 - 但是,在此之后,选项卡与每个选项卡的控件轮廓“组合”在一起。
3) TabControl 索引更改
Private Sub tabDetails_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabDetails.SelectedIndexChanged
Dim pg As Integer = Me.tabDetails.SelectedIndex
Select Case pg
Case 0
Me.txtPageScore.Text = score_pgPatientCare
Case 1
Me.txtPageScore.Text = score_pgBusiness
Case 2
Me.txtPageScore.Text = score_pgLIS
Case 3
Me.txtPageScore.Text = score_pgAcademic
Case 4
Me.txtPageScore.Text = score_pgRegulatory
End Select
End Sub
4) 步骤 3 触发此代码:
Private Sub UpdateScore()
Dim intTotalScore As Integer = Vars.intNewScore 'Max Score = 708
Dim intScore As Integer = 0
If Vars.DisableEvents Then Exit Sub
Vars.DisableEvents = True
score_pgPatientCare = Scoring.UpdateScore(Me.pgPatient)
score_pgBusiness = Scoring.UpdateScore(Me.pgBusiness)
score_pgLIS = Scoring.UpdateScore(Me.pgLIS)
score_pgAcademic = Scoring.UpdateScore(Me.pgAcademic)
score_pgRegulatory = Scoring.UpdateScore(Me.pgRegulatory)
intTotalScore += (score_pgPatientCare + score_pgBusiness + score_pgLIS + score_pgAcademic + score_pgRegulatory)
Using dbTPT As New BGL_ApplicationsEntities
'** Use this area if needing to calculate more than YES/NO
'**********************
'*** Patient Care ***
'**********************
If chkPatientCare_IRB.Checked Then
If Not txtPatientCare_IRB.Text.Trim = "" Then
Dim propertyName = "PatientCare_IRB_Approved"
intScore = CType(weightSettings.Items.Item(propertyName), Integer)
score_pgPatientCare += intScore
intTotalScore += intScore
End If
End If
'**********************
'*** Business ***
'**********************
If chkBusiness_Replace.Checked Then
If chkBusiness_Outdated.Checked Or
chkBusiness_Inferior.Checked Or
chkBusiness_Savings.Checked Then
intScore = 0
Dim propertyName = "Business_Replace_Just"
intScore = CType(weightSettings.Items.Item(propertyName), Integer)
score_pgBusiness += intScore
intTotalScore += intScore
End If
End If
End Using
ssLabel.Text = "Total Score: " + intTotalScore.ToString
custProgBar.Value = intTotalScore
Dim pg As Integer = Me.tabDetails.SelectedIndex
Select Case pg
Case 0
Me.txtPageScore.Text = score_pgPatientCare
Case 1
Me.txtPageScore.Text = score_pgBusiness
Case 2
Me.txtPageScore.Text = score_pgLIS
Case 3
Me.txtPageScore.Text = score_pgAcademic
Case 4
Me.txtPageScore.Text = score_pgRegulatory
End Select
Vars.DisableEvents = False
End Sub
5)上面的代码为每个选项卡触发此代码:
Module Scoring
Public Function UpdateScore(ByVal tab As TabPage) As Integer
Dim intPgScore As Integer = 0
Dim intScore As Integer = 0
Dim intMult As Integer = 0
Dim arrPropName() As String
Dim strPropName As String
Dim strYesNo As String = Nothing
'If Vars.DisableEvents Then Return 0
'Vars.DisableEvents = True
Using dbTPT As New BGL_ApplicationsEntities
If tab.Name = "pgPatient" Then
For Each pan In tab.ChildControls(Of Panel)
If pan.Name.ToString.Substring(0, 6) = "chkgrp" Then
Dim cuScores() As Integer = {0, 0, 0, 0, 0}
Dim i As Integer = 0
For Each chk As CheckBox In pan.ChildControls(Of CheckBox)
If chk.Checked Then
arrPropName = Split(chk.Name.Replace("chk", "").Replace("CU", "PatientCare"), "_")
strPropName = arrPropName(0) + "_" + arrPropName(1)
Dim w = dbTPT.tbl_Weights.FirstOrDefault(Function(n) n.Weight_Name = strPropName)
If w IsNot Nothing Then
intScore = CType(frmNewProject.weightSettings.Items.Item(arrPropName(0) + "_" + arrPropName(1)), Integer)
intMult = CType(frmNewProject.weightSettings.Items.Item(arrPropName(0) + "_" + arrPropName(2)), Integer)
cuScores(i) = intScore * intMult
End If
Else
cuScores(i) = 0
End If
i += 1
Next
For Each txt In pan.ChildControls(Of TextBox)
txt.Text = cuScores.Max.ToString
Next
intPgScore += cuScores.Max
End If
Next
End If
For Each chk As CheckBox In tab.ChildControls(Of CheckBox)
intScore = 0
arrPropName = Split(chk.Name.Replace("chk", ""), "_")
If Not arrPropName(0) = "CU" Then
If chk.Checked Then strYesNo = "_Yes" Else strYesNo = "_No"
strPropName = arrPropName(0) + "_" + arrPropName(1) + strYesNo
Dim w = dbTPT.tbl_Weights.FirstOrDefault(Function(n) n.Weight_Name = strPropName)
If w IsNot Nothing Then
intScore = CType(frmNewProject.weightSettings.Items.Item(strPropName), Integer)
End If
End If
intPgScore += intScore
Next
For Each rad As RadioButton In tab.ChildControls(Of RadioButton)
intScore = 0
arrPropName = Split(rad.Name.Replace("rad", ""), "_", 2)
strPropName = arrPropName(0) + "_" + arrPropName(1)
If rad.Checked Then
Dim w = dbTPT.tbl_Weights.FirstOrDefault(Function(n) n.Weight_Name = strPropName)
If w IsNot Nothing Then
intScore = CType(frmNewProject.weightSettings.Items.Item(arrPropName(0) + "_" + arrPropName(1)), Integer)
End If
End If
intPgScore += intScore
Next
For Each cbox As ComboBox In tab.ChildControls(Of ComboBox)
intScore = 0
If cbox.SelectedIndex > -1 Then
If cbox.SelectedIndex = 0 Then
intScore = 0
Else
strPropName = cbox.Name.Replace("cbox", "") + cbox.SelectedValue
Dim w = dbTPT.tbl_Weights.FirstOrDefault(Function(n) n.Weight_Name = strPropName)
If w IsNot Nothing Then
intScore = CType(frmNewProject.weightSettings.Items.Item(strPropName), Integer)
End If
End If
intPgScore += intScore
End If
Next
End Using
Return intPgScore
End Function
End Module
6) 选定的选项卡被绘制
Private Sub Paint_Tab(sender As Object, e As PaintEventArgs) Handles _
pgAcademic.Paint, pgBusiness.Paint, pgLIS.Paint, pgPatient.Paint, pgRegulatory.Paint
tabDetails.ResumeLayout()
pgAcademic.ResumeLayout()
pgBusiness.ResumeLayout()
pgLIS.ResumeLayout()
pgPatient.ResumeLayout()
pgRegulatory.ResumeLayout()
End Sub