C#:如何在SplitContainer面板中包含的PictureBox中添加两个滚动条

时间:2013-06-18 16:07:56

标签: c# scroll scrollbar panel autoscroll

我发现了一个类似的问题,但答案只会让其中一个滚动条出现。

我的表单有一个SplitContainer。在其中一个面板(Panel2)中有一个PictureBox,其中包含我想要显示的图像。

我需要的是找到一种方法,使图像超出面板大小时显示垂直和水平滚动条。

我已经将AutoScroll设置为true,并且我已经看到有必要将左侧的Anchor设置为其中一个滚动条,而将Top设置为另一个,但我需要它们两个

提前致谢。

2 个答案:

答案 0 :(得分:0)

我没有发现设置这样的问题。这是我的设计师代码:

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;





}

答案 1 :(得分:0)

确保在其中嵌入了PictureBox的SplitContainer.Panel 将AutoScroll属性设置为True 并且PictureBox的SizeMode属性设置为“ AutoSize”(PictureBoxSizeMode.AutoSize)。

希望我能帮助您:)