移动,调整大小以及拖放控件 [英] Move,Resize and Drag and Drop a control
问题描述
我正在使用Windows应用程序,用户应该可以在其中移动,调整大小以及拖放控件(在我的情况下为文本框).
除了不能区分MouseDown和Click事件之外,我对移动和拖放的感觉还不错,因为每次我按下控件上的鼠标按钮时,MouseDown事件都会触发,并且我不能真正使用click事件.有没有一种方法可以区分MouseDown和单击.
第二个:我试图在用户选择对象时突出显示控件,以便突出显示控件或获得控件周围的调整大小矩形,以便用户可以拖动它来调整对象的大小.创建应用程序时要做的事情(我们在窗体上添加控件,然后调整其大小).谁能帮我这个忙.
感谢
要区别MouseDown
与Click
,您可以在以下情况下启动计时器MouseDown
被触发.如果您在计时器到期之前得到MouseUp
,则单击它,否则它将开始拖放.
例如,可以通过使用OnPaint
事件并添加GDI +代码以根据组件状态(拖放活动或非活动状态)绘制突出显示.
eg_Anubhava写道:用户应该能够移动,调整大小和拖动并放下一个控件(在我的情况下为文本框).设置什么属性. AFAIK您只能水平调整非多行TextBox的大小,因此在实现拖动句柄时需要考虑这一点. :)
Hi,
I am working on a windows application where the user should be able to move,resize and drag and drop a control (a Textbox in my case).
I am pretty much ok with the moving and drag and drop except that I cant differentiate between MouseDown and Click events, because everytime I press the mouse button on the control the MouseDown event fires up and I cant really use the click event. Is there a way that i can differentiate between MouseDown and Single Click.
Second: I am trying to highlight the control when the user selects the objects so that I highlight the control or get that resizing rectangle around the control so that user can drag it to resize the object. Something we do while creating a application (we add a control on the form and then resize it) . Can any one please help me out with this.
Thanks解决方案As for differentiatingMouseDown
fromClick
, you can start a timer whenMouseDown
is fired. If you get aMouseUp
before the timer expires, then it''s a Click, otherwise it''s starting a drag-and-drop.
Highlighting the control can be done for example by using theOnPaint
event and adding GDI+ code to draw your highlighting depending on the component status (drag-and-drop active or inactive).
eg_Anubhava wrote:user should be able to move,resize and drag and drop a control (a Textbox in my case).
I''ll leave it to others to help you with most of this, but you might find it difficult to resize a TextBox, depending on what properties are set. AFAIK you can only resize a non-multiline TextBox horizontally, so you will need to consider this when implementing your drag-handles. :)
这篇关于移动,调整大小以及拖放控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!