如何使用户在运行时调整控件的大小? [英] How to enable user to resize the controls at runtime?

查看:107
本文介绍了如何使用户在运行时调整控件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望窗体上的控件可调整大小,并且用户可以将鼠标指针移到控件的边缘以开始调整其大小.
我可以那样做吗?如果可以的话,您能建议我一些解决方法吗?
非常感谢!

I want my controls on a form to be resizable and user can move the mouse pointer to the edges of the controls to start resizing their size.
Can I do that? If I can, could you please suggest me some solution?
Thank you so much!

推荐答案

,您可以使用AJAX控件工具包中提供的可调整大小的控件.请参考下面的链接.
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/ResizableControl/ResizableControl.aspx [ ^ ]
you can use resizable control available in in AJAX control toolkit. Please refer the link below.
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/ResizableControl/ResizableControl.aspx[^]


要在WinForms中移动或调整控件大小,您将需要为每个控件的MouseDown,MouseUp和MouseMove事件编写事件处理程序.
在MouseDown事件中,将一个布尔标志设置为"true",表示鼠标已按下,并记录MouseDown的位置.在MouseUp事件中将该标志设置为"false".

在MouseMove事件中,测试处于按下状态的鼠标的布尔标志,如果是,则:根据初始MouseDown和MouseMove事件中当前Mouse位置之间的差,计算deltax和deltay向量.
然后,对于调整大小,它变得很有趣:如果以某种方式拖动控件的原点可以保持原点,那么这是一个更简单的情况:您只是要将deltax添加到控件中宽度,以及控件高度的变化量.

建议您从实现控件原点可以保持固定的简单情况开始,然后继续思考在控件原点必须移动时处理调整大小的情况所需采取的措施.

最好,比尔
To move, or re-size, controls in WinForms, you are going to need to write event handlers for each control''s MouseDown, MouseUp, and MouseMove events.

In the MouseDown event set a boolean flag to ''true, indicating the mouse is down, and record the position of the MouseDown; in the MouseUp event set that flag to ''false.

In the MouseMove event, test the boolean flag for the mouse being down, and, if it is: calculate a deltax and deltay vector based on the difference between initial MouseDown and the current Mouse position in the MouseMove event.

And then, for re-size, it gets interesting: if you are dragging in a way that the origin of the control can stay the same, that''s a simpler case: you''re just going to add your deltax to the control''s width, and the deltay to the controls height.

Suggest you start by implementing the simple case where the control''s origin can remain fixed, and then move on to thinking about what you need to do to handle the resize cases when the control''s origin must move.

best, Bill


从某种程度上讲,您可以使用SplitContainer逃脱.它使用户能够在水平方向上对托管控件进行大小调整,在垂直方向上进行XOR.您可以将其中的几个结合起来.
To some extend, you could get away using SplitContainer. It enables user to resize hosted controls horizontally XOR vertically. You can combine several of these.


这篇关于如何使用户在运行时调整控件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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