ImageView.cs :  » GUI » wx-NET » wx » SampleImageView » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » SampleImageView » ImageView.cs

using wx;
using System.Drawing;
using System;
using System.IO;

namespace wx.SampleImageView{
    /**
     * This is the application.
     */
    public class ImageViewApp : App
    {
        /**
         * The overrided OnInit is where the main form should be created and
         * shown.  Application start-up logic can also be placed here.
         */
        public override bool OnInit()
        {
            // Create the main frame
            ImageViewFrame frame = new ImageViewFrame();

            // Show it
            frame.Show(true);

            // Return true, to indicate that everything was initialized 
            // properly.
            return true;
        }

        [STAThread]
        public static void Main()
        {
            // Create an instance of our application class
            ImageViewApp app = new ImageViewApp();

            // Run the application
            app.Run();
        }
    }

    /**
     * This is the main frame.  All user interaction will start here.
     */
    public class ImageViewFrame : Frame
    {
        // Every control that we want to handle events for will need an 
        // integer ID, these IDs are listed below.

        // File menu IDs
        private const int ID_FileOpenDir    = 1;
        private const int ID_FileExit       = 2;

        // Help menu IDs
        private const int ID_HelpAbout      = 3;

        // String to hold the directory we're browsing
        private string m_directory = "";

        // The image list
        private ImageList m_list;

        // The image viewer
        private ImageViewer m_viewer;

        /**
         * The base class is passed the title of the frame, the default 
         * position for its position, and an arbitrary size.
         *
         * All the components inside the frame are created and initialized 
         * here.
         */
        public ImageViewFrame()
            : base("ImageView", wxDefaultPosition, new Size(500, 500))
        {
            // The menu bar is the bar where all the menus will be attached 
            // to.
            MenuBar menuBar = new MenuBar();

            // The File menu
            Menu fileMenu = new Menu();

            // The first item we append is the "Open" command.  The ID for 
            // the menu item is passed, as well as two strings.
            //
            // The first string is the menu item text.  The stuff after '\t'
            // tells wxWidgets to use this as a short-cut key for the item.
            // An '&' will underline the next character on the menu, for 
            // easy access.
            //
            // The second string is the help text for the menu item.  When a
            // users mouse hovers over the item, the status bar text will
            // change to this.
            fileMenu.Append(ID_FileOpenDir, "&Open Directory...\tCtrl+O",
                            "Open a directory with images");

            // Append a menu seperator.
            fileMenu.AppendSeparator();

            // Exit menu item.
            fileMenu.Append(ID_FileExit, "E&xit\tCtrl+Shift+W", 
                            "Exit this fine application");

            // Attach the file menu to the menu bar
            menuBar.Append(fileMenu, "&File");

            // The Help menu
            Menu helpMenu = new Menu();

            helpMenu.Append(ID_HelpAbout, "&About...",
                            "About this application");

            menuBar.Append(helpMenu, "&Help");

            // Next we tell the frame to use the menu bar that we've created, 
            // using the Frame.MenuBar property.
            this.MenuBar = menuBar;

            // Create a status bar with 2 fields
            CreateStatusBar(2);

            // Set the initial status bar text, this will set the text in the 
            // first status bar field.
            StatusText = "Welcome to ImageView!";

            // The splitter window allows two child windows to be displayed
            // with a bar between them.
            //
            // When there is only one child in a Frame, the child will fill
            // that frame, hence we don't need a sizer in this frame.
            SplitterWindow split = new SplitterWindow(this, -1);

            // Create the image viewing control
            m_viewer = new ImageViewer(split);

            // Create our image list
            m_list = new ImageList(split, m_viewer);

            // We now split the window with the two children
            split.SplitVertically(m_list, m_viewer, 150);

            // Set some event handlers using the IDs of the controls we 
            // wish to handle events for.
            EVT_MENU(ID_FileExit,           new EventListener(OnFileExit));
            EVT_MENU(ID_FileOpenDir,        new EventListener(OnFileOpenDir));

            EVT_MENU(ID_HelpAbout,          new EventListener(OnHelpAbout));

            // Handle when the frame is closed
            EVT_CLOSE(new EventListener(OnClose));
        }

        /**
         * Exit event handler
         */
        protected void OnFileExit(object sender, Event evt)
        {
            // Close the frame.  Since this is the last (only) frame in the
            // application, the application will exit when it is closed.

            Close();
        }

        /**
         * Open Directory event handler
         */
        protected void OnFileOpenDir(object sender, Event evt)
        {
            DirDialog dlg = new DirDialog(this, "Choose an image directory",
                                          m_directory);

            if (dlg.ShowModal() == Dialog.wxID_OK) {
                m_directory = dlg.Path;

                // List the images. GetFiles is not very powerful: it is
        // limited to a DOS-like wildcard match. So in our case 
        // this is case sensitive on UN*X.
                string[] files = Directory.GetFiles(m_directory, "*.jpg");
                m_list.ListImages(files);

                Title = dlg.Path;
            }
        }

        /**
         * About event handler
         */
        protected void OnHelpAbout(object sender, Event evt)
        {
            // Message for our about dialog.
            string msg = "ImageView!\n\nAn application for viewing images.";

            // Display a message box.  The message box will have an OK button
            // (wxOK), and an information icon (wxICON_INFORMATION)
            MessageDialog.ShowModal(this, msg, "About ImageView", 
                                    Dialog.wxOK | Dialog.wxICON_INFORMATION);
        }

        protected void OnClose(object sender, Event evt)
        {
            // We can ask the user whether or not it is OK to close the frame,
            // then act appropriately.

            string msg = "Are you sure you'd like to exit?";

            int result = MessageDialog.ShowModal(this, msg, "Exit ImageView",
                                                 Dialog.wxYES_NO |
                                                 Dialog.wxICON_QUESTION);

            // Did the user click yes?
            if (result == Dialog.wxYES) {
                // They did, we tell wxWidgets to take care of closing the
                // application
                evt.Skip();
            }
        }

        /**
         * Override the base Title, since we want to add some more intelligent
         * behaviour.
         */
        public override string Title
        {
            get { return base.Title; }
            set { 
                string title = "ImageView";

                if (value != "")
                    title += " (" + value + ")";

                base.Title = title;
            }
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.