• 大小: 96KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C#
  • 标签: C#  winform  

资源简介

采用C# 技术,一个简单Winform 程序。程序简单有图像缩放平移功能,可以提供开发思路

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
namespace Display
{
    public class Drawing
    {
        /// 
        /// 实际坐标
        /// 

        public List< PointF> Points { get; set; }
        /// 
        /// 显示坐标
        /// 

        public List< PointF> PaintPoints { get; set; }
        /// 
        /// 绘图中心的X
        /// 

        public float PaintAreaCenterX { get; set; }
        /// 
        /// 绘图中心的Y
        /// 

        public float PaintAreaCenterY { get; set; }
        /// 
        /// 实际坐标的X
        /// 

        public double DisplayCenterX { get; set; }
        /// 
        /// 实际坐标的Y 
        /// 

        public double DisplayCenterY { get; set; }
        /// 
        /// 绘图比例
        /// 

        public double Scale = 1;
        /// 
        /// 图片显示框
        /// 

        public PictureBox PictureBox;
        /// 
        /// 当鼠标按下时的坐标
        /// 

        int X = 0 Y = 0;
        /// 
        /// 当鼠标按下时屏幕中心 的坐标
        /// 

        double displayx0 displayy0;

        public Drawing(PictureBox pictureBox)
        {
            PictureBox = pictureBox;
            Points = new List();
            PaintPoints = new List();
            PictureBox.MouseWheel += PictureBox_MouseWheel;
            PictureBox.MouseDown += PictureBox_MouseDown;
            PictureBox.MouseUp += PictureBox_MouseUp;
            PictureBox.MouseMove += PictureBox_MouseMove;
            PictureBox.MouseEnter+=PictureBox_MouseEnter;
            PictureBox.Paint += PictureBox_Paint;
           
        
        }
        //win10以下操作系统需要win10能自动获取焦点
        public  void PictureBox_MouseEnter(object sender EventArgs e)
        {
            PictureBox.Focus();
        }
        public void Invalidata()
        {
            PictureBox.Invalidate();
        }

        private void PictureBox_MouseWheel(object sender MouseEventArgs e)
        {
            if (e.Delta > 0)
            {
               
                Scale *= (float)1.25;
                PictureBox.Invalidate();
            }
            else
            {
                
                Scale /= (float)1.25;
                PictureBox.Invalidate();
            } 
        }

        private void PictureBox_MouseMove(object sender MouseEventArgs e)
        { 

            if (e.Button ==MouseButtons.Left)
                {
                    double dx = (e.X - X)/Scale;
                    double dy = (e.Y - Y)/Scale ;
                    DisplayCenterX = displayx0 - dx;
                    DisplayCenterY = displayy0 - dy;
                    PictureBox.Invalidate()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-29 08:53  图形缩放平移示例\
     目录           0  2016-08-21 09:15  图形缩放平移示例\Display\
     目录           0  2016-08-15 13:42  图形缩放平移示例\Display\bin\
     目录           0  2016-08-15 15:20  图形缩放平移示例\Display\bin\Debug\
     文件        8704  2016-08-21 09:16  图形缩放平移示例\Display\bin\Debug\Display.dll
     文件       17920  2016-08-21 09:16  图形缩放平移示例\Display\bin\Debug\Display.pdb
     目录           0  2016-08-15 13:42  图形缩放平移示例\Display\bin\Release\
     文件        2498  2016-08-15 15:20  图形缩放平移示例\Display\Display.csproj
     文件        6310  2016-08-21 09:15  图形缩放平移示例\Display\Drawing.cs
     目录           0  2016-08-15 13:42  图形缩放平移示例\Display\obj\
     目录           0  2016-08-21 09:16  图形缩放平移示例\Display\obj\Debug\
     文件        6769  2016-08-15 14:07  图形缩放平移示例\Display\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         463  2016-08-21 09:13  图形缩放平移示例\Display\obj\Debug\Display.csproj.FileListAbsolute.txt
     文件        2059  2016-08-21 09:13  图形缩放平移示例\Display\obj\Debug\Display.csprojResolveAssemblyReference.cache
     文件        8704  2016-08-21 09:16  图形缩放平移示例\Display\obj\Debug\Display.dll
     文件       17920  2016-08-21 09:16  图形缩放平移示例\Display\obj\Debug\Display.pdb
     文件           0  2016-08-15 13:42  图形缩放平移示例\Display\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-08-15 13:42  图形缩放平移示例\Display\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2016-08-15 13:42  图形缩放平移示例\Display\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2016-08-15 13:42  图形缩放平移示例\Display\obj\Debug\TempPE\
     目录           0  2016-08-15 13:42  图形缩放平移示例\Display\Properties\
     文件        1338  2016-08-15 13:42  图形缩放平移示例\Display\Properties\AssemblyInfo.cs
     目录           0  2016-08-15 15:24  图形缩放平移示例\简单图形平移缩放(类库)演示\
     文件         187  2016-08-15 13:41  图形缩放平移示例\简单图形平移缩放(类库)演示\App.config
     目录           0  2016-08-15 13:41  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\
     目录           0  2016-08-21 09:13  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\
     文件        8704  2016-08-21 09:16  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\Display.dll
     文件       17920  2016-08-21 09:16  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\Display.pdb
     文件       10752  2016-08-21 09:16  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\简单图形平移缩放(类库)演示.exe
     文件         187  2016-08-15 13:41  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\简单图形平移缩放(类库)演示.exe.config
     文件       26112  2016-08-21 09:16  图形缩放平移示例\简单图形平移缩放(类库)演示\bin\Debug\简单图形平移缩放(类库)演示.pdb
............此处省略33个文件信息

评论

共有 条评论