Icon.cs :  » GUI » wx-NET » wx » 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 » Icon.cs
//-----------------------------------------------------------------------------
// wx.NET - Icon.cs
//
// The wxIcon wrapper class.
//
// Written by Jason Perkins (jason@379.com)
// (C) 2003 by 379, Inc.
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: Icon.cs,v 1.10 2007/11/18 19:33:48 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace wx{
  public class Icon : Bitmap
  {
    [DllImport("wx-c")] static extern IntPtr wxIcon_ctor();
    [DllImport("wx-c")] static extern void   wxIcon_CopyFromBitmap(IntPtr self, IntPtr bitmap);
    [DllImport("wx-c")] static extern bool   wxIcon_LoadFile(IntPtr self, IntPtr name, BitmapType type);

    //---------------------------------------------------------------------

        /** CTor for ZipResource support.
         * This will load an image \c resourceName from ZipResource file or directory \c archiveName.
         * \code
         wx.ZipResource.AddCatalogLookupPrefix(@"..\Utils\MemLogDisplay");
         wx.Icon icon=new wx.Icon("archiveName.zrs", "iconname.png");
         \endcode
         */
        public Icon(string archiveName, string resourceName)
        {
            System.IO.Stream s=ZipResource.FindResource(archiveName, resourceName);
            if (s==null)
                throw new ArgumentException(string.Format("file 'zrs:{0}//{1}' not found", archiveName, resourceName));
            int length = (int)s.Length;
            byte[] buffer = new byte[length];
            s.Read(buffer, 0, length);
            Image img = new Image(buffer, BitmapType.wxBITMAP_TYPE_ANY);

            Bitmap bmp = new Bitmap(img);
            wxIcon_CopyFromBitmap(wxObject, bmp.wxObject);
        }

        /** This loads the icon from a local file.
         * Add a BitmapType to specify alternative ways of loading.
         */
    public Icon(string name)
      : this()
    {
      Image img = new Image();
            if (!img.LoadFile(name))
                throw new ArgumentException("file '" + name + "' not found");

      Bitmap bmp = new Bitmap(img);
      wxIcon_CopyFromBitmap(wxObject, bmp.wxObject);
    }

        /** Loads a bitmap of the provided type.
         * Use wx.BitmapType.wxBITMAP_TYPE_ANY if you have no information on the type
         * of the bitmap. Use wx.BitmapType.wxBITMAP_TYPE_RESOURCE to load a bitmap
         * from the .NET resource named \c name.
         */
        public Icon(string name, BitmapType type)
      : this()
    {
      if (type == BitmapType.wxBITMAP_TYPE_RESOURCE)
      {
        Assembly ResourceAssembly = Assembly.GetCallingAssembly();
        
        Image img = new Image(name, ResourceAssembly);
        
        Bitmap bmp = new Bitmap(img);
        wxIcon_CopyFromBitmap(wxObject, bmp.wxObject);
      }
      else
      {
                wxString wxName = wxString.SafeNew(name);
        if (!wxIcon_LoadFile(wxObject, Object.SafePtr(wxName), type))
          throw new ArgumentException();
      }
    }

    /** Convenience CTor for reading the resource of the provided name from the provided assembly.
     */
    public Icon(string resourceName, Assembly resourceAssembly)
      : this()
    {
      Bitmap bmp=new Bitmap(resourceName, resourceAssembly);
      wxIcon_CopyFromBitmap(wxObject, bmp.wxObject);
    }

    public Icon()
      : base(wxIcon_ctor())
    {
    }
    
    public Icon(IntPtr wxObject) 
      : base(wxObject) { }    

    //---------------------------------------------------------------------

    public void CopyFromBitmap(Bitmap bitmap)
    {
      wxIcon_CopyFromBitmap(wxObject, Object.SafePtr(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.