• 大小: 43KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签:

资源简介

c#单击按钮、滑轮滚动放大、缩小pictruebox中的图片,并且pictruebox里的图片可以拖动,而且图片被放大或缩小到一定的程度不会报错

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
        }

        /// 
        /// 图片导入
        /// 

        /// 
        /// 
        private void button1_Click(object sender EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();
            if (of.FileName == null) return;
            pictureBox1.Image = Image.FromFile(of.FileName);
            _bitmap = new Bitmap(pictureBox1.Image);
        }



        /// 
        /// 滑轮滚动图片放大、缩小
        /// 

        /// 
        /// 
        private void Form1_MouseWheel(object sender MouseEventArgs e)
        {
            var t = pictureBox1.Image.Size;
            t.Width += e.Delta;
            t.Height += e.Delta;
            if (t.Width < 0 || t.Height < 0)
            {
                return;
            }
            if (t.Width > 10000 || t.Height > 10000)
            {
                return;
            }
            pictureBox1.Image = new Bitmap(_bitmap t);


        }

        double _percent = 1;

        Bitmap _bitmap = null;
        /// 
        /// 图片放大按钮事件
        /// 

        /// 
        /// 
        private void button2_Click(object sender EventArgs e)
        {
            button3.Enabled = true;
            _percent = _percent + (double)0.1;
            
            pictureBox1.Image = PicSized(_bitmap _percent);

        }

       

        /// 
        /// 图片缩小按钮事件
        /// 

        /// 
        /// 
        private void button3_Click(object sender EventArgs e)
        {
            button2.Enabled = true;
            _percent = _percent - (double)0.1;

            pictureBox1.Image = PicSized(_bitmap _percent);

        }

        /// 
        /// 图片放大缩小功能
        /// 

        /// 
        /// 
        /// 
        public Bitmap PicSized(Bitmap originBmp double iSize)
        {
            int w = Convert.ToInt32(originBmp.Width * iSize);
            int h = Convert.ToInt32(originBmp.Height * iSize);
            if (w <50 || h <50)
            {
                button3.Enabled = false;
            }
            if (w > 99999 || h 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12288  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件      28160  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      11600  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        490  2010-03-17 22:39  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件       5818  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs

     文件       4443  2014-04-30 13:04  WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs

     文件       5817  2014-04-30 13:04  WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx

     文件       2152  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6402  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        488  2014-04-30 13:04  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog

     文件       1142  2014-04-30 13:04  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog

     文件       1339  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件      12288  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe

     文件        180  2014-04-30 13:04  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources

     文件      28160  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb

     文件        180  2014-04-30 10:33  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件        516  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Program.cs

     文件       1480  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       2877  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       5612  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx

     文件       1110  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs

     文件        249  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings

     文件       3707  2014-04-30 10:33  WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj

     文件        914  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1.sln

    ..A..H.     10240  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1.suo

     目录          0  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE

     目录          0  2014-04-30 18:00  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug

     目录          0  2014-04-30 10:33  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug

     目录          0  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86

     目录          0  2014-04-30 10:22  WindowsFormsApplication1\WindowsFormsApplication1\bin

............此处省略7个文件信息

评论

共有 条评论

相关资源