C#基础-简单案例

点不到的学习

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;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("当然是不学习啦");
            this.Close();
        }



        private void button2_MouseEnter(object sender, EventArgs e)
        {
            int x = this.ClientSize.Width - button2.Width;
            int y = this.ClientSize.Height - button2.Height;

            Random r = new Random();
            button2.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
        }
    }
}

灯+时间

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

namespace WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //☆★☆★☆★
            //☆  ★☆★☆★
            //★☆★☆★☆
            label1.Text=label1.Text.Substring(1) + label1.Text.Substring(0, 1);
        }
        /// <summary>
        /// 把当前时间赋值给Label2
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer2_Tick(object sender, EventArgs e)
        {
            label2.Text=DateTime.Now.ToString();
            //13:30分播放音乐
            if (DateTime.Now.Hour==13 && DateTime.Now.Minute==54 && DateTime.Now.Second==1)
            {
                //SoundPlayer sp = new SoundPlayer();
                //sp.SoundLocation = @"";
                MessageBox.Show("时间到了");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label2.Text = DateTime.Now.ToString();
        }
    }
}

切换图片上下一张

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 WindowsFormsApp8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
        }
            //获得指定文件夹的所有文件的全路径
           string[] path=Directory.GetFiles(@"C:\Users\Administrator\Desktop\DesktopWallpaper");
            int i = 0;
        /// <summary>
        /// 点击更换更换下一张图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            
            i++;
            if (i == path.Length)
            {
                i = 0;
            }
            pictureBox1.Image = Image.FromFile(path[i]);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            i--;
            if (i<0)
            {
                i = path.Length-1;
            }
            pictureBox1.Image = Image.FromFile(path[i]);
        }
    }
}

随机播放6张图片

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 WindowsFormsApp9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

            string[] path=Directory.GetFiles(@"C:\Users\Administrator\Desktop\DesktopWallpaper");
        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox6.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
            pictureBox2.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
            pictureBox3.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
            pictureBox4.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
            pictureBox5.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");
            pictureBox6.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\DesktopWallpaper\夜晚 星空 ɽ 光 · 一个人背影 4k唯美壁纸3840x2160_彼岸图网.jpg");

        }
        int i = 0;
        Random r = new Random();
        private void timer1_Tick(object sender, EventArgs e)
        {
            //i++;
                if (i==path.Length)
            {
                i = 0;
            }
            pictureBox1.Image = Image.FromFile(path[r.Next(0,path.Length)]);
            pictureBox2.Image = Image.FromFile(path[r.Next(0, path.Length)]);
            pictureBox3.Image = Image.FromFile(path[r.Next(0, path.Length)]);
            pictureBox4.Image = Image.FromFile(path[r.Next(0, path.Length)]);
            pictureBox5.Image = Image.FromFile(path[r.Next(0, path.Length)]);
            pictureBox6.Image = Image.FromFile(path[r.Next(0, path.Length)]);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值