This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyPopupHelper.vb
89 lines (68 loc) · 2.12 KB
/
MyPopupHelper.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Namespace MyComboBoxEdit
Public Class MyPopupHelper
Private handleGotFocus As EventHandler
Private scrControl As ScrollableControl
Public Sub New(ByVal scrControl As ScrollableControl)
handleGotFocus = Nothing
Me.scrControl = Nothing
If scrControl IsNot Nothing Then
handleGotFocus = New EventHandler(AddressOf OnGotFocus)
Me.scrControl = scrControl
SetEvents(Me.scrControl)
End If
End Sub
Private Sub SetEvents(ByVal sContrl As ScrollableControl)
For Each contr As Control In sContrl.Controls
Dim s_contrl As ScrollableControl = TryCast(contr, ScrollableControl)
If s_contrl IsNot Nothing Then
SetEvents(s_contrl)
Continue For
End If
Dim pbe As PopupBaseEdit = TryCast(contr, PopupBaseEdit)
If pbe Is Nothing Then
Continue For
End If
AddHandler pbe.GotFocus, handleGotFocus
Next contr
End Sub
Private Sub UnsetEvents(ByVal sContrl As ScrollableControl)
For Each contr As Control In sContrl.Controls
Dim s_contrl As ScrollableControl = TryCast(contr, ScrollableControl)
If s_contrl IsNot Nothing Then
UnsetEvents(s_contrl)
Continue For
End If
Dim pbe As PopupBaseEdit = TryCast(contr, PopupBaseEdit)
If pbe Is Nothing Then
Continue For
End If
RemoveHandler pbe.GotFocus, handleGotFocus
Next contr
End Sub
Private Sub OnGotFocus(ByVal sender As Object, ByVal e As EventArgs)
TryCast(sender, Control).BeginInvoke(New MethodInvoker(Function() AnonymousMethod1(sender)))
End Sub
Private Function AnonymousMethod1(ByVal sender As Object) As Boolean
Dim editor As PopupBaseEdit = TryCast(sender, PopupBaseEdit)
If editor.IsPopupOpen Then
editor.ClosePopup()
editor.ShowPopup()
End If
Return True
End Function
Protected Overrides Sub Finalize()
If scrControl IsNot Nothing AndAlso handleGotFocus IsNot Nothing Then
Try
UnsetEvents(scrControl)
Catch
End Try
End If
End Sub
End Class
End Namespace