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;
        }


    }


}

}这里写图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值