Oliv'
-
11 janv. 2001 à 23:11
rebixav
Messages postés130Date d'inscriptiondimanche 16 décembre 2007StatutMembreDernière intervention28 janvier 2013
-
17 août 2012 à 08:47
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
rebixav
Messages postés130Date d'inscriptiondimanche 16 décembre 2007StatutMembreDernière intervention28 janvier 2013 17 août 2012 à 08:47
En faite c'est très bien, car on ne peut pas changer "StartUpPosition " une fois le projet exécuté !
j'en ais même améliorer le concept sur les FORM, picture, et Fram :
dans un module, au niveau des déclaration mettre cela :
Public Sub align_form(la_form As Form, alignment As alignment_align_picture_)
la_form.Refresh
Select Case alignment
Case 0
la_form.Left = 0
Case 1
la_form.Left = Screen.Width - la_form.Width
Case 2
la_form.Left = (Screen.Width - la_form.Width) \ 2
Case 3
la_form.Top = 0
Case 4
la_form.Top = Screen.Height - la_form.Height
Case 5
la_form.Top = (Screen.Height - la_form.Height) \ 2
Case 6
la_form.Left = (Screen.Width - la_form.Width) \ 2
la_form.Top = (Screen.Height - la_form.Height) \ 2
End Select
la_form.Refresh
End Sub
Public Sub align_picture(la_picture As PictureBox, dans_la_form As Form, alignment As alignment_align_picture_)
la_picture.Refresh
rx12! = dans_la_form.Width / dans_la_form.ScaleWidth
ry12! = dans_la_form.Height / dans_la_form.ScaleHeight
Select Case alignment
Case 0
la_picture.Left = 0
Case 1
la_picture.Left = (dans_la_form.Width - (la_picture.Width * rx12!)) / rx12!
Case 2
la_picture.Left = ((dans_la_form.Width - (la_picture.Width * rx12!)) \ 2) / rx12!
Case 3
la_picture.Top = 0
Case 4
la_picture.Top = (dans_la_form.Height - (la_picture.Height * ry12!)) / ry12!
Case 5
la_picture.Top = ((dans_la_form.Height - (la_picture.Height * ry12!)) \ 2) / ry12!
Case 6
la_picture.Left = ((dans_la_form.Width - (la_picture.Width * rx12!)) \ 2) / rx12!
la_picture.Top = ((dans_la_form.Height - (la_picture.Height * ry12!)) \ 2) / ry12!
End Select
la_picture.Refresh
End Sub
Public Sub align_frame(la_frame As Frame, dans_la_form As Form, alignment As alignment_align_picture_)
la_frame.Refresh
rx12! = dans_la_form.Width / dans_la_form.ScaleWidth
ry12! = dans_la_form.Height / dans_la_form.ScaleHeight
Select Case alignment
Case 0
la_frame.Left = 0
Case 1
la_frame.Left = (dans_la_form.Width - (la_frame.Width * rx12!)) / rx12!
Case 2
la_frame.Left = ((dans_la_form.Width - (la_frame.Width * rx12!)) \ 2) / rx12!
Case 3
la_frame.Top = 0
Case 4
la_frame.Top = (dans_la_form.Height - (la_frame.Height * ry12!)) / ry12!
Case 5
la_frame.Top = ((dans_la_form.Height - (la_frame.Height * ry12!)) \ 2) / ry12!
Case 6
la_frame.Left = ((dans_la_form.Width - (la_frame.Width * rx12!)) \ 2) / rx12!
la_frame.Top = ((dans_la_form.Height - (la_frame.Height * ry12!)) \ 2) / ry12!
End Select
la_frame.Refresh
End Sub
...
Et voilà amusez vous bien !
Au faite comment on fait pour déposer comme là un fichier ZIP pour partager nos projet sur le SITE VBFRANCE.FR ?
merci de me répondre, please :)
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 1 juin 2007 à 06:50
bien d'accord avec EuroLolo, la propriété StartUpPosition sur CenterScreen, emballé c'est pesé ^^
Le Papa de Thibaut
Messages postés53Date d'inscriptionmercredi 22 novembre 2006StatutMembreDernière intervention 7 mars 20151 1 juin 2007 à 06:33
ce code est tres bien inutile de compliquer la procedure par un
"fCenterForm Me"
Osiris6880
Messages postés36Date d'inscriptionvendredi 29 octobre 2004StatutMembreDernière intervention 7 décembre 2007 11 févr. 2006 à 15:05
Ce code est très simple et fonctionne très bien, moi je m'est 10 !!!!
MasterGone
Messages postés8Date d'inscriptionlundi 9 octobre 2000StatutMembreDernière intervention 4 janvier 2004 25 mars 2002 à 09:59
Il y a bcp plus simple : il suffit de modifier la propriété StartUpPosition
C'est bon, mais ce n'est pas tout à fait juste, je propose d'essayer le code suivant :
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
ByVal uAction As Long, _
ByVal uParam As Long, _
ByRef lpvParam As Any, _
ByVal fuWinIni As Long) _
As Long
Const SPI_GETWORKAREA = 48
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Function fCenterForm(ByVal frm As Form)
Dim tR As RECT, lngRep As Long
lngRep = SystemParametersInfo(SPI_GETWORKAREA, 0, tR, 0&) 'place dans tR le rectangle utilisable de l'écran
If lngRep <> 0 Then
frm.Left = ScaleX(((tR.Right - tR.Left) - ScaleX(frm.Width, frm.ScaleMode, vbPixels)) / 2, vbPixels, frm.ScaleMode) 'on fait les conversions pour être en pixels
frm.Top = ScaleY(((tR.Bottom - tR.Top) - ScaleY(frm.Height, frm.ScaleMode, vbPixels)) / 2, vbPixels, frm.ScaleMode)
End If
End Function
17 août 2012 à 08:47
j'en ais même améliorer le concept sur les FORM, picture, et Fram :
dans un module, au niveau des déclaration mettre cela :
Public Enum alignment_align_picture_
Left_justify = 0
right_justify = 1
center_justify = 2
up_justify = 3
down_justify = 4
center_height_justify = 5
the_center_justify = 6
End Enum
Public Sub align_form(la_form As Form, alignment As alignment_align_picture_)
la_form.Refresh
Select Case alignment
Case 0
la_form.Left = 0
Case 1
la_form.Left = Screen.Width - la_form.Width
Case 2
la_form.Left = (Screen.Width - la_form.Width) \ 2
Case 3
la_form.Top = 0
Case 4
la_form.Top = Screen.Height - la_form.Height
Case 5
la_form.Top = (Screen.Height - la_form.Height) \ 2
Case 6
la_form.Left = (Screen.Width - la_form.Width) \ 2
la_form.Top = (Screen.Height - la_form.Height) \ 2
End Select
la_form.Refresh
End Sub
Public Sub align_picture(la_picture As PictureBox, dans_la_form As Form, alignment As alignment_align_picture_)
la_picture.Refresh
rx12! = dans_la_form.Width / dans_la_form.ScaleWidth
ry12! = dans_la_form.Height / dans_la_form.ScaleHeight
Select Case alignment
Case 0
la_picture.Left = 0
Case 1
la_picture.Left = (dans_la_form.Width - (la_picture.Width * rx12!)) / rx12!
Case 2
la_picture.Left = ((dans_la_form.Width - (la_picture.Width * rx12!)) \ 2) / rx12!
Case 3
la_picture.Top = 0
Case 4
la_picture.Top = (dans_la_form.Height - (la_picture.Height * ry12!)) / ry12!
Case 5
la_picture.Top = ((dans_la_form.Height - (la_picture.Height * ry12!)) \ 2) / ry12!
Case 6
la_picture.Left = ((dans_la_form.Width - (la_picture.Width * rx12!)) \ 2) / rx12!
la_picture.Top = ((dans_la_form.Height - (la_picture.Height * ry12!)) \ 2) / ry12!
End Select
la_picture.Refresh
End Sub
Public Sub align_frame(la_frame As Frame, dans_la_form As Form, alignment As alignment_align_picture_)
la_frame.Refresh
rx12! = dans_la_form.Width / dans_la_form.ScaleWidth
ry12! = dans_la_form.Height / dans_la_form.ScaleHeight
Select Case alignment
Case 0
la_frame.Left = 0
Case 1
la_frame.Left = (dans_la_form.Width - (la_frame.Width * rx12!)) / rx12!
Case 2
la_frame.Left = ((dans_la_form.Width - (la_frame.Width * rx12!)) \ 2) / rx12!
Case 3
la_frame.Top = 0
Case 4
la_frame.Top = (dans_la_form.Height - (la_frame.Height * ry12!)) / ry12!
Case 5
la_frame.Top = ((dans_la_form.Height - (la_frame.Height * ry12!)) \ 2) / ry12!
Case 6
la_frame.Left = ((dans_la_form.Width - (la_frame.Width * rx12!)) \ 2) / rx12!
la_frame.Top = ((dans_la_form.Height - (la_frame.Height * ry12!)) \ 2) / ry12!
End Select
la_frame.Refresh
End Sub
...
Et voilà amusez vous bien !
Au faite comment on fait pour déposer comme là un fichier ZIP pour partager nos projet sur le SITE VBFRANCE.FR ?
merci de me répondre, please :)
1 juin 2007 à 06:50
1 juin 2007 à 06:33
"fCenterForm Me"
11 févr. 2006 à 15:05
25 mars 2002 à 09:59
11 janv. 2001 à 23:11
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
ByVal uAction As Long, _
ByVal uParam As Long, _
ByRef lpvParam As Any, _
ByVal fuWinIni As Long) _
As Long
Const SPI_GETWORKAREA = 48
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Function fCenterForm(ByVal frm As Form)
Dim tR As RECT, lngRep As Long
lngRep = SystemParametersInfo(SPI_GETWORKAREA, 0, tR, 0&) 'place dans tR le rectangle utilisable de l'écran
If lngRep <> 0 Then
frm.Left = ScaleX(((tR.Right - tR.Left) - ScaleX(frm.Width, frm.ScaleMode, vbPixels)) / 2, vbPixels, frm.ScaleMode) 'on fait les conversions pour être en pixels
frm.Top = ScaleY(((tR.Bottom - tR.Top) - ScaleY(frm.Height, frm.ScaleMode, vbPixels)) / 2, vbPixels, frm.ScaleMode)
End If
End Function
'Votre fenêtre sera véritablement centrée.
Private Sub Form_Load()
fCenterForm Me
End Sub