在运行时对齐控件时的对齐线 [英] Snap-To lines when aligning controls at Runtime

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

问题描述

我有一个应用程序,用户可以在表单上拖动控件。但他们
请求我的Snap-To行,使控制的对齐更容易。我不知道snep-to行和如何实现它们 - 我看过:

I have an app where users can drag controls around on a Form. But they re asking me for Snap-To lines to make the alignment of controls easier. I have no idea about the snep-to lines and how to implement them - I have looked at:

http://msdn.microsoft.com/en-us/library/ms752100.aspx Adorner的,但它说它只适用于WPF 。

http://msdn.microsoft.com/en-us/library/ms752100.aspx Adorner's, but it says it's only for WPF. And I tried it in WinForms but (as expected) didn't work.

如何在我的应用程序中获取snap-to行(类似VS中的行) ?

How can I get snap-to lines (something like the ones in VS) in my app?

谢谢

Bael

推荐答案

在你的移动控制中,你可以分开调整顶部乘以你的线宽:

In your move control you could adjust the Left and Top by dividing and then multiplying by the width of your lines:

left = (left/10)*10;
top = (top/10)*10;

这不是完美的,但它很简单。当然,由于控件没有MoveEnd事件,你必须跟踪MouseButton状态或类似的东西。

It's not perfect but it it simple. Of course since controls don't have a MoveEnd event you'll have to track the MouseButton state or something similiar.

编辑:实施将适当地舍入除法结果,因此134 = 130和136 = 140。

A better implementation would properly round the division results so 134 = 130 and 136 = 140.

这篇关于在运行时对齐控件时的对齐线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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