Article Options
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:

Sponsored Links