资源简介

C# 通过鼠标实现放大图片和移动图片,内附有源码和exe,实现鼠标滚轮放大和图片平移

资源截图

代码片段和文件信息

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 ShowBigPic
{
    public partial class Form1 : Form
    {
        int xPos;
        int yPos;
        bool MoveFlag;
        public Form1()
        {
            InitializeComponent();
            pictureBox1.MouseWheel += new MouseEventHandler(pbxDrawing_MouseWheel);
        }

        //缩放
        private void pbxDrawing_MouseWheel(object sender System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                this.pictureBox1.Width = this.pictureBox1.Width * 9 / 10;
                this.pictureBox1.Height = this.pictureBox1.Height * 9 / 10;
            }
            else
            {
                this.pictureBox1.Width = this.pictureBox1.Width * 11 / 10;
                this.pictureBox1.Height = this.pictureBox1.Height * 11 / 10;
            }
        }

        private void pictureBox1_MouseUp(object sender MouseEventArgs e)
        {
            //鼠标已经抬起
            MoveFlag = false;
        }

        private void pictureBox1_MouseMove(object sender MouseEventArgs e)
        {
            //只在鼠标按下时绘制移动
            if (MoveFlag)
            {
                pictureBox1.Left += Convert.ToInt16(e.X - xPos);//设置x坐标.
                pictureBox1.Top += Convert.ToInt16(e.Y - yPos);//设置y坐标.
            }
        }

        private void pictureBox1_MouseDown(object sender MouseEventArgs e)
        {
            this.pictureBox1.Focus();
            MoveFlag = true;//已经按下.
            xPos = e.X;//当前x坐标.
            yPos = e.Y;//当前y坐标.
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-02-02 14:46  ShowBigPic\
     目录           0  2018-02-02 14:46  ShowBigPic\.vs\
     目录           0  2018-02-02 14:46  ShowBigPic\.vs\ShowBigPic\
     目录           0  2018-02-02 14:46  ShowBigPic\.vs\ShowBigPic\v14\
     文件       29696  2018-02-02 14:46  ShowBigPic\.vs\ShowBigPic\v14\.suo
     目录           0  2018-02-02 14:51  ShowBigPic\ShowBigPic\
     文件         997  2018-02-02 14:46  ShowBigPic\ShowBigPic.sln
     文件         189  2018-02-02 14:46  ShowBigPic\ShowBigPic\App.config
     目录           0  2018-02-02 14:46  ShowBigPic\ShowBigPic\bin\
     目录           0  2018-02-02 14:51  ShowBigPic\ShowBigPic\bin\Debug\
     文件       88064  2018-02-02 14:51  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.exe
     文件         189  2018-02-02 14:46  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.exe.config
     文件       22016  2018-02-02 14:51  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.pdb
     文件       22696  2018-02-02 14:51  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.vshost.exe
     文件         189  2018-02-02 14:46  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.vshost.exe.config
     文件         490  2017-09-29 21:43  ShowBigPic\ShowBigPic\bin\Debug\ShowBigPic.vshost.exe.manifest
     文件        1893  2018-02-02 14:51  ShowBigPic\ShowBigPic\Form1.cs
     文件        2970  2018-02-02 14:50  ShowBigPic\ShowBigPic\Form1.Designer.cs
     文件        5817  2018-02-02 14:50  ShowBigPic\ShowBigPic\Form1.resx
     目录           0  2018-02-02 14:46  ShowBigPic\ShowBigPic\obj\
     目录           0  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\
     文件        7299  2018-02-02 14:48  ShowBigPic\ShowBigPic\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         704  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.csproj.FileListAbsolute.txt
     文件        1064  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.csproj.GenerateResource.Cache
     文件       88064  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.exe
     文件         180  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.Form1.resources
     文件       22016  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.pdb
     文件       79092  2018-02-02 14:51  ShowBigPic\ShowBigPic\obj\Debug\ShowBigPic.Properties.Resources.resources
     文件           0  2018-02-02 14:46  ShowBigPic\ShowBigPic\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2018-02-02 14:46  ShowBigPic\ShowBigPic\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2018-02-02 14:46  ShowBigPic\ShowBigPic\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
............此处省略12个文件信息

评论

共有 条评论