【急】如何做到焦点缩放图片!在线等待!

千杯不醉-sen 2013-10-28 02:20:03
我想做到鼠标放在那里,它就在哪里缩放。现在的要求还没有达到。我想的是在缩放的时候同时执行图片的移动事件,但是不知道改杂么做了,还请各位看看,帮忙解决一下,谢谢各位了~哪位大哥先解决了这个问题,分就给他了,不多,但是心意哈~

控件源码:

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

namespace PictureView
{
public partial class pictureView : UserControl
{
private float _zoomScale;
private Point _startPoint, _endPoint;
private bool _isDown;
private bool _isLoadBmp;
private Bitmap _currBmp;

public pictureView()
{
InitializeComponent();

this.MouseWheel += new MouseEventHandler(panel1_MouseWheel);
this.MouseEnter += new EventHandler(panel1_MouseEnter);
}

private void pictureView_Load(object sender, EventArgs e)
{
SetStyle(ControlStyles.UserPaint, true);
//防止窗口跳动
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
//防止控件跳动
SetStyle(ControlStyles.DoubleBuffer, true);

_isLoadBmp = false;
_isDown = false;
_zoomScale = 1.0f;
_startPoint = new Point(0, 0);
_endPoint = new Point(0, 0);
}

public void panel1_MouseEnter(object sender, EventArgs e)
{
this.pictureBox1.Focus();
}

/// <summary>
/// 处理鼠标滚动事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void panel1_MouseWheel(object sender, MouseEventArgs e)
{
_zoomScale += (float)e.Delta / 1000;
if (_zoomScale < 0.1)
_zoomScale = 0.1f;
if (_zoomScale > 10.0)
_zoomScale = 10.0f;
pictureBox1.Refresh();

Point p = e.Location;

Point p1 = pictureBox1.PointToClient(p);
Point p2 = pictureBox1.PointToScreen(p);
}

public void FromFile(string filePath)
{
Image img = Image.FromFile(filePath);
_currBmp = new Bitmap(img);
if (pictureBox1.Width < _currBmp.Width || pictureBox1.Height < _currBmp.Height)
_zoomScale = Math.Min((float)pictureBox1.Width / (float)_currBmp.Width, (float)pictureBox1.Height / (float)_currBmp.Height);
else
_zoomScale = 1.0f;
img.Dispose();
_isLoadBmp = true;
pictureBox1.Refresh();
}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (_isLoadBmp)
{
Rectangle rect = new Rectangle(0, 0, _currBmp.Width, _currBmp.Height);
rect.Width = (int)(rect.Width * _zoomScale);
rect.Height = (int)(rect.Height * _zoomScale);
rect.X = (int)((pictureBox1.Width - rect.Width) / 2) + _endPoint.X;
rect.Y = (int)((pictureBox1.Height - rect.Height) / 2) + _endPoint.Y;
g.FillRectangle(Brushes.White, pictureBox1.ClientRectangle);
g.DrawImage(_currBmp, rect, new Rectangle(0, 0, _currBmp.Width, _currBmp.Height), GraphicsUnit.Pixel);
}
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
_isDown = true;
_startPoint.X = e.Location.X - _endPoint.X;
_startPoint.Y = e.Location.Y - _endPoint.Y;
this.Cursor = Cursors.Hand;
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (_isDown)
{
Point temp = e.Location;
_endPoint.X = temp.X - _startPoint.X;
_endPoint.Y = temp.Y - _startPoint.Y;
pictureBox1.Refresh();
}
}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
_isDown = false;
this.Cursor = Cursors.Default;
}

private void pictureView_Resize(object sender, EventArgs e)
{
pictureBox1.Refresh();
}
}
}
...全文
319 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
千杯不醉-sen 2013-12-05
  • 打赏
  • 举报
回复
引用 9 楼 c02645 的回复:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : Form
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.Location = new Point(0, 0);
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
            //MessageBox.Show(p.X.ToString() + "  " + p.Y.ToString());
        }
        private void getPoint(Control c)
        {
            if (c.Parent != null)
            {
                p.X += c.Location.X;
                p.Y += c.Location.Y;
                getPoint(c.Parent);
            }
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            //MessageBox.Show(p.X.ToString() + "  " + p.Y.ToString());
            try
            {
                Point p1 = pictureBox1.Location;
                int w1 = e.X - p.X;
                int h1 = e.Y - p.Y;
                int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
                int x = p1.X - w2;
                int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(h1) / w1));

                pictureBox1.Location = new Point(x, y);
            }
            catch { }
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Margin = new System.Windows.Forms.Padding(0);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
试下这个 之前private void getPoint(Control c) { p.X += c.Location.X; p.Y += c.Location.Y; if (c.Parent != null) getPoint(c.Parent); }有问题的,
感谢你的帮助,非常的那种,呵呵~~~ 你已经做得很好了,其余的我来做。
c02645 2013-10-28
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : Form
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.Location = new Point(0, 0);
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
            //MessageBox.Show(p.X.ToString() + "  " + p.Y.ToString());
        }
        private void getPoint(Control c)
        {
            if (c.Parent != null)
            {
                p.X += c.Location.X;
                p.Y += c.Location.Y;
                getPoint(c.Parent);
            }
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            //MessageBox.Show(p.X.ToString() + "  " + p.Y.ToString());
            try
            {
                Point p1 = pictureBox1.Location;
                int w1 = e.X - p.X;
                int h1 = e.Y - p.Y;
                int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
                int x = p1.X - w2;
                int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(h1) / w1));

                pictureBox1.Location = new Point(x, y);
            }
            catch { }
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Margin = new System.Windows.Forms.Padding(0);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
试下这个 之前private void getPoint(Control c) { p.X += c.Location.X; p.Y += c.Location.Y; if (c.Parent != null) getPoint(c.Parent); }有问题的,
千杯不醉-sen 2013-10-28
  • 打赏
  • 举报
回复
引用 6 楼 c02645 的回复:
[quote=引用 5 楼 yangsen600 的回复:] [quote=引用 4 楼 c02645 的回复:]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : 基类.BaseDockContent
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
        }
        private void getPoint(Control c)
        {
            p.X += c.Location.X;
            p.Y += c.Location.Y;
            if (c.Parent != null)
                getPoint(c.Parent);
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            Point p1 = pictureBox1.Location;
            int w1 = e.X - p.X;
            int h1 = e.Y - p.Y;
            int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
            int x = p1.X -w2;
            int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(p1.Y) / p1.X));
            pictureBox1.Location = new Point(x,y);
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
我写的这个可以缩放,但没有判断鼠标在图片上面才缩放,你判断一下就行了
缩放我做好了,现在是不知道杂么控制缩放后保证鼠标还在图片的之前那个点那里[/quote] 这个就是以鼠标为支点缩放啊,你先看一下嘛 [/quote] 我试过了,没有达到预期的效果,不过还是要谢谢你
_小黑_ 2013-10-28
  • 打赏
  • 举报
回复
先用Cursor.Position获取鼠标的坐标,然后将鼠标所在的地方的图片进行放大镜处理,这个方法是写在鼠标移动事件里就行http://blog.csdn.net/happy09li/article/details/7056567
c02645 2013-10-28
  • 打赏
  • 举报
回复
引用 5 楼 yangsen600 的回复:
[quote=引用 4 楼 c02645 的回复:]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : 基类.BaseDockContent
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
        }
        private void getPoint(Control c)
        {
            p.X += c.Location.X;
            p.Y += c.Location.Y;
            if (c.Parent != null)
                getPoint(c.Parent);
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            Point p1 = pictureBox1.Location;
            int w1 = e.X - p.X;
            int h1 = e.Y - p.Y;
            int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
            int x = p1.X -w2;
            int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(p1.Y) / p1.X));
            pictureBox1.Location = new Point(x,y);
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
我写的这个可以缩放,但没有判断鼠标在图片上面才缩放,你判断一下就行了
缩放我做好了,现在是不知道杂么控制缩放后保证鼠标还在图片的之前那个点那里[/quote] 这个就是以鼠标为支点缩放啊,你先看一下嘛
千杯不醉-sen 2013-10-28
  • 打赏
  • 举报
回复
引用 4 楼 c02645 的回复:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : 基类.BaseDockContent
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
        }
        private void getPoint(Control c)
        {
            p.X += c.Location.X;
            p.Y += c.Location.Y;
            if (c.Parent != null)
                getPoint(c.Parent);
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            Point p1 = pictureBox1.Location;
            int w1 = e.X - p.X;
            int h1 = e.Y - p.Y;
            int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
            int x = p1.X -w2;
            int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(p1.Y) / p1.X));
            pictureBox1.Location = new Point(x,y);
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
我写的这个可以缩放,但没有判断鼠标在图片上面才缩放,你判断一下就行了
缩放我做好了,现在是不知道杂么控制缩放后保证鼠标还在图片的之前那个点那里
c02645 2013-10-28
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace NewTemp
{
    public partial class Form3 : 基类.BaseDockContent
    {
        Point p = new Point();//图片位置
        public Form3()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(this_MouseWheel);
            Bitmap img = new Bitmap(@"F:\2.jpg");
            pictureBox1.Image = img;
            pictureBox1.Width = img.Width;
            pictureBox1.Height = img.Height;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            getPoint(pictureBox1);
        }
        private void getPoint(Control c)
        {
            p.X += c.Location.X;
            p.Y += c.Location.Y;
            if (c.Parent != null)
                getPoint(c.Parent);
        }

        void this_MouseWheel(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() +"  "+ e.Y.ToString());
            System.Drawing.Size t = pictureBox1.Size;
            int _w = t.Width;
            int w = t.Width + e.Delta;
            int h = Convert.ToInt32(t.Height + e.Delta * (Convert.ToDecimal(t.Height) / t.Width));
            if (w > 0 && h > 0)
            {
                pictureBox1.Width = w;
                pictureBox1.Height = h;
            }
            p = new Point(0, 0);
            getPoint(pictureBox1);
            Point p1 = pictureBox1.Location;
            int w1 = e.X - p.X;
            int h1 = e.Y - p.Y;
            int w2 = Convert.ToInt32(e.Delta * (Convert.ToDecimal(w1) / _w));
            int x = p1.X -w2;
            int y = Convert.ToInt32(p1.Y - w2 * (Convert.ToDecimal(p1.Y) / p1.X));
            pictureBox1.Location = new Point(x,y);
        }




        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(152, 57);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(280, 221);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 267);
            this.Controls.Add(this.pictureBox1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox1;
    }
}
我写的这个可以缩放,但没有判断鼠标在图片上面才缩放,你判断一下就行了
千杯不醉-sen 2013-10-28
  • 打赏
  • 举报
回复
没有人帮忙吗?自己先顶一下~
千杯不醉-sen 2013-10-28
  • 打赏
  • 举报
回复

                rect.X = (int)((pictureBox1.Width - rect.Width) / 2) + _endPoint.X;
                rect.Y = (int)((pictureBox1.Height - rect.Height) / 2) + _endPoint.Y;
我现在想控制这两个值,但是想了好久,不知道该如何去控制它
千杯不醉-sen 2013-10-28
  • 打赏
  • 举报
回复
测试的代码忘记删了

        public void panel1_MouseWheel(object sender, MouseEventArgs e)
        {
            _zoomScale += (float)e.Delta / 1000;
            if (_zoomScale < 0.1)
                _zoomScale = 0.1f;
            if (_zoomScale > 10.0)
                _zoomScale = 10.0f;
            pictureBox1.Refresh();
        }

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧