0

有人可以帮助在 vb.net 中的 XTRAFORM 中迭代 DevExpress TextEdit 控件吗?

我实际上想要做的是通过使用 EditValue 和 OldEditValue 属性来拦截 FormClosing 事件中的任何值更改。

我可能需要告诉我我的控件包含在 XtraTab 和 XtraPanel 容器中。

以下是我尝试过的:

Public Function TextEditChangesOccured(frm As XtraForm) As Boolean
    Dim result As Boolean
    For Each ctrl As BaseEdit In frm.Controls
        If TypeOf ctrl Is TextEdit Then
            If ctrl.EditValue <> ctrl.OldEditValue Then
                result = True
            Else
                result = False
            End If
        End If
    Next
    Return result
End Function

 Private Sub MyXtraForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    If TextEditChangesOccured(Me) Then
        DevExpress.XtraEditors.XtraMessageBox.Show("Changes have occured!", My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
End Sub

但它说无法将 XtraTab 控件转换为 TextEdit 控件。

您的帮助将不胜感激。

4

1 回答 1

0

要使您的代码正常工作,只需按如下方式更改您的代码片段:

Public Function TextEditChangesOccured(container As Control) As Boolean
    Dim result As Boolean
    For Each ctrl As Control In container.Controls
        Dim bEdit As BaseEdit = TryCast(ctrl, BaseEdit)
        If bEdit IsNot Nothing Then
            Dim tEdit As TextEdit = TryCast(ctrl, TextEdit)
            If tEdit IsNot Nothing Then
                result = result Or (bEdit.EditValue <> bEdit.OldEditValue)
            End If
        Else
            result = result Or TextEditChangesOccured(ctrl)
        End If
    Next
    Return result
End Function

要检测表单中所有编辑器的更改,请使用以下方法:

Partial Public Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
        SubscribeTextEditValueChanged(Me)
    End Sub
    Private Sub SubscribeTextEditValueChanged(ByVal container As Control)
        For Each ctrl As Control In container.Controls
            Dim tEdit As TextEdit = TryCast(ctrl, TextEdit)
            If tEdit IsNot Nothing Then
                AddHandler tEdit.EditValueChanged, AddressOf tEdit_EditValueChanged
            Else
                SubscribeTextEditValueChanged(ctrl)
            End If
        Next ctrl
    End Sub
    Private IsEditValueChanged As Boolean
    Private Sub tEdit_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
        IsEditValueChanged = True
    End Sub
    Protected Overrides Sub OnClosing(ByVal e As CancelEventArgs)
        If IsEditValueChanged Then
            ' do some stuff
        End If
        MyBase.OnClosing(e)
    End Sub
End Class
于 2014-07-14T13:45:23.527 回答