Article Options
Recently Viewed
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  A Simple Photo Browser  »  Adding an "Image..." Menu
 »  Home  »  Windows Development  »  A Simple Photo Browser  »  Adding an "Image..." Menu
 »  Home  »  Windows Development  »  Win Forms  »  A Simple Photo Browser  »  Adding an "Image..." Menu
A Simple Photo Browser
by Chris Mills | Published  04/14/2006 | .NET Newbie Windows Development Win Forms | Rating:
Adding an "Image..." Menu

It's now time to start adding a new menu that will allow the user to access the new functionality we are adding.  Add a new menu "Image" to your application's main menu and name it "mnuImage".  Now add the following menu items to your Image menu: "Flip Vertical", "Flip Horizontal", "Rotate Left", "Rotate Right", "Zoom In", "Zoom Out" and "Fit to Screen".  Name these menu items "mnuImageFlipVertical", "mnuImageFlipHorizontal", "mnuRotateLeft", etc…  We'll start by adding event handlers for the zoom menus.  Add the following event handlers to your code:
   
    Private Sub ImageZoomIn(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles mnuImageZoomIn.Click
        ' Increases the zoom factor and redraws the image.
        ' Passes the cordinates of the middle of the screen into the ReDrawPhoto function so
        ' That the center of the image at present remains in the center of the screen.
        dZoomFactor *= 1 + dZoomIncrements
        ReDrawPhoto(CInt(pnlPhoto.Width / 2) - pnlPhoto.AutoScrollPosition.X, _
            CInt(pnlPhoto.Height / 2) - pnlPhoto.AutoScrollPosition.Y)
    End Sub

    Private Sub ImageZoomOut(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles mnuImageZoomOut.Click
        dZoomFactor *= 1 - dZoomIncrements
        ReDrawPhoto(CInt(pnlPhoto.Width / 2) - pnlPhoto.AutoScrollPosition.X, _
            CInt(pnlPhoto.Height / 2) - pnlPhoto.AutoScrollPosition.Y)
    End Sub
 
    Private Sub ImageFitToScreen(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles mnuImageFitToScreen.Click
        FitPhotoToPanel()
        ReDrawPhoto(0, 0)
    End Sub

When we call the ReDrawPhoto function we have to specify the position on the screen that will remain in the same position after the zooming operation.  For the zoom menu items we will pass in the position of the centre of the portion of image that is currently being displayed.  Your user interface should now look like this:

Comments    Submit Comment

Comment #1  (Posted by Ged on 04/14/2006)
Rating
Clear comprehensive and useful - Great stuff - Thanks!
 
Comment #2  (Posted by an unknown user on 04/21/2006)
Rating
WOW! Great! Thanks!
 
Comment #3  (Posted by an unknown user on 04/24/2006)
Rating
Very nice, would make a perfect tutorial for potential .NET programmers. Thanx
 
Comment #4  (Posted by Javier on 05/03/2006)
Rating
Excelent article, but I have a question: Does it work with vb6? Thanks
 
Comment #5  (Posted by Javier on 05/03/2006)
Rating
Hi Chris. My name is Javier. I´m writing from Argentina. I had read your article "A Simple Photo Browser" and I wish to know if that code works in vb6? I have to develop an app like that and I find your article very useful. Thank you.

PD: sorry for my bad English
 
Comment #6  (Posted by an unknown user on 10/07/2006)
Rating
Some weeks ago, I tried to make a user control on my own, but it didn't work. Now I finally got a great example of one. Thanks
 
Comment #7  (Posted by an unknown user on 11/10/2006)
Rating
Very clear and completely documented explanation!
thx
 
Comment #8  (Posted by an unknown user on 11/10/2006)
Rating
Very clear and completely documented explanation!
thx
 
Comment #9  (Posted by an unknown user on 11/21/2006)
Rating
Everything is clear and easy to understand. It helped me a lot. Thanks.
 
Comment #10  (Posted by an unknown user on 12/30/2006)
Rating
The best I've seen so far... Thanks.
 
Comment #11  (Posted by an unknown user on 01/23/2007)
Rating
Clear,Understandable and pupil not assumed to be a .Net expert.
 
Comment #12  (Posted by Graham on 01/24/2007)
Rating
This will not run, there is an error with
Dim tnThumbnail As Thumbnail
Squiggley under Thumbnail
Error Message = Type 'Thumbnail' not Defined.
 
Comment #13  (Posted by an unknown user on 01/28/2007)
Rating
This is very nice. Cleared all my querries.
 
Comment #14  (Posted by Asha on 07/13/2007)
Rating
Excellent article.Keep up the good work.Great description of code too!!
 
Comment #15  (Posted by an unknown user on 11/03/2007)
Rating
Thank you so much
 
Comment #16  (Posted by an unknown user on 11/05/2007)
Rating
Excellent article, Chris
 
Comment #17  (Posted by an unknown user on 01/02/2008)
Rating
Great article. I found it just when I need it.
 
Comment #18  (Posted by an unknown user on 02/17/2008)
Rating
thanks so much, it's really helpful
 
Comment #19  (Posted by an unknown user on 07/25/2008)
Rating
Great article!
 
Comment #20  (Posted by Anke on 10/12/2008)
Rating
but I do wonder exactly how much attention ,
 
Comment #21  (Posted by Lion on 10/12/2008)
Rating
a sort of open source world government ,
 
Comment #22  (Posted by Niro on 12/31/2008)
Rating
Nice stuff =)
Is the thumbnail panel supposed to flicker when its loading up a folder of images?
 
Comment #23  (Posted by an unknown user on 02/17/2009)
Rating
Very god!!!
 
Comment #24  (Posted by an unknown user on 04/20/2009)
Rating
Thank you, thank you. I've been looking for a way to zoom images in my own programming. This helps.
 
Comment #25  (Posted by an unknown user on 10/23/2009)
Rating
Great explaination of how code is used !
 
Comment #26  (Posted by an unknown user on 12/20/2009)
Rating
this is an excellent artical to learn for frehser
 
Sponsored Links