我GaugeControl
的收藏中有三个仪表。我已经编写了它的双击事件处理程序,如下所示:
AddHandler gc.DoubleClick, AddressOf HandleGaugeDoubleClick
Private Sub HandleGaugeDoubleClick(sender As Object, e As EventArgs)
'Gauge Information
End Sub
其中 gc 被标记为 GaugeControl 类型,并且其中添加了三个 GaugeControl。
我的问题是,我如何才能获得双击哪个仪表的信息?
请注意,这些仪表位于一个GaugeControl中,并在其集合中一一添加。我将如何获得被双击的仪表的信息。
编辑
第一次,这个代码片段运行良好,但NullReferenceException
第二次点击同一个仪表时会给出第二次。
Dim hi As BasePrimitiveHitInfo = DirectCast(gc, IGaugeContainer).CalcHitInfo(e.Location) ' hi becomes Nothing when double clicked second time on same Gauge
If Not (TypeOf hi.Element Is DevExpress.XtraGauges.Core.Model.BaseGaugeModel) Then
Dim model = DevExpress.XtraGauges.Core.Model.BaseGaugeModel.Find(hi.Element)
If model IsNot Nothing AndAlso model.Owner IsNot Nothing Then
gauge = model.Owner
End If
End If
hi
当双击同一个仪表时,这里的变量第二次变为空/无。当hi
变为Nothing所以条件变为 false 并且剩余的代码产生NullReferenceException
.
请参阅此代码段:
If (Not (gauge.Scales Is Nothing) And (gauge.Scales.Count > 0)) Then ' Actual exception here
For i As Integer = 0 To gauge.Scales.Count - 1
scaleComponent = gauge.Scales(i)
cGaugeToBeShown.Scales.Add(scaleComponent)
Next
End If
cGaugeToBeShown在哪里Dim cGaugeToBeShown As New CircularGauge
。