LinkExchange Member Free Home Pages at GeoCities

1. Come centrare una form

Sub Form_Load ()
   CenterForm Me
End Sub

Sub CenterForm (f as Form)
   f.Left = (Screen.Width - f.Width) / 2
   f.Top = (Screen.Height - f.Height) / 2
End Sub

N.B. Con VB5 è sufficiente settare la proprietà StartUpPosition della form a 2 - CenterScreen




2. Come ottenere un popup menu

Prima di tutto è necessario creare un menu utilizzando il Menu Editor di VB5 (menu Tools, item Menu Editor, shortcut CTRL+E). Supponiamo che il nome del menu sia mnuPopUp.

Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
   PopUpMenu mnuPopUp
End If
End Sub




3. Come ottenere una form non rettangolare

Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 as Long, _
ByVal Y1 as Long, ByVal X2 as Long, ByVal Y2 as Long) as Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd as Long, _
ByVal hRgn as Long, ByVal bRedraw as Long) as Long

Private Sub Form_Load ()
   Show
   SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 200), True
End Sub




4. Come ottenere una form scrollabile

Private Sub Form_Load()
   Form1.ScaleMode = vbPixels
   With Picture1
      .Move 0, 0
      .BorderStyle = vbBSNone
      .ScaleMode = vbPixels
   End With
End Sub

Private Sub Form_Resize()
Dim bVScrollVisible As Boolean
Dim bHScrollVisible As Boolean

VScroll1.Visible = False
HScroll1.Visible = False

bVScrollVisible = Picture1.ScaleHeight > ScaleHeight - HScroll1.Height
bHScrollVisible = Picture1.ScaleWidth > ScaleWidth - VScroll1.Width
If bVScrollVisible Then
   With VScroll1
      If bHScrollVisible Then
         .Move ScaleWidth - .Width, 0, .Width, ScaleHeight - HScroll1.Height
      Else
         .Move ScaleWidth - .Width, 0, .Width, ScaleHeight
      End If
   End With
End If

If bHScrollVisible Then
   With HScroll1
      If bVScrollVisible Then
         .Move 0, ScaleHeight - .Height, ScaleWidth - VScroll1.Width
      Else
         .Move 0, ScaleHeight - .Height, ScaleWidth
      End If
   End With
End If

With HScroll1
   .Min = 0
   .Max = Picture1.ScaleWidth - ScaleWidth + IIf(bVScrollVisible, VScroll1.Width, 0)
   .Visible = bHScrollVisible
End With

With VScroll1
   .Min = 0
   .Max = Picture1.ScaleHeight - ScaleHeight + IIf(bHScrollVisible, HScroll1.Height, 0)
   .Visible = bVScrollVisible
End With

End Sub






Home Page
This page hosted by Get your own Free Home Page