C#:如何在 SplitContainer 面板中包含的 PictureBox 中添加两个滚动条
Posted
技术标签:
【中文标题】C#:如何在 SplitContainer 面板中包含的 PictureBox 中添加两个滚动条【英文标题】:C# : How to add both scrollbars in a PictureBox contained in a SplitContainer Panel 【发布时间】:2013-06-14 22:59:33 【问题描述】:我发现了一个类似的问题,但答案仅有助于显示其中一个滚动条。
我的表单有一个 SplitContainer。在其中一个面板 (Panel2) 中有一个 PictureBox,其中包含我要显示的图像。
我需要找到一种方法,当图像超过面板大小时,使垂直和水平滚动条都出现。
我已经将 AutoScroll 设置为 true,并且我发现有必要将 Anchor 设置在左侧以显示其中一个滚动条,并将 Anchor 设置在 Top 以显示另一个,但我需要它们。
提前致谢。
【问题讨论】:
所以将锚点设置在顶部和左侧,而不是底部或右侧 【参考方案1】:确保您嵌入 PictureBox 的 SplitContainer.Panel 将 AutoScroll 属性设置为 True 并且您的 PictureBox 的 SizeMode 属性设置为 'AutoSize' (PictureBoxSizeMode.AutoSize)。
希望我能帮到你:)
【讨论】:
【参考方案2】:我在设置这样的东西时没有发现任何问题。这是我的设计器代码:
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;
【讨论】:
以上是关于C#:如何在 SplitContainer 面板中包含的 PictureBox 中添加两个滚动条的主要内容,如果未能解决你的问题,请参考以下文章
如何调整 SplitContainer 中 Panel1 和 Panel2 之间的空间?
C# WinForm的SplitContainer控件固定Panel大小