I am developing a WinForms application and cannot figure out how to solve the problem. I need to show the image in the form. Since the image can be arbitrarily large, I need scroll bars on the frame with the image so that the user can see it completely. Approaching it, I found that the best way to achieve this is to add a PictureBox as a child of the Panel control and make the panel automatic and automatic. I did this programmatically, because with the help of the constructor, I could not insert the image as a child control of the panel. The problem that I am currently facing is that I cannot possibly be able to center and scroll the image at the same time. If I put the anchor in the upper, left, lower, right bars, the scroll bars are not displayed, and the displayed image is strange, if I return the anchor only left-up, the image is not centered.
Is there a way to do both at the same time? Here is the code for my panel and Picturebox:
this.panelCapturedImage = new System.Windows.Forms.Panel(); this.panelCapturedImage.SuspendLayout(); this.panelCapturedImage.AutoScroll = true; this.panelCapturedImage.AutoSize = true; this.panelCapturedImage.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.panelCapturedImage.Controls.Add(this.pictureBoxCapturedImage); this.panelCapturedImage.Location = new System.Drawing.Point(0, 49); this.panelCapturedImage.Name = "panelCapturedImage"; this.panelCapturedImage.Size = new System.Drawing.Size(3, 3); this.panelCapturedImage.TabIndex = 4; this.pictureBoxCapturedImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pictureBoxCapturedImage.Location = new System.Drawing.Point(0, 0); this.pictureBoxCapturedImage.Name = "pictureBoxCapturedImage"; this.pictureBoxCapturedImage.Size = new System.Drawing.Size(0, 0); this.pictureBoxCapturedImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.pictureBoxCapturedImage.TabIndex = 0; this.pictureBoxCapturedImage.TabStop = false; this.panelCapturedImage.Controls.Add(this.pictureBoxCapturedImage);
And here, where I set the image:
public Image CapturedImage { set { pictureBoxCapturedImage.Image = value; pictureBoxCapturedImage.Size = value.Size; } }
brafales
source share