Hscrollbar

ffaabbss Messages postés 17 Date d'inscription mercredi 20 octobre 2004 Statut Membre Dernière intervention 22 février 2005 - 27 déc. 2004 à 13:03
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 - 3 janv. 2005 à 16:03
bonjour,
voila je suis en train de programmer un planning mais le probleme c'est que tout ne tient pas dans ma form. j'ai fait mon planning avec des picturebox de facon a ce que les personnes cochent simplement leurs zones horaires. Donc j'aimerai savoir comment on fait pour mettre tout mon planning dans une zone controler par un hscrollbar.

Merci pour vos reponses.

9 réponses

philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
28 déc. 2004 à 12:01
sur un form:
- un VScroll (nommé: VScroll1)
- un HScroll (nommé: HScroll1)
- un PictureBox (nommé:Picture1)

... et le code suivant:

Option Explicit

Private Const SCROLLSENS As Long = 500
Private iTop  As Long
Private iLeft As Long

Private Sub Form_Load()
    iTop = Me.Picture1.Top
    iLeft = Me.Picture1.Left
    
    Call SetScrollPositions
    Call SetScrollValues
End Sub

Private Sub Form_Resize()
    Call SetScrollPositions
    Call SetScrollValues
End Sub

Private Sub SetScrollPositions()
    ' scroll V
    Me.VScroll1.Top = 0
    Me.VScroll1.Height = Me.ScaleHeight - Me.HScroll1.Height
    Me.VScroll1.Left = Me.ScaleWidth - Me.VScroll1.Width
    ' scroll H
    Me.HScroll1.Left = 0
    Me.HScroll1.Width = Me.ScaleWidth - Me.VScroll1.Width
    Me.HScroll1.Top = Me.ScaleHeight - Me.HScroll1.Height
End Sub

Private Sub SetScrollValues()
    Dim x As Long
    Dim y As Long
    x = -(Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width)
    y = -(Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height)
    ' scroll V
    Me.VScroll1.Enabled = (y > 0)
    Me.VScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
    ' scroll H
    Me.HScroll1.Enabled = (x > 0)
    Me.HScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
End Sub

Private Sub HScroll1_Change()
    If Me.HScroll1.Value = Me.HScroll1.Max Then
        Me.Picture1.Left = Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width
    Else
        Me.Picture1.Left = iLeft - (Me.HScroll1.Value * SCROLLSENS)
    End If
End Sub

Private Sub VScroll1_Change()
    If Me.VScroll1.Value = Me.VScroll1.Max Then
        Me.Picture1.Top = Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height
    Else
        Me.Picture1.Top = iTop - (Me.VScroll1.Value * SCROLLSENS)
    End If
End Sub



La position initiale de tes controls ne joue aucune importance: le code les place au bons endroits.
0
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
28 déc. 2004 à 12:10
remplace le procédure "SetScrollValues" par le code suivant:

Private Sub SetScrollValues()
    Dim x As Long
    Dim y As Long
    x = -(Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width)
    y = -(Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height)
    ' scroll V
    Me.VScroll1.Enabled = (y > 0)
    Me.VScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
    ' scroll H
    Me.HScroll1.Enabled = (x > 0)
    Me.HScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
    ' align picture at 0,0
    If Not Me.VScroll1.Enabled Then Me.Picture1.Top = iTop
    If Not Me.HScroll1.Enabled Then Me.Picture1.Left = iLeft
End Sub
0
ffaabbss Messages postés 17 Date d'inscription mercredi 20 octobre 2004 Statut Membre Dernière intervention 22 février 2005
3 janv. 2005 à 10:00
Ok Merci philheiz,
mais mon but est de pouvoir faire bouger horizontalement une zone de ma form qui contient plein de picturebox.. mon planning est tellement detaillé qu'il ne tient pas horizontalement sur toute ma feuille. De plus j'ai choisi des picturebox car je peux les faire changer de couleur lorsque l'utilisateur clique dessus, contrairement aux checkbox.
Donc ma question est : peut-on faire bouger une zone qui contient deja des picturebox?
0
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
3 janv. 2005 à 11:10
plutôt que d'utiliser une form comme conteneur, tu utilises p.ex. un picturebox.

tu reprends le code ci-dessus, tu colles tous les controls dans un nouveau picturebox (picture2) et tu remplaces tous les "Me.ScaleHeight" et autres "scale" par "Me.picture2.ScaleHeight".

le principe est le même.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ffaabbss Messages postés 17 Date d'inscription mercredi 20 octobre 2004 Statut Membre Dernière intervention 22 février 2005
3 janv. 2005 à 11:29
Ok philheiz,
je ne peux pas tester le code tout de suite, je le ferai ce soir. Mais pour coller mes picturebox dans le principal, faut-il lui activer une propriété spéciale?
0
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
3 janv. 2005 à 12:29
non
0
ffaabbss Messages postés 17 Date d'inscription mercredi 20 octobre 2004 Statut Membre Dernière intervention 22 février 2005
3 janv. 2005 à 14:53
je viens de tester (car j'avais un peu de temps) mais ca ne fonctionne pas. Les scrollbars verticaux et horizontaux se collent directement à la fenetre et non au picturebox. Dans ton code "Me" est le nom de ta fenetre?
0
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
3 janv. 2005 à 16:01
voilà la marche à suivre:

sur un form:
- un PictureBox (nommé:picMain)

dans picMain:
- un VScroll (nommé: VScroll1)
- un HScroll (nommé: HScroll1)
- un PictureBox (nommé:Picture1)

... et le code suivant dans le From:

Option Explicit

Private Const SCROLLSENS As Long = 500
Private iTop As Long
Private iLeft As Long

Private Sub Form_Load()
Me.Picture1.Top = 0
Me.Picture1.Height = 2 * Me.picMain.Height
Me.Picture1.Left = 0
Me.Picture1.Width = 2 * Me.picMain.Width

iTop = Me.Picture1.Top
iLeft = Me.Picture1.Left

Me.VScroll1.ZOrder
Me.HScroll1.ZOrder

Call SetScrollPositions
Call SetScrollValues
End Sub

Private Sub Form_Resize()
Call SetScrollPositions
Call SetScrollValues
End Sub


Private Sub SetScrollPositions()
' scroll V
Me.VScroll1.Top = 0
Me.VScroll1.Height = picMain.ScaleHeight - Me.HScroll1.Height
Me.VScroll1.Left = picMain.ScaleWidth - Me.VScroll1.Width
' scroll H
Me.HScroll1.Left = 0
Me.HScroll1.Width = picMain.ScaleWidth - Me.VScroll1.Width
Me.HScroll1.Top = picMain.ScaleHeight - Me.HScroll1.Height
End Sub

Private Sub SetScrollValues()
Dim x As Long
Dim y As Long
x = -(Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width)
y = -(Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height)
' scroll V
Me.VScroll1.Enabled = (y > 0)
Me.VScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
' scroll H
Me.HScroll1.Enabled = (x > 0)
Me.HScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS)
' align picture at 0,0
If Not Me.VScroll1.Enabled Then Me.Picture1.Top = iTop
If Not Me.HScroll1.Enabled Then Me.Picture1.Left = iLeft
End Sub

Private Sub HScroll1_Change()
If Me.HScroll1.Value = Me.HScroll1.Max Then
Me.Picture1.Left = Me.picMain.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width
Else
Me.Picture1.Left = iLeft - (Me.HScroll1.Value * SCROLLSENS)
End If
End Sub

Private Sub VScroll1_Change()
If Me.VScroll1.Value = Me.VScroll1.Max Then
Me.Picture1.Top = Me.picMain.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height
Else
Me.Picture1.Top = iTop - (Me.VScroll1.Value * SCROLLSENS)
End If
End Sub
0
philheiz Messages postés 117 Date d'inscription mercredi 3 décembre 2003 Statut Membre Dernière intervention 11 octobre 2007 1
3 janv. 2005 à 16:03
oups ...

file-moi ton mail et je t'envoie la source.
0
Rejoignez-nous