本文介绍了通过轨迹栏在图片框中加载图片(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果跟踪栏位于1%上,则图像也将加载,例如从左到右的选取框仅占1%,并且跟踪栏将变为2,3,4,5,6 ..... 100%,因此图像也应根据轨迹栏加载.


If track bar is on 1% then the image will also load, like marquee from left to right only 1%, and track bar will go 2,3,4,5,6.....100%, so image should also load according to the trackbar.


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

//Created by Raj Kumar Shukla @ 22*09*2012
namespace toolStripContainer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        double i;
        Image img = Image.FromFile("23.jpg");

        private void Form1_Load(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (i = 1; i <= 100;)
            {
                Thread.Sleep(100);
                backgroundWorker1.ReportProgress(Convert.ToInt32(i));
                i =i+0.2 ;
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pictureBox1.Image = img;
            pictureBox1.Height = img.Height;
            pictureBox1.Width = img.Width;


            progressBar1.Value = e.ProgressPercentage;

            if (e.ProgressPercentage < 100)
            {
                this.Text ="Image loading Plz wait....";
                menuStrip1.Enabled = false;
            }
            else
            {
                this.Text = "Image Loading Completed";
                menuStrip1.Enabled = true;
            }

            trackBar1.Value = e.ProgressPercentage;

            pictureBox1.Width = e.ProgressPercentage * 10;



        }

       public void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open Photo";
            dlg.Filter = "jpg files (*.jpg)|*.jpg";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
               img = new Bitmap(dlg.OpenFile());
            }
            dlg.Dispose();
            backgroundWorker1.RunWorkerAsync();
        }

       private void button1_Click(object sender, EventArgs e)
       {

       }
    }
}



[edit]添加了代码块,我将内容从问题的答案中移了出来-OriginalGriff [/edit]



[edit]Code block added, I moved the content from an Answer to the question - OriginalGriff[/edit]

推荐答案


这篇关于通过轨迹栏在图片框中加载图片(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 11:05
查看更多