c#开发Windows桌面程序,支持触摸屏

2023-05-16

这是一段由new bing聊天机器人提供的代码,我没有测试是否能正常运行,请谨慎使用。

我是这样提问的:

我想用c#开发一款Windows桌面程序,这个程序支持触摸屏,这个程序打开后要全屏无边框显示,打开后要开始轮播我指定文件夹下的图片,每张图片暂停6秒钟,然后继续播放下一张,当用户在触摸屏中间区域点击时,播放暂停,再点击时,播放继续,当用户点击触摸左侧区域时,播放上一张图片,当用户点击触摸屏右侧区域时,播放下一张图片,请给出详细的代码及说明

这是ai给出的代码:

public partial class Form1 : Form
{
    private int _currentIndex = 0;
    private readonly List<string> _imagePaths = new List<string>();
    private readonly Timer _timer = new Timer();

    public Form1()
    {
        InitializeComponent();
        this.FormBorderStyle = FormBorderStyle.None;
        this.WindowState = FormWindowState.Maximized;
        this.Load += Form1_Load;
        this.MouseDown += Form1_MouseDown;
        this._timer.Interval = 6000;
        this._timer.Tick += Timer_Tick;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        var folderPath = @"C:\Users\Public\Pictures\Sample Pictures";
        var files = Directory.GetFiles(folderPath, "*.jpg");
        foreach (var file in files)
        {
            this._imagePaths.Add(file);
        }
        if (this._imagePaths.Count > 0)
        {
            this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
            this._timer.Start();
        }
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        if (this._currentIndex < this._imagePaths.Count - 1)
        {
            this._currentIndex++;
            this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
            this._timer.Start();
        }
        else
        {
            this._currentIndex = 0;
            this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
            this._timer.Start();
        }
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.X < (this.Width / 3))
        {
            if (this._currentIndex > 0)
            {
                this._currentIndex--;
                this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
                this._timer.Start();
            }
            else
            {
                this._currentIndex = this._imagePaths.Count - 1;
                this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
                this._timer.Start();
            }
        }
        else if (e.X > ((this.Width / 3) * 2))
        {
            if (this._currentIndex < (this._imagePaths.Count - 1))
            {
                this._currentIndex++;
                this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
                this._timer.Start();
            }
            else
            {
                this._currentIndex = 0;
                this.pictureBox1.ImageLocation = this._imagePaths[this._currentIndex];
                this._timer.Start();
            }
        }
        else
        {
            if (this.timer.Enabled)
            {
                this.timer.Stop();
            }
            else
            {
                this.timer.Start();
            }
        }
    }
}

这是ai给的代码说明:

这段代码会在窗体加载时,从指定文件夹中获取所有图片的路径,并将第一张图片显示在窗体中。然后,它会使用计时器来轮播图片。每张图片暂停6秒钟,然后继续播放下一张。当用户在触摸屏中间区域点击时,播放暂停,再点击时,播放继续。当用户点击触摸左侧区域时,播放上一张图片。当用户点击触摸屏右侧区域时,播放下一张图片。 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c#开发Windows桌面程序,支持触摸屏 的相关文章

随机推荐

  • 嵌入式开发常用的三种通信协议串口通信、SPI和IIC

    常用的三种通信协议串口通信 SPI和IIC 文章目录 常用的三种通信协议串口通信 SPI和IIC一 通信分类1 1 同步通信和异步通信1 2 单工通信 半双工通信和全双工通信1 3 串行通信与并行通信 二 串口通信2 1 UART2 2 R
  • HTML 解决css缓存

    span class token operator lt span link rel span class token operator 61 span span class token string 34 stylesheet 34 sp
  • Ubuntu18.04安装Nvidia显卡驱动教程

    0 前期准备 禁用BIOS的secure boot xff0c 即disable它 xff0c 如果不关闭 xff0c 使用第三方源安装显卡驱动会安装后不能使用 1 禁用nouveau 1 创建文件 xff0c 如果没有下载vim编辑器 x
  • VINS之estimator节点小结

    VINS的核心节点 xff0c 包括VIO的初始化过程 紧耦合的非线性化过程 边缘化处理过程 主要流程步骤 1 主函数线程 订阅了四个topic xff0c 分别调用回调函数 xff1b 创建了13个话题发布器 xff1b 开辟了一个VIO
  • 基于布谷鸟搜索算法的函数寻优算法

    文章目录 一 理论基础1 算法原理2 算法流程图 二 Matlab代码三 参考文献 一 理论基础 1 算法原理 布谷鸟采用一种特殊的寄生宿主巢穴的方式孕育繁殖 它将孵育的蛋置入寄生宿主的巢穴 xff0c 让寄生宿主孵化布谷鸟蛋 由于布谷鸟幼
  • 基于逐维反向学习的动态适应布谷鸟算法

    文章目录 一 理论基础1 布谷鸟搜索算法2 DA DOCS算法 xff08 1 xff09 逐维反向学习策略 xff08 2 xff09 动态适应 xff08 3 xff09 DA DOCS算法流程 二 实验与结果分析三 参考文献 一 理论
  • SMPL学习笔记

    文章目录 前言一 SMPL概述1 形状参数 beta 2 姿态参数
  • 多协议BGP-----MPBGP

    MPBGP是在BGP 4 基础上的扩展 xff0c 分为三种 xff1a ipv4 ipv4 ipv6 ipv6 ipv6 ipv4 ipv4 ipv6 本文主要介绍 xff1a ipv6 ipv4 xff08 在 建立ipv6 的BGP邻
  • __asm void MSR_MSP(uint32_t addr) 提示:error:expected '(' after 'asm'

    SYSTEM sys sys c 33 7 error expected 39 39 before 39 void 39 ASM void MSR MSP u32 addr 在STM32中的sys c文件编译报出这个错误时 xff1a AS
  • LTL线性时序逻辑

    https blog csdn net yuniruchujian article details 106213848https www docin com p 506137477 html
  • 强化学习资料

    强化学习资料 莫烦学习资料 莫烦学习资料 https mofanpy com bilibili视频资料 xff1a https www bilibili com video BV13W411Y75P from 61 search amp s
  • apollo学习

    知乎王方浩 https zhuanlan zhihu com p 52521739 csdn https blog csdn net u013914471 type 61 blog bilibili 忠厚老实的老王 https space
  • 求解离散黎卡提矩阵代数方程

    离散代数黎卡提方程求解 1 黎卡提方程 在LQR最优控制中 xff0c 有连续时间最优控制 xff0c 即LQR xff0c 也有离散时间最优控制DLQR xff0c 则在求解中一定会遇到解连续时间黎卡提方程和离散时间黎卡提方程的问题 xf
  • 基于运动学模型的无人机模型预测控制(MPC)-2

    基于无人机自身模型的模型预测控制 无约束情况 1 模型建立 无人机运动学模型 xff1a x
  • 一阶低通滤波器-连续转离散

    一阶低通滤波器 1 一阶连续低通滤波器 y s r
  • 汽车动力学模型

    1 动力学模型 在纵向时 xff0c 可能还会受到纵向空气阻力 xff0c 前轮滚动阻力 xff0c 后轮滚动阻力 xff0c 坡道重力分量等
  • PX4飞控源码及解析

    源码地址 xff1a https github com 987419640 Firmware 解析 xff1a https dev px4 io zh concept architecture html
  • Hadoop:简介和安装

    Hadoop简介 Hadoop项目由多个子项目组成 与其他项目不同 xff0c 这个项目更像一个生态系统 其中 xff0c 核心项目包括HDFS MapReduce框架 YARN和ZooKeeper HDFS是一个符合Hadoop要求的分布
  • centos6.x如何安装docker

    1 curl Lks https yum spaceduck org kernel ml aufs kernel ml aufs repo gt etc yum repos d kernel ml aufs repo 2 yum remov
  • c#开发Windows桌面程序,支持触摸屏

    这是一段由new bing聊天机器人提供的代码 xff0c 我没有测试是否能正常运行 xff0c 请谨慎使用 我是这样提问的 xff1a 我想用c 开发一款Windows桌面程序 xff0c 这个程序支持触摸屏 xff0c 这个程序打开后要