![](/img/trans.png)
[英]DataBound UserControl and PropertyNameChanged Event problem in .net winforms
[英]VB.Net UserControl Closing Event in Winforms
我試圖從DevExpress網格控件中保存一些布局,以便用戶可以更改布局並在以后使用該控件時重新加載它們。
我的問題是速度問題,我正在通過表單內的用戶控件加載控件。 現在,我的問題是,通過使該控件的一個實例顯示在該選項卡組控件內部的面板控件中,然后將該控件的實例添加到選項卡組控件中,然后在隱藏該控件時清除該控件,來創建控件。
If ClaimsGridPanelControl.Visible = True Then
ClaimsGridPanelControl.Controls.Add(New RXClaimsGridControl(ClaimsBindingSource))
Else
ClaimsGridPanelControl.Controls.Clear()
End If
因此,在清除控件時,需要在RxClaimGridControl內部調用SaveLayout方法。 但是沒有事件(至少我可以找到)在刪除/關閉/隱藏用戶控件時觸發。
我對處理.Clear()的想法是在父控件中引發一個事件,然后在用戶控件中處理該事件。
關於刪除/關閉/隱藏用戶控件,我是否缺少某些事件,或者有更好的方法來執行此操作?
重寫UserControl的Dispose
或OnHandleDestroyed
方法。
我在http://lukhezo.com/2007/10/10/usercontrol-closing-event/找到了
Protected Overloads Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
AddHandler Me.ParentForm.FormClosing, AddressOf ParentForm_FormClosing
End Sub
Private Sub ParentForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
If MessageBox.Show("Would you like to close the parent form?", "Close parent form?", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
e.Cancel = True
End If
End Sub
然后,您可以在ParentForm_FormClosing事件中調用client.Close()(或所需的任何操作),而不是MessageBox.Show()。
我的評論:您可以將AddHandler語句放在UserControl Load事件中。
盡管這個問題是5年前提出的,但我認為這種解決方案很好。
我相信您從錯誤的位置調用了SaveLayout()。 僅當對DXGrid本身進行更改且與面板無關時,才應保存布局。
您可以通過處理
GridView_ShowCustomizationForm
樣例代碼
Private Sub GridView_ShowCustomizationForm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridView.ShowCustomizationForm
Dim gView As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
AddHandler gView.CustomizationForm.FormClosing, AddressOf SaveGridSettings
End Sub
Private Sub SaveGridSettings()
Grid.MainView.SaveLayoutToXml("c:\Settings.xml")
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.