I have found a solution, this is the final rease:
private float xRate; private float yRate; private void diagramView_PaintControl(object sender, PaintControlEventArgs e) { UserControl control = e.Node.Control as UserControl; if (control != null) { xRate = 0F; yRate = 0F; Rectangle rec = control.DisplayRectangle; System.Drawing.Bitmap bitMap = new Bitmap(rec.Width, rec.Height); control.DrawToBitmap(bitMap, rec); e.Graphics.DrawImage(bitMap, e.PaintRect);
xRate = e.PaintRect.Width / rec.Width; yRate = e.PaintRect.Height / rec.Height;
if (control is UserControlB) { foreach (Control ctrl in control.Controls) { DrawControl(e, ctrl); } } } e.Handled = true; }
private void DrawControl(PaintControlEventArgs e, Control ctrl) { if (ctrl is UserControlA) { Rectangle rec = ctrl.DisplayRectangle; System.Drawing.Bitmap bitMap = new Bitmap(rec.Width, rec.Height); ctrl.DrawToBitmap(bitMap, rec);
RectangleF recF = new RectangleF(); recF.X = e.PaintRect.X + ctrl.Bounds.X * xRate; recF.Y = e.PaintRect.Y + ctrl.Bounds.Y * yRate; recF.Width = rec.Width * xRate; recF.Height = rec.Height * yRate;
e.Graphics.DrawImage(bitMap, recF); } else { foreach (Control control in ctrl.Controls) { DrawControl(e, control); } } }
Hope this will help the guys who have the same problem.
Also, i have another problem: ControlNode controlNode = new ControlNode(diagramView); controlNode.Bounds = new RectangleF(0, 0, UserControl.Width, UserControl.Height); controlNode.Control = UserControl; diagram.Nodes.Add(controlNode); If the Width and Height is 20/30, when display the chart, the Width and Height will be bigger than we want. I tried to add controlNode's constraints to limited the width and height to 20/30, but it's no use.
Thanks!
|