Centered and scrolled PictureBox in WinForms

前端 未结 3 1549
孤街浪徒
孤街浪徒 2021-01-13 20:16

I\'m developing a WinForms application and can\'t figure out how to resolve an issue. I need to show an image in a Form. Because the image can be arbitrarily large, I need s

3条回答
  •  渐次进展
    2021-01-13 21:08

    Based on earlier answers I was able to create this full example:

    private void testShowPictureBox()
        {
            /* format form */
            Form frmShowPic = new Form();
            frmShowPic.Width = 234;
            frmShowPic.Height = 332;
            frmShowPic.MinimizeBox = false;
            frmShowPic.MaximizeBox = false;
            frmShowPic.ShowIcon = false;
            frmShowPic.StartPosition = FormStartPosition.CenterScreen;
    
            frmShowPic.Text = "Show Picture";
    
            /* add panel */
            Panel panPic = new Panel();
            panPic.AutoSize = false;
            panPic.AutoScroll = true;
            panPic.Dock = DockStyle.Fill;
    
            /* add picture box */
            PictureBox pbPic = new PictureBox();
            pbPic.SizeMode = PictureBoxSizeMode.AutoSize;
            pbPic.Location = new Point(0, 0);
    
            panPic.Controls.Add(pbPic);
            frmShowPic.Controls.Add(panPic);
    
            /* define image */
            pbPic.ImageLocation = @"c:\temp\pic.png";
    
            frmShowPic.ShowDialog();
       }
    

提交回复
热议问题