видимо before не такой уж и before. должно быть текст передаётся для редактирования ДО вызова события.
могу предложить только извратиться так:
- Код: Выделить всё
Public Class Form1
Private Class Renamer
Public Event AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs)
Public Event BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs)
Dim WithEvents trv As TreeView
Dim WithEvents tmr As Timer
Dim n As TreeNode
Public Sub New(ByVal n_trv As TreeView)
trv = n_trv
trv.LabelEdit = False
tmr = New Timer
tmr.Interval = 1000
End Sub
Private Sub trv_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles trv.AfterLabelEdit
trv.LabelEdit = False
RaiseEvent AfterLabelEdit(trv, e)
End Sub
Private Sub trv_MouseCaptureChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trv.MouseCaptureChanged
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
Dim ev As New NodeLabelEditEventArgs(n)
RaiseEvent BeforeLabelEdit(trv, ev)
trv.LabelEdit = True
n.BeginEdit()
tmr.Enabled = False
n = Nothing
End Sub
Private Sub trv_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles trv.NodeMouseClick
If e.Node IsNot Nothing Then
If e.Node.Equals(n) Then
tmr.Enabled = True
Exit Sub
Else
n = e.Node
Exit Sub
End If
End If
n = Nothing
End Sub
End Class
Dim WithEvents supa As Renamer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
supa = New Renamer(TreeView1)
End Sub
Private Sub supa_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles supa.AfterLabelEdit
Beep()
End Sub
Private Sub supa_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles supa.BeforeLabelEdit
e.Node.Text = "!!!"
End Sub
End Class
глючить, правда, будет падла...