我有一项工作,将单元格位置存储为特定单元格中的注释,但我遇到了 CvsInsight::SetComment 方法不持久的情况。
我将表单显示为对话框,其中用户可以更改存储在注释单元格中的单元格位置,当用户单击“保存”按钮时,我将创建自定义类的新实例,设置属性到新的单元格位置(由用户设置),将 DialogResult 设置为“确定”,然后关闭表单。然后,在我调用 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,我找不到任何文档说明为什么它不会在不引发异常的情况下设置该值。
最佳答案
对于那些遇到同样问题的人来说,问题解决了,因为我试图设置一个超过作业中最大行的单元格。为了解决这个问题,我必须将设置注释的单元格更改为行索引较低的单元格。
不幸的是,康耐视在其任何文档中都没有记录这种行为。
关于vb.net - Cognex Insight SetComment 不持久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62056249/