浏览大图片

Posted on 2019-01-12 22:56  努力成长静待花开  阅读(208)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Panel控件的AutoScroll属性 //指定容器是否允许用户滚动到任何放置在其可见边界之外的控件

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.wmf";
            openFileDialog1.ShowDialog();
            Image myImage = Image.FromFile(openFileDialog1.FileName);
            panel1.AutoScroll = true;
            pictureBox1.Image = myImage;
            pictureBox1.Width = myImage.Width;
            pictureBox1.Height = myImage.Height;
        }