我有一个任务,将单元格位置存储为特定单元格中的注释,但我遇到的情况是CvsInsight::SetComment方法不持久化。
我将表单显示为对话框,其中用户可以更改存储在注释单元格中的单元格位置,当用户单击“保存”按钮时,我将创建自定义类的新实例,将属性设置为新的单元格位置(由用户设置),将DialogResult设置为OK,然后关闭表单。然后在调用ShowDialog的表单中,为自定义类中各自单元格上的每个属性调用SetComment方法。
这就是我在对话框的“保存”按钮中所做的:
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
' Check if the name, username, password, pass, fail, total, reset, and results are all set
Dim invalidFields As List(Of String) = New List(Of String)()
For Each pair In _requiredFields
If (String.IsNullOrWhiteSpace(DirectCast(Controls.Find(pair.Key, True).FirstOrDefault, TextBox).Text)) Then
invalidFields.Add(pair.Value)
End If
Next
If (invalidFields.Any()) Then
MessageBox.Show($"The following required fields are missing a value: {String.Join(", ", invalidFields)}", "Invalid Form", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
' Set the returned object's values, set the dialog result, and then close the dialog
CameraSettings = New CameraSettings() With {
.FailCell = FailCellLocation.Text,
.FocusCell = FocusCell.Text,
.IsVisible = Visibility.Checked,
.PassCell = PassCellLocation.Text,
.ResetCell = ResetCellLocation.Text,
.ResultsCell = ResultsCellLocation.Text,
.TotalCell = TotalCellLocation.Text
}
DialogResult = DialogResult.OK
Close()
End Sub
这就是我在打开对话框的形式中所做的:
Private Sub Settings_Click(sender As Object, e As EventArgs) Handles Settings.Click
Using cameraSettingsDialog As frmCameraSetting = New frmCameraSetting(InsightDisplay.InSight)
With cameraSettingsDialog
If (.ShowDialog = DialogResult.OK) Then
InsightDisplay.InSight.SetComment(New CvsCellLocation(_focusCell), New CvsCellComment(.CameraSettings.FocusCell))
InsightDisplay.InSight.SetComment(New CvsCellLocation(_passCell), New CvsCellComment(.CameraSettings.PassCell))
InsightDisplay.InSight.SetComment(New CvsCellLocation(_failCell), New CvsCellComment(.CameraSettings.FailCell))
InsightDisplay.InSight.SetComment(New CvsCellLocation(_totalCell), New CvsCellComment(.CameraSettings.TotalCell))
InsightDisplay.InSight.SetComment(New CvsCellLocation(_resultCell), New CvsCellComment(.CameraSettings.ResultsCell))
InsightDisplay.InSight.SetComment(New CvsCellLocation(_resetCell), New CvsCellComment(.CameraSettings.ResetCell))
GetSettingCells()
End If
End With
End Using
End Sub
正在发生的情况是,代码执行时不抛出任何异常,但未设置注释。令人沮丧的是,我无法调试,因为每当我试图在设置注释的过程中访问结果时,CvsInsightDisplay的Insight就会被设置为null。但是,我可以验证CameraSettings的属性是否与我所期望的一样,因为如果我设置一个Console.WriteLine
来打印各种属性,它们是正确的。
纵观SDK,我找不到任何文档,说明为什么在不抛出异常的情况下它不会设置值。
发布于 2020-05-28 04:27:59
对于那些遇到同样问题的人,这个问题是围绕着这样一个事实解决的,那就是我试图设置一个超过作业最大行的单元格。要解决这个问题,我必须将要为其设置注释的单元格更改为行索引较低的单元格。
不幸的是,康耐视的任何文档中都没有记录这种行为。
https://stackoverflow.com/questions/62056249
复制相似问题