C#第二次作业的第三题

主函数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 作业3
{
static class Program
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

主要实现功能的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 作业3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;//设置图片在pictureBox1中居中显示
        pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");//在程序显示中先加载一张图片


    }


    string[] path = Directory.GetFiles(@"C:\Users\Administrator\Desktop\images");//把所有图片路径放到一个数组中

    static  Random r = new Random(); //随机数
    int one;//第一张图片出现的次数
    int two;//第2张图片出现的次数
    int three;//第3张图片出现的次数
    int four;//第4张图片出现的次数
    int five;//第5张图片出现的次数

    private void button1_Click(object sender, EventArgs e)
    {
        int num = r.Next(0,9);

        pictureBox1.Image = Image.FromFile(path[num]);//图片显示的路径


        if (path[num].Equals(path[0]))
        {
            one++;
            label1.Text = "显示的次数" + one;
        }
        else if (path[num].Equals(path[1]))
        {
            two++;
            label1.Text = "显示的次数" + two;
        }
        else if (path[num].Equals(path[2]))
        {
            three++;
            label1.Text = "显示的次数" + three;
        }
        else  if (path[num].Equals(path[3]))
        {
            four++;
            label1.Text = "显示的次数" + four;
        }
        else if(path[num].Equals(path[4]))
        {
            five++;
            label1.Text = "显示的次数" + five;
        }


    }


}

}C#第二次作业的第三题_第1张图片

你可能感兴趣的:(作业,c#)