Bonjour a tout le forum,


J'ai un gros soucis avec la gestion d'un zoom dans mon appli... 5 jours que j'y suis et je m'en sorts pas.

Voila, j'ai:
- un panel (pb) avec autoscroll=false
- une picturebox (piccontainer)
- une scrollbar vertical (VScrollBar1)
- une scrollbar horizontal (HScrollBar1)
- un bouton de zoom + (cmdaction2)
- un bouton de zoom - (cmdaction3)

Le systeme de zoom centré sur la picturebox marche tres bien.
Les scrollbar apparaissent si les dimensions de celle-ci sont supérieures à celle du panel (logique me direz vous)
Voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Option Explicit On
Imports System.Drawing.Printing
Public Class Form1

    Public sngZPLZoom As Double

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        picZPLView.Image = Nothing
        sngZPLZoom = 6
        picZPLView.Width = (Convert.ToDouble(txtetiquette0.Text) * sngZPLZoom) + &H2
        picZPLView.Height = (Convert.ToDouble(txtetiquette1.Text) * sngZPLZoom) + &H6
        Call Form_Resize()
       
    End Sub

    Private Sub Form_Resize()
        Dim lngI As Long
        Dim lngJ As Long
        Dim sngI As Single
        Dim x, y, x1, y1, x2, y2 As Single

        If Me.WindowState <> 1 Then
            piccontainer.Width = piczplview.Width + (piczplview.Width / 3.5)
            piccontainer.Height = piczplview.Height + (piczplview.Height / 3.5)

            If piccontainer.Width < pb.Width Then
                HScrollBar1.Visible = False
            Else
                HScrollBar1.Visible = True
                HScrollBar1.Minimum = pb.Width - piccontainer.Width
                HScrollBar1.Maximum = pb.Width
                HScrollBar1.LargeChange = 10
                HScrollBar1.SmallChange = 1
                HScrollBar1.Value = (HScrollBar1.Maximum + HScrollBar1.Minimum) / 2
            End If

            If piccontainer.Height < pb.Height Then
                VScrollBar1.Visible = False
            Else
                VScrollBar1.Visible = True
                VScrollBar1.Minimum = 0
                VScrollBar1.Maximum = pb.Height- piccontainer.height
                VScrollBar1.LargeChange = 10
                VScrollBar1.SmallChange = 1
                VScrollBar1.Value = (VScrollBar1.Maximum + VScrollBar1.Minimum) / 2
            End If

            piccontainer.Left = (pb.Width - piccontainer.Width) / 2
            piccontainer.Top = (pb.Height - piccontainer.Height) / 2
            piczplview.Left = (pb.Width - piczplview.Width) / 2
            piczplview.Top = (pb.Height - piczplview.Height) / 2


            Dim fond As Bitmap = New Bitmap(picContainer.Width, picContainer.Height)
            piccontainer.Image = fond
            Dim taille As Single
            taille = (10 * sngZPLZoom) / 5
            Dim ft As Font = New Font("arial", taille, FontStyle.Bold)
            Dim g As Graphics = Graphics.FromImage(picContainer.Image)
            piccontainer.Image = Nothing
            lngI = 0
            For sngI = ((picZPLView.Width) / txtetiquette0.Text) To picZPLView.Width - 1 Step ((picZPLView.Width) / txtetiquette0.Text)
                lngI = lngI + 1
                If lngI < 10 Then
                    If lngI <> 5 Then
                        x1 = piczplview.Left + sngI - piccontainer.Left
                        y1 = piczplview.Top - 4 - piccontainer.Top
                        x2 = piczplview.Left + sngI - piccontainer.Left
                        y2 = piczplview.Top - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                        x1 = piczplview.Left + sngI - piccontainer.Left
                        y1 = piczplview.Top + piczplview.Height - piccontainer.Top
                        x2 = piczplview.Left + sngI - piccontainer.Left
                        y2 = (piczplview.Top + piczplview.Height) + 4 - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    Else
                        x1 = piczplview.Left + sngI - piccontainer.Left
                        y1 = piczplview.Top - 8 - piccontainer.Top
                        x2 = piczplview.Left + sngI - piccontainer.Left
                        y2 = piczplview.Top - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                        x1 = piczplview.Left + sngI - piccontainer.Left
                        y1 = piczplview.Top + piczplview.Height - piccontainer.Top
                        x2 = piczplview.Left + sngI - piccontainer.Left
                        y2 = (piczplview.Top + piczplview.Height) + 8 - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    End If
                Else
                    lngI = 0
                    lngJ = lngJ + 10
                    x1 = piczplview.Left + sngI - piccontainer.Left
                    y1 = (piczplview.Top - piccontainer.Top) - (sngZPLZoom * 3)
                    x2 = piczplview.Left + sngI - piccontainer.Left
                    y2 = (piczplview.Top - piccontainer.Top)
                    g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    x1 = piczplview.Left + sngI - piccontainer.Left
                    y1 = piczplview.Top + piczplview.Height - piccontainer.Top
                    x2 = piczplview.Left + sngI - piccontainer.Left
                    y2 = ((piczplview.Top + piczplview.Height) - piccontainer.Top) + (sngZPLZoom * 3)
                    g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    x = ((piczplview.Left + sngI) - ((g.MeasureString(lngJ, ft).Width) / 2)) - piccontainer.Left
                    y = (piczplview.Top - piccontainer.Top) - (sngZPLZoom * 6)
                    g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                    x = ((piczplview.Left + sngI) - ((g.MeasureString(lngJ, ft).Width) / 2)) - piccontainer.Left
                    y = (piczplview.Top + piczplview.Height - piccontainer.Top) + (sngZPLZoom * 3)
                    g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                End If
            Next sngI
            lngI = 0
            lngJ = 0
            For sngI = ((picZPLView.Height) / txtetiquette1.Text) To picZPLView.Height - &H1 Step ((picZPLView.Height) / txtetiquette1.Text)
                lngI = lngI + 1
                If lngI < 10 Then
                    If lngI <> 5 Then
                        x1 = piczplview.Left - 4 - piccontainer.Left
                        y1 = piczplview.Top + sngI - piccontainer.Top
                        x2 = piczplview.Left - piccontainer.Left
                        y2 = piczplview.Top + sngI - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                        x1 = piczplview.Left + piczplview.Width - piccontainer.Left
                        y1 = piczplview.Top + sngI - piccontainer.Top
                        x2 = (piczplview.Left + piczplview.Width) + &H4 - piccontainer.Left
                        y2 = piczplview.Top + sngI - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    Else
                        x1 = piczplview.Left - &H8 - piccontainer.Left
                        y1 = piczplview.Top + sngI - piccontainer.Top
                        x2 = piczplview.Left - piccontainer.Left
                        y2 = piczplview.Top + sngI - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                        x1 = piczplview.Left + piczplview.Width - piccontainer.Left
                        y1 = piczplview.Top + sngI - piccontainer.Top
                        x2 = (piczplview.Left + piczplview.Width) + &H8 - piccontainer.Left
                        y2 = piczplview.Top + sngI - piccontainer.Top
                        g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    End If
                Else
                    lngI = 0
                    lngJ = lngJ + 10
                    x1 = (piczplview.Left - piccontainer.Left) - (sngZPLZoom * 3)
                    y1 = piczplview.Top + sngI - piccontainer.Top
                    x2 = piczplview.Left - piccontainer.Left
                    y2 = piczplview.Top + sngI - piccontainer.Top
                    g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    x1 = piczplview.Left + piczplview.Width - piccontainer.Left
                    y1 = piczplview.Top + sngI - piccontainer.Top
                    x2 = ((piczplview.Left + piczplview.Width) - piccontainer.Left) + (sngZPLZoom * 3)
                    y2 = piczplview.Top + sngI - piccontainer.Top
                    g.DrawLine(Pens.Blue, x1, y1, x2, y2)
                    x = (piczplview.Left - piccontainer.Left) - (7 * sngZPLZoom)
                    y = ((piczplview.Top + sngI) - ((g.MeasureString(lngJ, ft).Width)) / 2.5) - piccontainer.Top
                    g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                    x = ((piczplview.Left + piczplview.Width) - piccontainer.Left) + (3 * sngZPLZoom)
                    y = ((piczplview.Top + sngI) - ((g.MeasureString(lngJ, ft).Width)) / 2.5) - piccontainer.Top
                    g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)

                End If
            Next
            picContainer.Image = fond
        End If
        Call drawZPL()
    End Sub

    Private Sub cmdAction1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction1.Click
        sngZPLZoom = 6.2
        picZPLView.Image = Nothing
        picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
        picZPLview.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
        Call Form_Resize()

    End Sub

    Private Sub cmdAction2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction2.Click
        If sngZPLZoom < 10 Then
            sngZPLZoom = sngZPLZoom + 0.2
            picZPLView.Image = Nothing
            picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
            picZPLview.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
            Call Form_Resize()
            
        End If
    End Sub

    Private Sub cmdAction3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction3.Click
        If sngZPLZoom > 2.4 Then
            sngZPLZoom = sngZPLZoom - 0.2
            picZPLView.Image = Nothing
            picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
            picZPLView.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
            Call Form_Resize()
        End If
    End Sub

     Private Sub initializ()
        picZPLView.Image = Nothing
        sngZPLZoom = 6
        picZPLView.Width = (Convert.ToDouble(txtetiquette0.Text) * sngZPLZoom) + &H2
        picZPLView.Height = (Convert.ToDouble(txtetiquette1.Text) * sngZPLZoom) + &H6
        Call Form_Resize()
    End Sub
End Class
Mon soucis viens de la gestion des scrollbar... (en rouge).
En fait, je souhaite que lorsque ma picturebox est plus grande que le panel, on puisse visualiser les parties "cachées" de la picturebox en jouant sur les scrollbars... facile en theorie
Le probleme c'est que j'y arrive pas... soit ca deborde trop a gauche, a droite... soit le curseur n'est plus centré lors du zoom...
En gros je patauge ;-)

Pour deplacer les curseurs des scrollbars, j'ai le code suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
        piccontainer.Left = -HScrollBar1.Value
    End Sub
 
    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
        piccontainer.Height = -VScrollBar1.Value
    End Sub
cela me donne qqchose mais pas ce que je veux, donc si une ame charitable pourrait me donner un coup de main....

a l'avance merci