当我们尝试确定窗体的大小时,PictureBox控件将自动调整大小 [英] PictureBox control resize atomatically when we will try to incerase the size of the form

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

问题描述

我要在Windows窗体的左上角放置一个TextBox和一个Button控件(仅用于测试),并在其中放置一个PictureBox控件,然后将图像放入其中,因此,我的要求是每当我增加PictureBox控件的窗体大小时我需要有关Dock和Anchor属性的信息,所以任何人都可以帮助我.

I am putting one TextBox and one Button control(just for testing) at the left corner of the windows form and a PictureBox control and puttng a image into it so,my requirement is whenever i will increase the form size the PictureBox control need to be maximize.I know about the Dock and Anchor property so can anyone help me out.

推荐答案

将Anchor属性设置为所有四个侧面-这样,PictureBox随着表单的增大和缩小,各个方向之间的距离将保持不变-您已经知道了.

如果您想要的是PictureBox中的图像也要增大和缩小,则只需将PictureBox.SizeMode设置为StretchImage
Set the Anchor properties to all four sides - that way the PictureBox will remain the same distance from all sides as the form grows and shrinks - you know that already.

If what you want is the Image in the PictureBox to also grow and shrink, then just set the PictureBox.SizeMode to StretchImage


您是否要PictureBox最大化并重新渲染图像?就该组件的滥用而言,这种简单的功能已经引起了质疑,该组件被设计为仅在最简单的情况下使用,但非常容易.如果您要做的事情比仅显示一张静态图片要复杂得多(嗯,也许偶尔但不经常更改图片),那么此组件仅提供了障碍而没有帮助;它会占用开发时间和额外的资源,因此无法提供有用的功能.

经常会滥用此控制类型,并经常导致很大的挫败感.

没有什么用呢?与从System.Windows.Forms.Control派生的简单自定义控件相比,该控件处理事件Paint或覆盖虚拟方法Paint.如果您对图像做任何事情,这是最合适的技术.

有关更多详细信息,请参阅我过去的答案:
如何从旧图纸中清除面板 [ ^ ],
在C#中绘制矩形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [在mdi子表单之间画线 [
Do you want PictureBox to maximize and re-render the image? This simple functionality is already questionable in terms of the abuse of this component which is designed to be used only in the simplest situations, but very easily. Should you do something a bit more complex than just showing one static picture (well, maybe changing the picture occasionally, but not often), this component provides no help but just obstacles; it eats up development time and extra resources, offering no useful functionality in return.

Abuse of this control type is very usual and regularly causes big deal of frustration.

No useful compared with what? Compared to a simple custom control derived from System.Windows.Forms.Control handling the event Paint or overriding the virtual method Paint. If you do anything to the image, this is the most adequate technique.

For further detail, please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

See also these answers for better understanding of the technique:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^].

—SA


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

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