I have GaugeControl
having three gauges in its collection. I have written its double click event handler as follows:
AddHandler gc.DoubleClick, AddressOf HandleGaugeDoubleClick
Private Sub HandleGaugeDoubleClick(sender As Object, e As EventArgs)
'Gauge Information
End Sub
where gc is decalred to be of type GaugeControl and three GaugeControls have been added in it.
My question is, how I can get the information of which Gauge has been double clicked?
Note that these gauges are in one GaugeControl and added one by one in its collection. How will I be able to obtain the info of the Gauges that was double clicked.
EDIT
First time, this code snippet runs fine, but gives NullReferenceException
second time when clicked on same Gauge.
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
Here variable hi
becomes null/Nothing second time when double clicked on same Gauge. As hi
becomes Nothing so condition becomes false and remaining code produces NullReferenceException
.
See this code snippet:
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
Where cGaugeToBeShown is Dim cGaugeToBeShown As New CircularGauge
.