C# - Resize Image Using TrackBar

C# - How To Change PictureBox Size Using TrackBar In C#

c# resize picturebox


In This C# Tutorial  We Will See How To Resize PictureBox Width And Height Using TrackBar In CSharp Programming Language.


Project Source Code:

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 WindowsFormsApplication1
{
    public partial class Form14 : Form
    {
        public Form14()
        {
            InitializeComponent();
        }
        //Width
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            pictureBox1.Size = new Size(trackBar1.Value, pictureBox1.Size.Height);
            pictureBox1.Left = (this.ClientSize.Width - pictureBox1.Width) / 2;
            pictureBox1.Top = (this.ClientSize.Height - pictureBox1.Height) / 2;
        }
        //Height
        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            pictureBox1.Size = new Size(pictureBox1.Size.Width, trackBar2.Value);
            pictureBox1.Left = (this.ClientSize.Width - pictureBox1.Width) / 2;
            pictureBox1.Top = (this.ClientSize.Height - pictureBox1.Height) / 2;
        }

        private void Form14_Load(object sender, EventArgs e)
        {
            trackBar1.Value = pictureBox1.Size.Width;
            trackBar2.Value = pictureBox1.Size.Height;
            pictureBox1.Left = (this.ClientSize.Width - pictureBox1.Width) / 2;
            pictureBox1.Top = (this.ClientSize.Height - pictureBox1.Height) / 2;
        }
    }
}

OutPut :

c# resize picturebox using trackbar




Share this

Related Posts

Previous
Next Post »