如何在 Picturebox 上获得滚动条

发布于 2024-10-12 01:37:18 字数 276 浏览 4 评论 0 原文

我有 PictureBox 图片

我使用:

picture.Size = bmp.Size;
picture.Image = bmp;

假设有两个整数 maxWidthmaxHeigth
我想在图片大小超过 maxWidth 和/或 maxHeight 时向图片添加垂直/水平滚动条。我怎样才能做到这一点?

I have PictureBox picture.

I use:

picture.Size = bmp.Size;
picture.Image = bmp;

Let's say there are two integers maxWidth and maxHeigth.
I want to add vertical/horizontal scrollbar to picture when its size exceeds maxWidth and/or maxHeight. How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦里梦着梦中梦 2024-10-19 01:37:18

您可以使用 Panel 控件轻松完成此操作

在表单中插入一个面板,例如 panel1 并设置

panel1.AutoScroll = true;

插入一个 PictureBoxPanel 中,说出图片并设置

picture.SizeMode = PictureBoxSizeMode.AutoSize;

图像

picture.Image = bmp;

You can easily do it with a Panel Control

Insert a panel to your form, say panel1 and set

panel1.AutoScroll = true;

insert a PictureBox to the Panel, say picture and set

picture.SizeMode = PictureBoxSizeMode.AutoSize;

and set the Image

picture.Image = bmp;
空心空情空意 2024-10-19 01:37:18

我通过在面板控件中放置一个图片框来使其工作,我将面板的 AutoScroll 属性设置为 true,但我还将面板的 Autosize 属性设置为 True,并将面板的 Dock 属性设置为 Fill(这样当用户调整面板大小时)形式 - 小组也将如此)。对于Picturebox,我将其Dock属性设置为None,将SizeMode设置为Autosize(因此当面板和表单调整大小时它也会调整大小。它的工作方式就像一个魅力,Picturebox有滚动条,当用户调整表单大小时 - 一切都是静止的放置正确!

I got it to work by also putting a picturebox inside a panel control, I set the Panel's AutoScroll property to true, but I also set the Panel's Autosize property to True, and the Panel's Dock property to Fill (that way when the user resizes the form - so will the Panel). For the Picturebox, I set it's Dock property to None, and the SizeMode to Autosize (so it resizes also when the Panel and form Resizes. It worked like a charm, the Picturebox has Scrollbars and when the user resizes the form - everything is still placed correctly!

一瞬间的火花 2024-10-19 01:37:18

在这个项目中,一个人构建了一个 ImagePanel 用户控件,您可以将其拖放到表单上;它为您提供滚动条和缩放功能。

http://www.codeproject.com/KB/graphics/YLScsImagePanel.aspx

Here's a project where a guy built an ImagePanel user control that you can drop onto a form; it gives you scrollbars and zoom capability.

http://www.codeproject.com/KB/graphics/YLScsImagePanel.aspx

墨离汐 2024-10-19 01:37:18

这对我有用。

PictureBox picture = new PictureBox();
picture.Image=Image.FromFile("image.bmp");
picture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Panel panel = new Panel();
panel.Size=new Size(800,600);
panel.Location=new Point(0,0);
panel.AutoScroll=true;
panel.Controls.Add(picture);
this.Controls.Add(panel);

It works to me.

PictureBox picture = new PictureBox();
picture.Image=Image.FromFile("image.bmp");
picture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Panel panel = new Panel();
panel.Size=new Size(800,600);
panel.Location=new Point(0,0);
panel.AutoScroll=true;
panel.Controls.Add(picture);
this.Controls.Add(panel);
风轻花落早 2024-10-19 01:37:18

另一个建议是将图片框放在 FlowlayoutPanel 中。

将 FlowlayoutPanel 的自动滚动设置为 true 并将图片大小模式设置为正常

使用 FlowlayoutPanel 确保图像在面板中始终处于 0,0

Another suggestion is to put the picturebox inside a FlowlayoutPanel .

Set the Auto scroll of the FlowlayoutPanel to true and set the picture size mode to normal

Using a FlowlayoutPanel makes sure the image is always at 0,0 in the panel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文