我刚刚开始学习C#和Visual Studio,试图在书籍和示例代码上工作。
我知道这不是一个非常聪明的问题,但这是我正在努力解决的问题。我有一个windows窗体,我需要在tableLayoutPanel中包含的图片框中显示图像。简单的问题是,我必须加载的图像可能有几个大小,并且一个典型的图像并没有在分配的空间内完全显示:只显示适合容器的区域,图像的其余部分被剪切。我必须显示整个图像,我不需要调整它的大小。我已经设置了autosize属性,但这似乎不起作用。
下面是form.cs中的一些代码
string imageName = openFileDialog1.FileName; // Get the image name
// Read the image
try
{
img = ( Bitmap) Image .FromFile(imageName);
}
catch
{
MessageBox.Show("oooops" , Text, MessageBoxButtons.OK, MessageBoxIcon .Hand);
}
pictureBox1.Image = img; // show the image然后在form.designer.cs中找到的私有空InitializeComponent()中:
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
...
this.pictureBox1 = new System.Windows.Forms.PictureBox();
...
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 1, 1);
...
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 1, 1);
...
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 9.034863F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 2.388038F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 88.5771F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(784, 762);
...
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;你有任何关于如何显示整个图像的提示吗?
即使使用滑动条也可以,但如果容器的autoscroll = true,则什么也不会发生,图像仍然会被截断。
谢谢你的帮助
发布于 2012-05-23 20:24:29
tableLayout控件中的autoscroll属性管理整个表的滚动,包括所有子控件。当图像太大而无法放入图片控件时,autoscroll = yes属性会显示滑动条,允许滑动表格布局控件中打包的所有内容,而不是单个图像单元格。图片框没有autoscroll属性,因为据我所知,autoscroll是容器的属性;我想,要在自己分配的空间中滑动图像,应该使用中间容器。
我的问题不是一个好问题。它的根源在于我对遏制层次结构和相关属性的困惑,而不是真正缺乏知识或概念。嗯,总有改进的空间……
https://stackoverflow.com/questions/10579325
复制相似问题