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: 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
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; |
Thank you, I'm going to try it.
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
Hi Blanca,
Thanks for your update.
Please let us know if any concern.
Regards,
Swarnesh K
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