陈程的技术博客

  • 关于作者
全栈软件工程师
一个专注于技术研究创新的程序员
  1. 首页
  2. .NET
  3. 正文

winform应用程序幻灯片设计

2020年8月26日 627点热度 0人点赞 0条评论

gitee演示:https://gitee.com/zuiyuewentian/monitorMonitor.git

gitee封装:https://gitee.com/zuiyuewentian/CarouselForm.git

介绍
winform 封装一个幻灯片滚动动画
功能介绍
采用定时器+绘制自动以控件位置操作,并封装成工具,一句话调用即可实现动画效果。
动画展示,可以扩展幻灯片播放

使用方式,参考项目中:

mainFormController.Init(5, 3, panel_Main.Width, panel_Main.Height);

参考实现代码:

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 ExtractWord
{
    public partial class Change : Form
    {
        public Change()
        {
            InitializeComponent();

            timer_change.Interval = 10;
            timer_change.Tick += Timer_change_Tick;
            stepLength = panel_Body.Width / 20;
        }

        Panel Panel1 = new Panel();
        Panel Panel2 = new Panel();
        Panel Panel3 = new Panel();

        private void Change_Load(object sender, EventArgs e)
        {
            Panel1.BackColor = Color.FromArgb(211,220,230);
            Panel1.Width = panel_Body.Width;
            Panel1.Height = panel_Body.Height - 100;
            Panel1.Location = new Point(0, 50);

            Panel2.BackColor = Color.FromArgb(153,169,191);
            Panel2.Width = panel_Body.Width;
            Panel2.Height = panel_Body.Height - 100;
            Panel2.Location = new Point(panel_Body.Width, 50);

            Panel3.BackColor = Color.FromArgb(211, 220, 230);
            Panel3.Width = panel_Body.Width;
            Panel3.Height = panel_Body.Height - 100;
            Panel3.Location = new Point(panel_Body.Width * 2, 50);

            panel_Body.Controls.Add(Panel1);
            panel_Body.Controls.Add(Panel2);
            panel_Body.Controls.Add(Panel3);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            direction = true;
            lastLength = 0;
            timer_change.Start();
        }

        int lastLength = 0;
        int stepLength = 0;
        bool direction = true;

        private void Timer_change_Tick(object sender, EventArgs e)
        {
            if (direction)
            {
                if (lastLength + stepLength > panel_Body.Width)
                {
                    int tempStepLength = panel_Body.Width - lastLength;

                    int p1X = Panel1.Location.X - tempStepLength;
                    int p2X = Panel2.Location.X - tempStepLength;
                    int p3X = Panel3.Location.X - tempStepLength;

                    Panel1.Location = new Point(p1X, Panel1.Location.Y);
                    Panel2.Location = new Point(p2X, Panel2.Location.Y);
                    Panel3.Location = new Point(p3X, Panel3.Location.Y);

                    timer_change.Stop();
                }
                else
                {
                    int p1X = Panel1.Location.X - stepLength;
                    int p2X = Panel2.Location.X - stepLength;
                    int p3X = Panel3.Location.X - stepLength;

                    Panel1.Location = new Point(p1X, Panel1.Location.Y);
                    Panel2.Location = new Point(p2X, Panel2.Location.Y);
                    Panel3.Location = new Point(p3X, Panel3.Location.Y);

                    lastLength += stepLength;
                }
            }
            else {
                if (lastLength + stepLength > panel_Body.Width)
                {
                    int tempStepLength = panel_Body.Width - lastLength;

                    int p1X = Panel1.Location.X + tempStepLength;
                    int p2X = Panel2.Location.X + tempStepLength;
                    int p3X = Panel3.Location.X + tempStepLength;

                    Panel1.Location = new Point(p1X, Panel1.Location.Y);
                    Panel2.Location = new Point(p2X, Panel2.Location.Y);
                    Panel3.Location = new Point(p3X, Panel3.Location.Y);

                    timer_change.Stop();
                }
                else
                {
                    int p1X = Panel1.Location.X + stepLength;
                    int p2X = Panel2.Location.X + stepLength;
                    int p3X = Panel3.Location.X + stepLength;

                    Panel1.Location = new Point(p1X, Panel1.Location.Y);
                    Panel2.Location = new Point(p2X, Panel2.Location.Y);
                    Panel3.Location = new Point(p3X, Panel3.Location.Y);

                    lastLength += stepLength;
                }
            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            direction = false;
            lastLength = 0;
            timer_change.Start();
        }
    }
}

 

 

标签: C# gdi winform
最后更新:2021年4月2日

博主

全栈工程师,侧重项目技术解决方案规划和开发

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

分类
  • .NET (65)
  • docker (3)
  • linux (12)
  • python (20)
  • web (14)
  • 小程序 (4)
  • 数据库 (2)
  • 未分类 (4)
  • 杂七杂八 (10)
标签聚合
DevExpress python linux centos nginx js winform C#
最新 热点 随机
最新 热点 随机
.NET开发手册标准参考 招募兼职前端开发 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
RestSharp 接口请求封装类 小程序-云开发 获取用户的openid等信息 记一次fastapi做后台的跨域问题 python 发送邮件 python操作隐藏Selenium登录网站的身份指纹

COPYRIGHT © 2021 陈程的技术博客. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS