Post by Cryotica on Apr 23, 2014 1:51:45 GMT 10
Hey, I'm creating a image viewer, its got your basic open file dialog, a menu strip and a picture box, but I want a scroll wheel to zoom in and out, and have a status bar indicate the zoom percentage. Help anybody?
If you live in the future, why worry about the present? It's the past . . .
Proud Supporter of Nathan Lecompte!
|
|
Post by Nathan Lecompte on Apr 23, 2014 14:56:51 GMT 10
Hey Cryotica, I'm guessing you're using a picturebox to display your images, right? The following code resizes the picturebox by a certain amount when the MouseWheel event of the picturebox is activated. 1. Place a panel on your form (this will be where your image will show) and insert a picturebox into the panel. 2. Make sure your picturebox anchor is " top, left" and dock is equal to none. 3. Set picturebox size-mode to stretch. 4. Move picturebox to top left corner of the panel. 5. Set picturebox autosize to True. 6. Dock your panel to where you want your image to appear. 7. Set panel Autoscroll to True. 8. In the picturebox MouseWheel event insert the following code: Private Sub PictureBox_MouseWheel(sender As System.Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel If e.Delta <> 0 Then If e.Delta <= 0 Then If PictureBox1.Width < 500 Then Exit Sub 'minimum 500? Else If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000? End If
PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000) PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000) End If
End Sub I hope this helps! Nathan.
|
|
Post by Cryotica on Apr 23, 2014 19:22:08 GMT 10
Hey Cryotica, I'm guessing you're using a picturebox to display your images, right? The following code resizes the picturebox by a certain amount when the MouseWheel event of the picturebox is activated. 1. Place a panel on your form (this will be where your image will show) and insert a picturebox into the panel. 2. Make sure your picturebox anchor is " top, left" and dock is equal to none. 3. Set picturebox size-mode to stretch. 4. Move picturebox to top left corner of the panel. 5. Set picturebox autosize to True. 6. Dock your panel to where you want your image to appear. 7. Set panel Autoscroll to True. 8. In the picturebox MouseWheel event insert the following code: Private Sub PictureBox_MouseWheel(sender As System.Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel If e.Delta <> 0 Then If e.Delta <= 0 Then If PictureBox1.Width < 500 Then Exit Sub 'minimum 500? Else If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000? End If
PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000) PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000) End If
End Sub I hope this helps! Nathan. What if I want a fully docked picturebox, thats always docked?
If you live in the future, why worry about the present? It's the past . . .
Proud Supporter of Nathan Lecompte!
|
|
Post by Nathan Lecompte on Apr 23, 2014 19:25:59 GMT 10
Hey Cryotica, I'm guessing you're using a picturebox to display your images, right? The following code resizes the picturebox by a certain amount when the MouseWheel event of the picturebox is activated. 1. Place a panel on your form (this will be where your image will show) and insert a picturebox into the panel. 2. Make sure your picturebox anchor is " top, left" and dock is equal to none. 3. Set picturebox size-mode to stretch. 4. Move picturebox to top left corner of the panel. 5. Set picturebox autosize to True. 6. Dock your panel to where you want your image to appear. 7. Set panel Autoscroll to True. 8. In the picturebox MouseWheel event insert the following code: Private Sub PictureBox_MouseWheel(sender As System.Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel If e.Delta <> 0 Then If e.Delta <= 0 Then If PictureBox1.Width < 500 Then Exit Sub 'minimum 500? Else If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000? End If
PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000) PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000) End If
End Sub I hope this helps! Nathan. What if I want a fully docked picturebox, thats always docked? You'll have to dock the panel instead. The picturebox needs to be undocked in order for the zooming to work...
|
|
Post by Nathan Lecompte on Apr 24, 2014 12:58:31 GMT 10
Hey, I'm creating a image viewer, its got your basic open file dialog, a menu strip and a picture box, but I want a scroll wheel to zoom in and out, and have a status bar indicate the zoom percentage. Help anybody? If this solved your question please add "[SOLVED]" to your subject/title.
|
|