Reputation: 1
I've found a similar question, but the answer only helps making one of the scrollbars appear.
My form has a SplitContainer. In one of its panels (Panel2) there is a PictureBox with an image i want to show.
What i need is to find a way to make both vertical and horizontal scrollbars appear when the image exceeds the panel's size.
I already set AutoScroll to true, and I've seen it's necessary to set Anchor at left for one of the scrollbars to appear, and at Top for the other one, but i need both of them.
Thanks in advance.
Upvotes: 0
Views: 2650
Reputation: 11
make sure your SplitContainer.Panel in which you embedded your PictureBox has AutoScroll property set to True and your PictureBox has SizeMode property set to 'AutoSize' (PictureBoxSizeMode.AutoSize).
Hope I helped you :)
Upvotes: 1
Reputation: 12811
I didn't find any issues setting up something like this. Here's my designer code:
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.AutoScroll = true;
this.splitContainer1.Panel2.Controls.Add(this.pictureBox1);
this.splitContainer1.Size = new System.Drawing.Size(576, 406);
this.splitContainer1.SplitterDistance = 192;
this.splitContainer1.TabIndex = 0;
//
// pictureBox1
//
this.pictureBox1.Image = global::WinFormsScratch.Properties.Resources.Desert;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(1024, 768);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(576, 406);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Form1";
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.PictureBox pictureBox1;
}
Upvotes: 0