If I understand the test project correctly, GridNode only draws a bitmap. When the mouse pointer enters a node, CreateCustomEditControl adds a grid control on top of it as an editor, and mouse-leave regenerates GridNode.Image.
So if you need to create pixel-perfect alignment of the pop-over grid with GridNode.Image, you must keep in mind that WinForms can show that child grid only at integer pixel coordinates. Following seems to work well on my system:
//gridNode.Bounds = new RectangleF(10, 10, 200, 150);
gridNode.Bounds = diagramView.ClientToDoc(
diagramView.DocToClient(new RectangleF(10, 10, 200, 150)));
here nested DocToClient returning pixel values, and outer ClientToDoc returning diagram coords for them. Then also shifting the grid by one pixel in CreateCustomEditControl:
if (e.Node == this)
{
e.EditControl = GridView;
var pixelRect = _view.DocToClient(Bounds);
pixelRect.X += 1;
pixelRect.Y += 1;
e.EditControl.Bounds = pixelRect;
}
Not sure why that's needed: either GridView.DrawToBitmap excludes border thickness, or the ClientToDoc(DocToClient) combo always rounds down, but has to round up if fraction part of coordinate is larger than 0.5. Try playing with different Bounds values to see if it's the latter case. Then you could determine whether to shift by 1 by checking the fraction part of DocToClientF result.
If you'll be aligning the node to pixels as above and letting users draw interactively, you can apply those operations from NodeCreated and NodeModified event handlers.
Some other options you might try:
- change diagram's MeasureUnit to Pixel;
- override GridView drawing code and translate by that factional part of DocToClientF before calling base;
Regards,
Slavcho
Mindfusion