调整Windows窗体大小时自动调整PictureBox的大小 [英] Resize PictureBox automatically as Windows form is resized

查看:540
本文介绍了调整Windows窗体大小时自动调整PictureBox的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个Windos表单,然后是一个TabPanel,然后是一个Panel,在该面板中我有多个图片框。我如何调整图片框的大小以便在我调整窗口大小时它们适应?



非常感谢

Hi,

I have a Windos Form, then a TabPanel, then a Panel and inside that panel I have multiple pictureboxes. How can I resize the pictureboxes so they adapt when I resize the window?

Thanks a lot

推荐答案

我认为这是一个Windows应用程序?控件的Anchor属性确定在调整窗体大小时它们的行为方式。只需使用属性窗口中的那些并尝试它,直到获得所需的行为。
I assume this is a Windows app? The Anchor properties of the controls determine how they behave when the form is resized. Just play with those in the Properties window and try it until you get the behavior you want.


如果您正在谈论自动调整任何控件的大小,您通常可以将其停靠在其他控件上控制如 Panel (或表单 TabPage 和其他)本身将调整大小。您需要使用 Dock 属性,其值为 System.Windows.Forms.DockStyle.Fill

http://msdn.microsoft.com/en-us /library/system.windows.forms.control.dock.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx [ ^ ]。



锚点也可以工作,但通常 Dock 填充要好得多。另请参阅:

http:// msdn .microsoft.com / zh-cn / library / system.windows.forms.control.padding.aspx [ ^ ]。



然而,我不知道确定你真的需要调整 PictureBox 的大小。最有可能的是,你根本不应该使用这个控件。它完全是冗余的(您可以使用相同的API实现它)并且只需要简化最简单的杂务(固定大小的静态图像等)。当你尝试做任何更复杂的事情时,它变得很麻烦。在你的情况下,问题是重新采样图像。



(顺便说一下,你应该明白重新采样图像的质量是不可接受的。你只能制作它比原来小,或者只是略大一点。除非你同意让它看起来很难看。)



所以,不要使用 PictureBox 可能比使用它更好。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



还有:

c在面板上绘制图纸 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

如何加快我的vb.net程序? [的 ^ ],

mdi子表单之间的绘制线 [ ^ ]。



我希望它能解释你需要理解的简单技巧。 />


-SA
If you are talking about automatic resize of any control, you can usually have it docked to some other control like Panel (or a Form, TabPage and others) which itself would be resized. You need to use Dock property with the value System.Windows.Forms.DockStyle.Fill:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx[^].

Anchors would work, too, but usually Dock with Padding is much better. See also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.padding.aspx[^].

However, I don't sure that you really need to resize PictureBox. Most likely, you should not use this control at all. It is totally redundant (you can implement it using the same API) and only needed to simplify the simplest chores (static image of fixed size and so on). It becomes a hassle when you try to do anything even a tiny bit more complex. In your case, the problem would be resampling of the image.

(By the way, you should understand that resampling an image up its quality unacceptable. You can only make it smaller than original, or only slightly bigger. unless you agree to make it ugly looking.)

So, not using PictureBox could be better than using it. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

And also:
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^],
Drawing Lines between mdi child forms[^].

I hope it will explain the simple techniques you need to understand.

—SA


这篇关于调整Windows窗体大小时自动调整PictureBox的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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