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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| Option Explicit
Private Type POINTAPI
X As Long
y As Long
End Type
Private Type RECT
Bottom As Long
Left As Long
Right As Long
Top As Long
End Type
Private Type WINDOWPLACEMENT
flags As Long
Length As Long
ptMaxPosition As POINTAPI
ptMinPosition As POINTAPI
rcNormalPosition As RECT
showCmd As Long
End Type
Private Declare Function GetWindowPlacement Lib "user32" ( _
ByVal hwnd As Long, _
lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function MoveWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal X As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Dim MeCoord As WINDOWPLACEMENT
Private Type LesCoord
Height As Long
Left As Long
Top As Long
Width As Long
End Type
Dim NewMeCoord As LesCoord
'******************************************************************
'** la propriété ScaleMode de UserControl doit être mis à Pixels **
'** la propriété KeyPreview de UserControl doit être mis à True **
'******************************************************************
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
'recuperation des coordonnées de l'UserControl posé sur le conteneur
GetWindowPlacement UserControl.hwnd, MeCoord
' ne me demandez pas pourquoi (le systeme de calcul bizzard),
'je ne sais pas , deduit apres de nombreux essais
NewMeCoord.Height = MeCoord.showCmd - MeCoord.rcNormalPosition.Right
NewMeCoord.Left = MeCoord.rcNormalPosition.Left
NewMeCoord.Top = MeCoord.rcNormalPosition.Right
NewMeCoord.Width = MeCoord.rcNormalPosition.Top - MeCoord.rcNormalPosition.Left
Select Case KeyCode
Case vbKeyLeft '37 Flèche gauche
If Shift = vbCtrlMask Then 'CTRL
'deplacement vers la gauche
NewMeCoord.Left = NewMeCoord.Left - 1
Else
'diminution en largeur
NewMeCoord.Width = NewMeCoord.Width - 1
End If
Case vbKeyUp '38 Flèche haute
If Shift = vbCtrlMask Then 'CTRL
'deplacement vers le haut
NewMeCoord.Top = NewMeCoord.Top - 1
Else
'diminution en hauteur
NewMeCoord.Height = NewMeCoord.Height - 1
End If
Case vbKeyRight '39 Flèche droite
'Si appui sur Ctrl, agrandissement du contrôle, sinon, déplacement
If Shift = vbCtrlMask Then 'CTRL
'deplacement vers la droite
NewMeCoord.Left = NewMeCoord.Left + 1
Else
'agrandissement en largeur
NewMeCoord.Width = NewMeCoord.Width + 1
End If
Case vbKeyDown '40 Flèche basse
If Shift = vbCtrlMask Then
'deplacement vers la bas
NewMeCoord.Top = NewMeCoord.Top + 1
Else
'agrandissement en hauteur
NewMeCoord.Height = NewMeCoord.Height + 1
End If
End Select
'verifications des coordonnées minimum
If NewMeCoord.Width <= 12 Then NewMeCoord.Width = 13
If NewMeCoord.Left < 1 Then NewMeCoord.Left = 1
If NewMeCoord.Height <= 16 Then NewMeCoord.Height = 17
If NewMeCoord.Top < 1 Then NewMeCoord.Top = 1
'n'est valable que si le contrôle est placé directement sur le Form
'************* à revoire *******************
If NewMeCoord.Left > ScaleX(UserControl.Parent.ScaleWidth, UserControl.Parent.ScaleMode, vbPixels) - NewMeCoord.Width Then
NewMeCoord.Left = ScaleX(UserControl.Parent.ScaleWidth, UserControl.Parent.ScaleMode, vbPixels) - NewMeCoord.Width
End If
If NewMeCoord.Top > ScaleY(UserControl.Parent.ScaleHeight, UserControl.Parent.ScaleMode, vbPixels) - NewMeCoord.Height Then
NewMeCoord.Height = ScaleY(UserControl.Parent.ScaleHeight, UserControl.Parent.ScaleMode, vbPixels) - NewMeCoord.Height
End If
'************* fini à revoire *******************
'met a jour le TextBox
txtText.Move 0, 0, NewMeCoord.Width - 1, NewMeCoord.Height - 1
'met a jour le UserControl
MoveWindow UserControl.hwnd, _
NewMeCoord.Left, NewMeCoord.Top, _
NewMeCoord.Width, NewMeCoord.Height, 1
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
txtText.Width = ScaleX(UserControl.Width, UserControl.Parent.ScaleMode, vbPixels)
txtText.Height = ScaleY(UserControl.Height, UserControl.Parent.ScaleMode, vbPixels)
End Sub |
Partager