当前位置: 首页>>代码示例>>C#>>正文


C# ImageList.Images属性代码示例

本文整理汇总了C#中System.Windows.Forms.ImageList.Images属性的典型用法代码示例。如果您正苦于以下问题:C# ImageList.Images属性的具体用法?C# ImageList.Images怎么用?C# ImageList.Images使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.ImageList的用法示例。


在下文中一共展示了ImageList.Images属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button1_Click

internal System.Windows.Forms.ImageList ImageList1;

// Create an ImageList Object, populate it, and display
// the images it contains.
private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{

    // Construct the ImageList.
    ImageList1 = new ImageList();

    // Set the ImageSize property to a larger size 
    // (the default is 16 x 16).
    ImageList1.ImageSize = new Size(112, 112);

    // Add two images to the list.
    ImageList1.Images.Add(
        Image.FromFile("c:\\windows\\FeatherTexture.bmp"));
    ImageList1.Images.Add(
        Image.FromFile("C:\\windows\\Gone Fishing.bmp"));

    // Get a Graphics object from the form's handle.
    Graphics theGraphics = Graphics.FromHwnd(this.Handle);

    // Loop through the images in the list, drawing each image.
    for(int count = 0; count < ImageList1.Images.Count; count++)
    {
        ImageList1.Draw(theGraphics, new Point(85, 85), count);

        // Call Application.DoEvents to force a repaint of the form.
        Application.DoEvents();

        // Call the Sleep method to allow the user to see the image.
        System.Threading.Thread.Sleep(1000);
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:36,代码来源:ImageList.Images

示例2: Form1

//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

public class Form1 : Form
{
      private System.Windows.Forms.ListView browserListView;
      private System.Windows.Forms.Label currentLabel;
      private System.Windows.Forms.Label displayLabel;
      private System.Windows.Forms.ImageList fileFolder;
      
      string currentDirectory = Directory.GetCurrentDirectory();

  public Form1() {
        InitializeComponent();
        Image folderImage = Image.FromFile("winter.jpg" );
        Image fileImage = Image.FromFile("winter.jpg" );

        fileFolder.Images.Add( folderImage );
        fileFolder.Images.Add( fileImage );

        LoadFilesInDirectory( currentDirectory );
        displayLabel.Text = currentDirectory;
  }

    private void browserListView_Click( object sender, EventArgs e )
    {
      if ( browserListView.SelectedItems.Count != 0 )
      {
         if ( browserListView.Items[0].Selected )
         {
            DirectoryInfo directoryObject = new DirectoryInfo( currentDirectory );

            if ( directoryObject.Parent != null )
               LoadFilesInDirectory( directoryObject.Parent.FullName );
         }else {
            string chosen = browserListView.SelectedItems[ 0 ].Text;
            if ( Directory.Exists( currentDirectory + @"\" + chosen ) )
            {
               if ( currentDirectory == @"C:\" )
                  LoadFilesInDirectory( currentDirectory + chosen );
               else
                  LoadFilesInDirectory(currentDirectory + @"\" + chosen );
            }
         }
         displayLabel.Text = currentDirectory;
      } 
   } 
   public void LoadFilesInDirectory( string currentDirectoryValue )
   {
      try
      {
         browserListView.Items.Clear();
         browserListView.Items.Add( "Go Up One Level" );

         currentDirectory = currentDirectoryValue;
         DirectoryInfo newCurrentDirectory = new DirectoryInfo( currentDirectory );

         DirectoryInfo[] directoryArray = newCurrentDirectory.GetDirectories();
         FileInfo[] fileArray = newCurrentDirectory.GetFiles();

         foreach ( DirectoryInfo dir in directoryArray )
         {
            ListViewItem newDirectoryItem = browserListView.Items.Add( dir.Name );
            newDirectoryItem.ImageIndex = 0;
         }

         foreach ( FileInfo file in fileArray )
         {
            ListViewItem newFileItem = browserListView.Items.Add( file.Name );
            newFileItem.ImageIndex = 1;
         }
      } catch ( UnauthorizedAccessException ) {
         Console.WriteLine( "Unauthorized Access Exception");
      }
   }
      private void InitializeComponent()
      {
         this.browserListView = new System.Windows.Forms.ListView();
         this.fileFolder = new System.Windows.Forms.ImageList(new System.ComponentModel.Container());
         this.currentLabel = new System.Windows.Forms.Label();
         this.displayLabel = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // browserListView
         // 
         this.browserListView.Location = new System.Drawing.Point(12, 60);
         this.browserListView.Name = "browserListView";
         this.browserListView.Size = new System.Drawing.Size(456, 197);
         this.browserListView.SmallImageList = this.fileFolder;
         this.browserListView.TabIndex = 0;
         this.browserListView.View = System.Windows.Forms.View.List;
         this.browserListView.Click += new System.EventHandler(this.browserListView_Click);
         // 
         // fileFolder
         // 
         this.fileFolder.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
         this.fileFolder.ImageSize = new System.Drawing.Size(16, 16);
         this.fileFolder.TransparentColor = System.Drawing.Color.Transparent;
         // 
         // currentLabel
         // 
         this.currentLabel.AutoSize = true;
         this.currentLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.currentLabel.Location = new System.Drawing.Point(10, 19);
         this.currentLabel.Name = "currentLabel";
         this.currentLabel.Size = new System.Drawing.Size(122, 20);
         this.currentLabel.TabIndex = 1;
         this.currentLabel.Text = "Now in Directory:";
         // 
         // displayLabel
         // 
         this.displayLabel.AutoSize = true;
         this.displayLabel.Location = new System.Drawing.Point(138, 19);
         this.displayLabel.Name = "displayLabel";
         this.displayLabel.Size = new System.Drawing.Size(0, 0);
         this.displayLabel.TabIndex = 2;
         // 
         // ListViewTestForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(480, 270);
         this.Controls.Add(this.displayLabel);
         this.Controls.Add(this.currentLabel);
         this.Controls.Add(this.browserListView);
         this.Name = "ListViewTestForm";
         this.Text = "ListViewTest";
         this.ResumeLayout(false);
         this.PerformLayout();

      }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:146,代码来源:ImageList.Images


注:本文中的System.Windows.Forms.ImageList.Images属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。