Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.17.174.239] |
|
Сообщ.
#1
,
|
|
|
Option Explicit '= Как сделать прилипание формы к границам = 'D[u]fa 30.03.04, 19:44 'http://forum.sources.ru/index.php?showtopic=49771 'Значение пикселей, на расстоянии которых форма будет прилипать к границам экрана Private Const Size = 10 Dim SngY As Integer, SngX As Integer Public Sub MoveForm(Frm As Form, X, Y, SngX, SngY) Dim lngLeft As Long, lngTop As Long lngLeft = Frm.Left + (X - SngX) * Screen.TwipsPerPixelX lngTop = Frm.Top + (Y - SngY) * Screen.TwipsPerPixelY If (lngLeft + Frm.Width >= Screen.Width - Size * Screen.TwipsPerPixelX) And _ (lngLeft + Frm.Width <= Screen.Width + Size * Screen.TwipsPerPixelX) Then lngLeft = Screen.Width - Frm.Width ElseIf (lngLeft >= 0 - Size * Screen.TwipsPerPixelX) And _ (lngLeft <= 0 + Size * Screen.TwipsPerPixelX) Then lngLeft = 0 End If If (lngTop + Frm.Height >= Screen.Height - Size * Screen.TwipsPerPixelX) And _ (lngTop + Frm.Height <= Screen.Height + Size * Screen.TwipsPerPixelX) Then lngTop = Screen.Height - Frm.Height ElseIf (lngTop >= 0 - Size * Screen.TwipsPerPixelY) And _ (lngTop <= 0 + Size * Screen.TwipsPerPixelY) Then lngTop = 0 End If Call Frm.Move(lngLeft, lngTop) End Sub Private Sub Form_Load() Me.ScaleMode = vbPixels End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then SngY = Y SngX = X End If End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton And Me.WindowState = vbNormal Then Call MoveForm(Me, X, Y, SngX, SngY) End If End Sub |