Thumbnail.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 » Thumbnail.cs

using wx;
using System;
using System.Drawing;

namespace wx.SampleImageView{
    /**
     * Class to display a thumbnail image.
     */
    public class Thumbnail : Panel, IDisposable
    {
        // Delegate to handle thumnail events
        public delegate void ThumbnailClick(string file, wx.Bitmap bmp);

        // Delegate for external classes to hook into click events
        public ThumbnailClick ThumbnailClicked;

        // The bitmap on this thumbnail
        private wx.Bitmap m_bitmap;
        
        // Filename of the bitmap to use
        private string m_fileName;

        // A bitmap button used to display the image
        private BitmapButton m_bitmapBtn;

        // A text label for the file name
        private StaticText m_label;

        public Thumbnail(Window parent, string fileName)
            : base(parent)
        {
            m_fileName = fileName;

            // A box sizer to arrange the controls vertically 
            BoxSizer sizer = new BoxSizer(Orientation.wxVERTICAL);

            // The bitmap constructor can load the image files directly
            wx.Image image = new wx.Image(m_fileName);
            m_bitmap = new wx.Bitmap(image);
            //m_bitmap = new wx.Bitmap(m_fileName, 
            //                         BitmapType.wxBITMAP_TYPE_BMP);

            wx.Bitmap smallBmp = m_bitmap;

            // Scale the bitmap to icon size, retaining the aspec ratio
            int max = Math.Max(m_bitmap.Width, m_bitmap.Height);
            if (max > 100) {

                double scale = 100.0 / (double)max;
                int width = (int)((double)m_bitmap.Width * scale), 
                    height = (int)((double)m_bitmap.Height * scale);
                
                wx.Image img = m_bitmap.ConvertToImage();
                img.Rescale(width, height);
                smallBmp = new wx.Bitmap(img);
            }

            // Create the bitmap button with the small bitmap
            m_bitmapBtn = new BitmapButton(this, -1, smallBmp);

            // Add it to the sizer, centered, with a small border
            sizer.Add(m_bitmapBtn, 1, Alignment.wxALIGN_CENTRE | 
                      Direction.wxALL, 3);

            // Create our static text label with the file name as the label
            m_label = new StaticText(this, -1, "");

            string lbl = m_fileName.Substring(m_fileName.LastIndexOf('/') + 1);
            lbl = lbl.Substring(0, lbl.LastIndexOf('.'));
            m_label.Label = lbl;

            // Add the label to the sizer, centered, with a small border
            sizer.Add(m_label, 0, Alignment.wxALIGN_CENTRE | 
                      Direction.wxALL, 3);

            // Set the sizer
            Sizer = sizer;
            sizer.SetSizeHints(this);

            // Catch the bitmap button click event, a '-1' is used, since our
            // panel control has only one bitmap button, so the event can only
            // come from one place.
            EVT_BUTTON(-1, new EventListener(OnBitmapButtonClicked));
        }

        protected void OnBitmapButtonClicked(object sender, Event evt)
        {
            // Notify our listeners
            if (ThumbnailClicked != null) {
                ThumbnailClicked(m_fileName, m_bitmap);
            }
        }
    }
}

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