We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Move a line always snap to grid or grid by grid

Thread ID:

Created:

Updated:

Platform:

Replies:

120955 Oct 29,2015 10:30 AM UTC Nov 19,2015 07:22 AM UTC Windows Forms 13
loading
Tags: Diagram
Blanca Calderon
Asked On October 29, 2015 10:30 AM UTC

Hi,
went I move a line, a textnode or an image I would like that always be snap to grid.
If I have a a diagram withVerticalSpacing = 5 andHorizontalSpacing = 5 I would like that the movement will be 5 on 5, not 5, 7,5, 10....
I hope I explained well.
Thanks.
Regards,
Blanca

Blanca Calderon
Replied On October 29, 2015 10:59 AM UTC

In addition I need to avoid the variation of line's length grid by grid.

I need movement of an element grid by grid, but the length of a line avoiding this.

Naganathan Ganesh Babu [Syncfusion]
Replied On October 30, 2015 05:21 AM UTC

Hi Blanca,

 

Thanks for contacting Syncfusion support.

 

went I move a line, a textnode or an image I would like that always be snap to grid.

If I have a a diagram withVerticalSpacing = 5 andHorizontalSpacing = 5 I would like that the movement will be 5 on 5, not 5, 7,5, 10....

I hope I explained well.

We are unable to reproduce the reported issue. Please share more information about your requirement probably a video.

 

Please refer to the below attached video and sample. 

 

Video:

 

Video 

 

Sample:

 

Sample

 In addition I need to avoid the variation of line's length grid by grid.

I need movement of an element grid by grid, but the length of a line avoiding this.

Please share more information about your requirement probably a video.

 

Regards,

 

Naganathan K G 



Blanca Calderon
Replied On October 30, 2015 08:09 AM UTC

Hi,

I have three different problems.

1) I would like move an element grid by grid (I don´t want the movement in the middle of the grid). 



Attachment: Video_1446196041_e728bfb2.zip

Blanca Calderon
Replied On October 30, 2015 08:15 AM UTC

2) I always want a straight line, from one pixel to another pixel of the grid but straight line. 
It's almost impossible to draw a straight line.

Attachment: Video_1446196340_a37e0ee3.zip

Blanca Calderon
Replied On November 2, 2015 10:02 AM UTC

Could you give me an anwers? It's urgent.

Thanks

Swarnesh Krishna Kumar [Syncfusion]
Replied On November 2, 2015 10:06 AM UTC

Hi Blanca,

We have created a simple sample to achieve your requirement.

                       Queries
                           Solution
1) I would like move an element grid by grid (I don´t want the movement in the middle of the grid). 
We suggest you to use Nudge operation in order to achieve your requirement.

Code Example:

void diagram1_KeyDown(object sender, KeyEventArgs e)

        {

//Disables Default key operations           

e.SuppressKeyPress = true;

if(e.KeyCode == Keys.Right ||e.KeyCode == Keys.Left)

            {

this.diagram1.NudgeIncrement = diagram1.View.Grid.HorizontalSpacing;


if (e.KeyCode == Keys.Right)

 this.diagram1.NudgeRight();

 else

 this.diagram1.NudgeLeft();

  }
    }

2) I always want a straight line, from one pixel to another pixel of the grid but straight line. 
It's almost impossible to draw a straight line.

We suggest you to set false for AllowMoveY for Connectors HeadEndPoint and TailEndPoint in order to achieve your requirement.


CodeExample:


LineConnector line = new LineConnector(new PointF(100, 100), new PointF(400, 100));

 //By setting false AllowMoveY for both HeadEndPoint and TailEndPoint it will draw a straight line.           

line.HeadEndPoint.AllowMoveY = false;
line.TailEndPoint.AllowMoveY = false;



We have attached a sample for your reference.

Sample:
Sample

Regards,
Swarnesh K


Blanca Calderon
Replied On November 2, 2015 10:09 AM UTC

Thank you, I'm going to try it.

Blanca Calderon
Replied On November 2, 2015 12:18 PM UTC

Thank you, I'm going to try it.

1) It works fine with keypress and mouse movement but when I press shift+key down (or up, or left or right) I want that the movement will be as usual, pixel by pixel.

I've tried this but it doesn't work.

 if (Control.ModifierKeys != Keys.Shift)
            {
                //Disables Default key operations            
                e.SuppressKeyPress = true;
                if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)
                {
                    this.diagram1.NudgeIncrement = diagram1.View.Grid.HorizontalSpacing;

                    if (e.KeyCode == Keys.Right)
                        this.diagram1.NudgeRight();
                    else
                        this.diagram1.NudgeLeft();
                }

                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
                {
                    this.diagram1.NudgeIncrement = diagram1.View.Grid.VerticalSpacing;

                    if (e.KeyCode == Keys.Up)
                        this.diagram1.NudgeUp();
                    else
                        this.diagram1.NudgeDown();
                }
            }            

Swarnesh Krishna Kumar [Syncfusion]
Replied On November 3, 2015 06:07 AM UTC

Hi Blanca,

In order to achieve your requirement, we have modified the sample. Please detect Shift keys with the help of “e.Shift” in the Diagram’s KeyDown event.


Code Example:
 [C#]

if (!e.Shift && (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right))

            {

                e.SuppressKeyPress = true;

                //Increments  Grid by Grid

                this.diagram1.NudgeIncrement = diagram1.View.Grid.HorizontalSpacing;


                if (e.KeyCode == Keys.Right)

                    this.diagram1.NudgeRight();

                else

                    this.diagram1.NudgeLeft();

            }

            Else

//Increments  Pixel by Pixel
                this.diagram1.NudgeIncrement = 1;
We have attached a sample for your reference.
Sample:
Sample
Regards,
Swarnesh K



Blanca Calderon
Replied On November 4, 2015 08:59 AM UTC

It works fine, thank you.

Swarnesh Krishna Kumar [Syncfusion]
Replied On November 6, 2015 05:23 AM UTC

Hi Blanca,

Thanks for your update.

Please let us know if any concern.

Regards,

Swarnesh K


Blanca Calderon
Replied On November 18, 2015 11:22 AM UTC

Hi,

I have one question related with this.

I want to move a line always snap to grid, but if I use Shift + key (up, down, left or right) and after this I come back to only press a key (up, down, left or right) the movement is not snap to grid any more.

How can I come back to snap to grid??

Attachment: Video_1447849306_9cf9a755.zip

Swarnesh Krishna Kumar [Syncfusion]
Replied On November 19, 2015 07:22 AM UTC

Hi Blanca,
We suggest you to find the nodes nearest grid point using Diagram.Controller.View.Grid’s GetNearestGridPoint method and translate the node according to that in order to achieve your requirement.
We have attached the sample for your references.
Code example:
//Registering Event
diagram1.Model.EventSink.PinPointChanged += EventSink_PinPointChanged;

void EventSink_PinPointChanged(PinPointChangedEventArgs evtArgs)

        {

            if (b)

            {

                b = false;

                Node n = (evtArgs.NodeAffected) as Node;

                PointF NearestGrid = diagram1.Controller.View.Grid.GetNearestGridPoint(n.BoundingRectangle.Location);

                if (n.BoundingRectangle.X != NearestGrid.X || n.BoundingRectangle.Y != NearestGrid.Y)

                    n.Translate(NearestGrid.X - n.BoundingRectangle.X, NearestGrid.Y - n.BoundingRectangle.Y);

            }
        }
Sample:
Sample
Regards,
Swarnesh K


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;