• listBox和pictureBox的使用


    重要属性:
    pictureBox中SizeMode可以更改图像显示的尺寸大小。

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace ListBox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //为了在两个方法中都能访问到 String[] path = Directory.GetFiles("E:\00","*.jpg"); private void Form1_Load(object sender, EventArgs e) { for ( int i = 0; i < path.Length; i++) { //根据路径名获取文件名称 string fileName = Path.GetFileName(path[i]); listBox1.Items.Add(fileName); } } private void listBox1_DoubleClick(object sender, EventArgs e) { //添加图片文件,需要添加全路径 pictureBox1.Image = Image.FromFile(path[listBox1.SelectedIndex]); } } }

    使用List

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;
    
    namespace ListBox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            //为了在两个方法中都能访问到
            List<string> list = new List<string>();
    
            private void Form1_Load(object sender, EventArgs e)
            {
                String[] path = Directory.GetFiles("E:\00", "*.jpg");
                 for ( int i = 0; i < path.Length; i++)
                {
                     //根据路径名获取文件名称
                     string fileName = Path.GetFileName(path[i]);
                     listBox1.Items.Add(fileName);
    
                     //将图片全路径添加到List泛型中;
                     list.Add(path[i]);
                }
            }
    
            private void listBox1_DoubleClick(object sender, EventArgs e)
            {
                //添加图片文件,需要添加全路径
                pictureBox1.Image = Image.FromFile(list[listBox1.SelectedIndex]);
            }
    
            private void listBox1_Click(object sender, EventArgs e)
            {
                
                pictureBox1.Image = Image.FromFile(list[listBox1.SelectedIndex]);
            }
        }
    }
    

      

  • 相关阅读:
    转载-----nodejs内存定位
    node内存泄露排查转载
    git使用规范
    git的使用方法
    Sublime Text 3最好的功能、插件和设置
    Appium-Python-Windows环境搭建笔记
    MPI Note
    先装VS2008之后,又装了2013,然后启动VS2008提示“Tools Version”有问题?
    SQLite 编译错误
    WPF异常捕获三种处理 UI线程, 全局异常,Task异常
  • 原文地址:https://www.cnblogs.com/my-cat/p/7417673.html
Copyright © 2020-2023  润新知