0
Answer

How to Fit image (stratch) with this functionality ???

Faisal Ansari

Faisal Ansari

12y
1k
1
i have an pictureBox with panning features, but i i want to add fit image feature like stratch image ,, how can i do this ???

code is here ..

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;

namespace PanningImageDemo
{
    public partial class Form1 : Form
    {
        private Point startingPoint = Point.Empty;
        private Point movingPoint = Point.Empty;
        private bool panning = false;
        Image img;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            img = Image.FromFile("D:\\Drawings\\dwg\\638.tif");
            pictureBox1.Size = img.Size;
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            panning = true;
            startingPoint = new Point(e.Location.X - movingPoint.X, e.Location.Y - movingPoint.Y);
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            panning = false;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (panning)
            {
                movingPoint = new Point(e.Location.X - startingPoint.X, e.Location.Y - startingPoint.Y);
                pictureBox1.Refresh();
                //pictureBox1.Invalidate();
            }
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(img, movingPoint);
        }
    }
}

Reply soon 


Thanks