|
■No19971 (魔界の仮面弁士 さん) に返信 > ■No19970 (jiioi さん) に返信 >>この前、匿名メソッドをVBに置き換える方法を教えていただきましたが、 >>戻り値がある場合はどうしたらいいかおしえていただけないでしょうか? > > VB 側は、Sub が Function に変わるだけで、後は戻り値が無い場合と一緒です。
そうおもって書き換えてみましたが、 Dim callback As TAxisAbstract.DTraceAxisLineCallback = New anonymous(_isSuppressFirst, _isSuppressLast, _axis, g, _pen) この部分で暗黙的な変換が出来ないと怒られました。
Public Sub Draw() If Not _visible Then Return End If
Dim g As Graphics = _core.Graphics
Dim clipBak As Region = g.Clip g.Clip = _plotArea.GetClippingRegion()
Dim callback As TAxisAbstract.DTraceAxisLineCallback = New anonymous(_isSuppressFirst, _isSuppressLast, _axis, g, _pen) _axis.TraceAxisLineCallback(_interval, callback) g.Clip = clipBak End Sub
'匿名メソッド Private Class anonymous
Private t_isSuppressFirst As Boolean Private t_isSuppressLast As Boolean Private t_axis As TAxisAbstract Private tg As Graphics Private t_pen As Pen
Public Sub New(ByVal _isSuppressFirst As Boolean, ByVal _isSuppressLast As Boolean, ByVal _axis As TAxisAbstract, ByVal g As Graphics, ByVal _pen As Pen) t_isSuppressFirst = _isSuppressFirst t_isSuppressLast = _isSuppressLast t_axis = _axis tg = g t_pen = _pen End Sub Public Shared Narrowing Operator CType(ByVal o As anonymous) As TAxisAbstract.DTraceAxisLineCallback Return AddressOf o.callback End Operator Private Function callback(ByVal interval As Double, ByVal value As Double, ByVal point As Point, ByVal isFirst As Boolean, ByVal isLast As Boolean) As Boolean If isFirst AndAlso t_isSuppressFirst Then Return True End If If isLast AndAlso t_isSuppressLast Then Return True End If
t_axis.DrawGridLine(tg, t_pen, point) Return True End Function
|