Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic A problem about printing a ControlNode (Read 3079 times)
Ralax
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Apr 23rd, 2008
A problem about printing a ControlNode
Apr 23rd, 2008 at 1:28am
Print Post  
I use devexpress's XtraUserControl, then the UserControl is filled with a XtraTreeList, i can see the UserControl and XtraTreeList, but when print the chart, i can only see the XtraUserControl, i couldn't see the XtraTreeList.

is the chart is not what i see is what i get???

what can i do?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: A problem about printing a ControlNode
Reply #1 - Apr 23rd, 2008 at 8:47am
Print Post  
Flowchart.NET can print Windows Forms control only if they render their entire contents in an override of the Control.OnPaint method. If a control is merely a wrapper around a standard Windows control or an ActiveX one, you can still print it by handling the DiagramView.PaintControl event. If the XtraList provides some methods to export a bitmap or metafile image, use them in the PaintControl handler to get an image, and draw it by calling Graphics.DrawImage().

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ralax
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Apr 23rd, 2008
Re: A problem about printing a ControlNode
Reply #2 - May 9th, 2008 at 9:45am
Print Post  
Thanks, Stoyo!

Yes, i can print UserControl(A) which is filled with a XtraTreeList,
but if UserControl(A) is a child control of another UserControl(B), when i print UserControl(B), i still can not see the XtraTreeList,

i'm confused! why?





  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: A problem about printing a ControlNode
Reply #3 - May 9th, 2008 at 12:46pm
Print Post  
Do you print UserControl(A) by handling PaintControl? FlowChart.NET won't loop over child nodes (as in UserControl(B)) and raise PaintControl for them - your application will get e single PaintControl raised for UserControl(B) and the handler must loop over the child controls and paint them.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ralax
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Apr 23rd, 2008
Re: A problem about printing a ControlNode
Reply #4 - May 13th, 2008 at 6:22am
Print Post  
Here is my codes:

private void diagramView_PaintControl(object sender, PaintControlEventArgs e)
       {
           UserControl control = e.Node.Control as UserControl;
           if (control != null)
           {
               Rectangle rec = control.DisplayRectangle;
               System.Drawing.Bitmap bitMap = new Bitmap(rec.Width, rec.Height);
               control.DrawToBitmap(bitMap, rec);

               System.IO.MemoryStream stream = new System.IO.MemoryStream();
               bitMap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
               System.Drawing.Image image = Image.FromStream(stream, true);
              
               if (control is UserControlB)
               {
                   foreach (Control ctrl in control.Controls)
                   {
                       DrawControl(e, ctrl);
                   }
               }
               e.Graphics.DrawImage(image, e.PaintRect);
           }
           e.Handled = true;
       }

       private void DrawControl(PaintControlEventArgs e, Control ctrl)
       {
           if (ctrl is TreeList)
           {
               Rectangle rec = ctrl.DisplayRectangle;
               System.Drawing.Bitmap bitMap = new Bitmap(rec.Width, rec.Height);
               ctrl.DrawToBitmap(bitMap,rec);
              
               System.IO.MemoryStream stream = new System.IO.MemoryStream();
               bitMap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
               System.Drawing.Image image = Image.FromStream(stream, true);
               e.Graphics.DrawImage(image, rec);
           }
           else
           {
               foreach (Control control in ctrl.Controls)
               {
                   DrawControl(e, control);
               }
           }
       }

use the above control, i still can not print the treeList in usercontrolb.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: A problem about printing a ControlNode
Reply #5 - May 13th, 2008 at 9:46am
Print Post  
What happens if you move this line

e.Graphics.DrawImage(image, e.PaintRect);

above

if (control is UserControlB)

in the diagramView_PaintControl method?

Stoyan
  
Back to top
 
IP Logged
 
Ralax
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Apr 23rd, 2008
Re: A problem about printing a ControlNode
Reply #6 - May 15th, 2008 at 4:14am
Print Post  
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!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: A problem about printing a ControlNode
Reply #7 - May 15th, 2008 at 11:11am
Print Post  
What you assign to controlNode.Bounds is usually measured in millimeters, while UserControl.Width and Height are specified in pixels. You could use the ClientToDoc method to convert from pixels to the current MeasureUnit.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint