Winform面板可滚动大小 [英] Winform panel scrollable size

查看:143
本文介绍了Winform面板可滚动大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Win10上使用VS2015 / C#测试面板控件:



在面板1中添加50个PictureBox控件:



Image img = Image.FromFile(Application.StartupPath + @\ .png); //任何形象



panel1.AutoScroll = true;

panel1.Height = 500;


i = 0; i< 50; i ++)

{

PictureBox pb = new PictureBox();

pb.Left = i * 10;

pb.Top = i *(img.Height + 10);

pb.SizeMode = PictureBoxSizeMode.AutoSize;

pb.Image = img;

toolTip1.SetToolTip(pb,i.ToString()+:+ pb.Top.ToString());

panel1.Controls.Add(pb);

}



如果图片框的顶部小于32767,图片框可以放在正确的位置。但是如果图片框的顶部大于32767,则图片框不能放置在正确的位置,它将被放置在面板的底部。换句话说,Panel控件的最大可滚动高度就像32767.



我希望所有图片框都在面板中的所需位置。是否有任何方法可以放大面板的可滚动尺寸?



我尝试过:



此问题存在于Win7 / 8/10上,但在WinXP中找不到。它与VS版本和.NET框架版本无关,只与Windows版本有关。

I use VS2015/C# on Win10 to test Panel control:

Add 50 PictureBox controls into panel1:

Image img = Image.FromFile(Application.StartupPath + @"\1.png"); //any image

panel1.AutoScroll = true;
panel1.Height = 500;

for (int i = 0; i < 50; i++)
{
PictureBox pb = new PictureBox();
pb.Left = i*10;
pb.Top = i * (img.Height + 10);
pb.SizeMode = PictureBoxSizeMode.AutoSize;
pb.Image = img;
toolTip1.SetToolTip(pb, i.ToString()+": "+pb.Top.ToString());
panel1.Controls.Add(pb);
}

If the 'Top' of a picture box is less than 32767, the picture box can be placed in right position. But if the 'Top' of a picture box is greater than 32767, the picture box can not be placed in right position, it will be placed at the bottom of the panel. In an another word, the maximum scrollable height of Panel control is like 32767.

I want all picture box in wanted position in panel. Is any method to enlarge panel scrollable size?

What I have tried:

This issue is exist on Win7/8/10, but no found in WinXP. It is no relation with VS versions and .NET framework versions, just in relation with Windows versions.

推荐答案

我会构建自己的自定义Panel,它具有我想要的行为在这个面板中,我不会放置你所有的图片 - 只有那些可以看到的图片和一个在顶部(负坐标)和一个在底部(在面板外) 。

现在我将构建一个特殊的Scroll-Function,它只适用于这个控件并为它们分配(如果需要)新图片。
I would build my own customized Panel which has the behaviour I want to have.
In this Panel I would not place all of your Pictures - only those which can be seen and one more at the Top (negative coordinates) and one more at the Bottom (outside the Panel).
Now I would build up a special Scroll-Function which only works with this Controls and assign them (if needed) new Pictures.


这篇关于Winform面板可滚动大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆