Snap to lines when aligning controls at run time

I have an application in which users can move controls on a form. But they re asking me for Snap-To lines to simplify the alignment of controls. I have no idea about snep-to lines and how to implement them - I looked:

http://msdn.microsoft.com/en-us/library/ms752100.aspx Adorner's, but he talks about it only for WPF. And I tried this in WinForms, but (as expected) did not work.

How can I get binding to lines (something like VS in VS) in my application?

thank

Bael

+2
source share
3 answers

CodeProject:

.

+1

Left Top, :

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

, . , MoveEnd, MouseButton - .

: , 134 = 130 136 = 140.

+1

, ; , .

const grid = 12;
private void MyControl_LocationChanged(object sender, EventArgs e)
{
    if (this.Left % grid != 0)
        this.Left -= this.Left % grid;
    if (this.Top % grid != 0)
        this.Top -= this.Top % grid;
}

usercontrol

protected override void OnMove(EventArgs e)
{
    if (this.Left % grid != 0)
        this.Left -= this.Left % grid;
    if (this.Top % grid != 0)
        this.Top -= this.Top % grid;
}

- ; , ; :

0

Source: https://habr.com/ru/post/1732424/


All Articles