Перекинуть Label из окна в контейнер пользовательского контрола - VB
Формулировка задачи:
Добрый день
сейчас самостоятельно разрабатываю
компонент Спойлер..
исходники здесь
модификация здесь:
так вот, есть ли нормальный способ чтоб перекинуть лейбл из окна
в контейнер пользовательского контрола
Там проблемное место, это 101-я строчка, в модуле UserControl'а
..Какие будут предложения коллеги ?
вот как я придумал пока сделать, но это решение меня мало радует
Решение задачи: «Перекинуть Label из окна в контейнер пользовательского контрола»
textual
Листинг программы
Option Explicit
'
' © Антихакер32™
'
'
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'
Public Enum FlagsSpoilerStyle
[По умолчанию] = 0
[Кнопка слева] = 1
End Enum
'
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Sub SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
'
'Default Property Values:
Const m_def_Style = 0
Const def_Exp = 280 'Высота кнопки
Const HWND_TOPMOST = -1
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_TOOLWINDOW = 128
'Property Variables:
Dim m_Style As FlagsSpoilerStyle
Dim WithEvents cm1 As CommandButton
Dim sh1 As Shape
Dim mSpoilerAction As Boolean
Dim oldParRect As RECT, mRect As RECT
Dim ResizeAction As Boolean
Public Sub WActivate()
On Error GoTo errr
If SpoilerAction Then SpoilerAction = False
errr:
End Sub
Public Sub WMove()
Static Rect1 As RECT, Rect2 As RECT
On Error GoTo errr
If mSpoilerAction Then
GetWindowRect Parent.hWnd, Rect1
GetWindowRect hWnd, Rect2
With Rect2
.Left = .Left + (Rect1.Left - oldParRect.Left)
.Top = .Top + (Rect1.Top - oldParRect.Top)
SetWindowPos hWnd, -1, .Left, .Top, 0, 0, SWP_NOSIZE
End With
oldParRect = Rect1
End If
errr:
End Sub
Private Property Get SpoilerAction() As Boolean
SpoilerAction = mSpoilerAction
End Property
Private Property Let SpoilerAction(ByVal vNewValue As Boolean)
Static Rect1 As RECT, Rect2 As RECT, Rect3 As RECT, Border&
On Error GoTo errr
GetWindowRect Parent.hWnd, Rect1
GetWindowRect hWnd, Rect2
ResizeAction = True
If vNewValue Then
With Rect2
.Left = Rect1.Left + (.Left - Rect1.Left)
.Top = Rect1.Top + (.Top - Rect1.Top)
SetWindowPos hWnd, 0, .Left, .Top, 0, 0, SWP_NOSIZE
SetParent hWnd, 0
oldParRect = Rect1
End With
Select Case m_Style
Case [По умолчанию]: Height = sh1.Height
Case [Кнопка слева]: Width = sh1.Width
End Select
Else
GetClientRect Parent.hWnd, Rect3
With Rect2
.Left = (.Left - (Rect1.Right - Rect3.Right))
.Left = .Left + (mRect.Left - .Left)
.Top = (.Top - (Rect1.Bottom - Rect3.Bottom))
.Top = .Top + (mRect.Top - .Top)
SetParent hWnd, Parent.hWnd
SetWindowPos hWnd, 0, .Left, .Top, 0, 0, SWP_NOSIZE
End With
Select Case m_Style
Case [По умолчанию]: Height = def_Exp
Case [Кнопка слева]: Width = def_Exp
End Select
End If
mSpoilerAction = vNewValue
errr:
ResizeAction = False
End Property
Private Sub cm1_Click()
SpoilerAction = Not SpoilerAction
End Sub
Private Sub UserControl_Initialize()
Set cm1 = Controls.Add("vb.CommandButton", "cm1_" & hWnd)
Set sh1 = Controls.Add("vb.Shape", "sh1_" & hWnd)
sh1.Visible = 1: cm1.Visible = 1
SetWindowLong hWnd, GWL_EXSTYLE, _
GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
If ResizeAction Then Exit Sub
With mRect
If Not mSpoilerAction Then
sh1.Move 0, 0, Width, Height
.Left = Extender.Left \ Screen.TwipsPerPixelX
.Top = Extender.Top \ Screen.TwipsPerPixelY
End If
Select Case m_Style
Case [По умолчанию]: cm1.Move 0, 0, sh1.Width, def_Exp
Case [Кнопка слева]: cm1.Move 0, 0, def_Exp, sh1.Height
End Select
End With
End Sub
Private Sub UserControl_Show()
Dim o As Object
If Ambient.UserMode Then
SpoilerAction = 1
Hook Extender
End If
End Sub
Private Sub UserControl_Terminate()
UnHook
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=8,0,0,0
Public Property Get Style() As FlagsSpoilerStyle
Style = m_Style
End Property
Public Property Let Style(ByVal New_Style As FlagsSpoilerStyle)
m_Style = New_Style
PropertyChanged "Style"
UserControl_Resize
End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_Style = m_def_Style
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Style = PropBag.ReadProperty("Style", m_def_Style)
UserControl_Resize
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
End Sub