感谢 DJ KRAZE 的建议,我明白了。
在存储库 TextEdit 的 EditValueChanging 事件中,我将 e.NewValue 分配给 DevExpress 标签并将其 PreferredSize.Widht 与列 Width 进行比较。如果它更大,我会删除字符,直到它更小并将文本分配给 e.NewValue。
光标跳到 0,所以(根据 DevExpress 常见问题解答)我必须执行调用来更改 TextEdit.SelectionStart 属性。该死!VB-2008 不接受匿名方法,必须把它分开 :)
谢谢。
问候。
Private Sub RepositoryItemTextEditDescrip_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemTextEditDescrip.EditValueChanging
Static lbl As New DevExpress.XtraEditors.LabelControl
Dim tx As DevExpress.XtraEditors.TextEdit = sender
Dim s As String = e.NewValue.ToString.Split(vbCr)(0)
lbl.Text = s
lbl.Font = tx.Font
If lbl.PreferredSize.Width >= colDescrip.Width - 15 Then
Do Until lbl.PreferredSize.Width <= colDescrip.Width - 15 Or s.Length = 0
s = s.Remove(s.Length - 1)
lbl.Text = s
Loop
End If
Dim i As Integer = tx.SelectionStart
e.NewValue = s
BeginInvoke(New Action(Of TextEdit, Integer)(AddressOf sbTxSelectIndx), New Object() {tx, i})
End Sub
Private Sub sbTxSelectIndx(ByVal tx As TextEdit, ByVal i As Integer)
tx.Select(i, 0)
End Sub