资源简介

通过鼠标点击事件控制panel的自动滚动条移动,实现在触摸屏上的手指拖动效果

资源截图

代码片段和文件信息

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
    {
        int x = 10;//x坐标
        int y = 0;//y坐标
        string direction = “0“;//方向
        float _FlStateTime;//手指停留的时间
        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender PaintEventArgs e)
        {
            this.panel1.AutoScroll = false;
        }
        private void panel1_MouseWheel(object sender EventArgs e)
        {
           // MessageBox.Show(“鼠标滚轮“);
        }
        private void panel1_MouseDown(object sender MouseEventArgs e)
        {
            //this.panel1.Focus();
            //MessageBox.Show(“鼠标点击“);
            this.x=e.X;
            this.y = e.Y;
            this._FlStateTime = float.Parse(DateTime.Now.Second.ToString());
        }
        private void panel1_MouseUp(object sender MouseEventArgs e)
        {
            //MessageBox.Show(“鼠标离开“);
            int cx = e.X - this.x;
            this._FlStateTime = float.Parse(DateTime.Now.Second.ToString())-_FlStateTime;
            if (cx > 0)
            {
                this.direction = “右边“;
                //MessageBox.Show(direction+“距离:“+ cx+“时间:“ +_FlStateTime);
                // MessageBox.Show(panel1.AutoScrollPosition.X.ToString());
                int ax = Math.Abs(panel1.AutoScrollPosition.X);//滑动前位置
                int hx = Math.Abs(cx);//滑动距离
                Point p = new Point(ax - hx 0);
                this.panel1.AutoScrollPosition = p;
            }
            else if(cx == 0)
            {
                this.direction = “没动“;
                MessageBox.Show(direction + “距离:“ + cx + “时间:“ + _FlStateTime);
            }
            else
            {
                this.direction = “左边“;
                //MessageBox.Show(direction+ “距离:“ + cx + “时间:“ + _FlStateTime);
                int ax = Math.Abs(panel1.AutoScrollPosition.X);//滑动前位置
                int hx = Math.Abs(cx);//滑动距离
                Point p = new Point(ax + hx 0);
                this.panel1.AutoScrollPosition = p;
            }
            this.x = e.X;
            this.y = e.Y;
        }
        private void button4_MouseDown(object sender MouseEventArgs e)
        {
            this.panel1_MouseDown(sendere);
            //int index = this.button4.TabIndex;
            this.button4.TabIndex=1;
        }
        private void button4_MouseUp(object sender MouseEventArgs e)
        {
            this.panel1_MouseUp(sender e);
        }
        private void button3_MouseDown(object sender MouseEventArgs e)
        {
            this.panel1_MouseDown(sender e);
        }
        private void button3_MouseUp(object sender M

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-29 08:53  WindowsFormsApp2\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\.vs\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\.vs\WindowsFormsApp2\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\
     文件       47104  2019-03-29 08:53  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\.suo
     目录           0  2019-03-29 08:53  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\
     文件           0  2019-03-28 14:30  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\db.lock
     文件      602112  2019-03-28 22:32  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\storage.ide
     文件       32768  2019-03-29 08:50  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\storage.ide-shm
     文件     4140632  2019-03-29 08:34  WindowsFormsApp2\.vs\WindowsFormsApp2\v15\Server\sqlite3\storage.ide-wal
     目录           0  2019-03-29 08:53  WindowsFormsApp2\WindowsFormsApp2\
     文件        1146  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2.sln
     文件         189  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\App.config
     目录           0  2019-03-29 08:53  WindowsFormsApp2\WindowsFormsApp2\bin\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\WindowsFormsApp2\bin\Debug\
     文件      168448  2019-03-29 08:26  WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.exe
     文件         189  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.exe.config
     文件       40448  2019-03-29 08:26  WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.pdb
     目录           0  2019-03-28 14:54  WindowsFormsApp2\WindowsFormsApp2\bin\Release\
     文件        6080  2019-03-29 08:26  WindowsFormsApp2\WindowsFormsApp2\Form1.cs
     文件       12365  2019-03-29 08:26  WindowsFormsApp2\WindowsFormsApp2\Form1.Designer.cs
     文件        6019  2019-03-29 08:26  WindowsFormsApp2\WindowsFormsApp2\Form1.resx
     目录           0  2019-03-29 08:53  WindowsFormsApp2\WindowsFormsApp2\obj\
     目录           0  2019-03-29 08:53  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\
     文件        1443  2019-03-29 08:25  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7276  2019-03-28 14:54  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2019-03-28 14:30  WindowsFormsApp2\WindowsFormsApp2\obj\Debug\TempPE\
............此处省略16个文件信息

评论

共有 条评论